Coding questions

CarlosTrades

New member
I’m Not that fluent in thinkscript and I’m wondering how I would code for a arrow signal to show after a ema crossover and the second candle close in that direction
 
Solution
I’m Not that fluent in thinkscript and I’m wondering how I would code for a arrow signal to show after a ema crossover and the second candle close in that direction


this will find ema crossovers
it determines if the bar at a crossover is up or down.
then counts those same bars (up or down) and plots an arrow on the bar that matches the count (default 2)
so the type of cross doesn't matter. it matches a future bar to the same bar type on a crossover.


Code:
# arrow_after_emax

#https://usethinkscript.com/threads/coding-questions.16368/
# code for a arrow signal, to show after a ema crossover, and the second candle close in that direction

def na = double.nan;
def bn = barnumber();

def up = close > open;
def dwn = close < open...
I’m Not that fluent in thinkscript and I’m wondering how I would code for a arrow signal to show after a ema crossover and the second candle close in that direction


this will find ema crossovers
it determines if the bar at a crossover is up or down.
then counts those same bars (up or down) and plots an arrow on the bar that matches the count (default 2)
so the type of cross doesn't matter. it matches a future bar to the same bar type on a crossover.


Code:
# arrow_after_emax

#https://usethinkscript.com/threads/coding-questions.16368/
# code for a arrow signal, to show after a ema crossover, and the second candle close in that direction

def na = double.nan;
def bn = barnumber();

def up = close > open;
def dwn = close < open;
input count_after_cross = 2;

def price = close;
input ma1_len = 20;
input ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);

input ma2_len = 50;
input ma2_type =  AverageType.EXPONENTIAL;
def ma2 = Movingaverage(ma2_type, price, ma2_len);

def xup = ma1 crosses above ma2;
def xdwn = ma1 crosses below ma2;

input show_lines = yes;
plot z1 = if show_lines then ma1 else na;
z1.setdefaultcolor(getcolor(1));
#z1.setlineweight(1);
z1.hidebubble();

plot z2 = if show_lines then ma2 else na;
z2.setdefaultcolor(getcolor(2));
#z2.setlineweight(1);
z2.hidebubble();

# cross up , up or down bar
def xupdir = if bn == 1 then 0
 else if xdwn then 0
 else if xup and up then 1
 else if xup and dwn then -1
 else if xupdir[1] > 0 and up then xupdir[1] + 1
 else if xupdir[1] < 0 and dwn then xupdir[1] - 1
 else xupdir[1];

# cross down , up or down bar
def xdwndir = if bn == 1 then 0
 else if xdwn and up then 1
 else if xdwn and dwn then -1
 else if xdwndir[1] > 0 and up then xdwndir[1] + 1
 else if xdwndir[1] < 0 and dwn then xdwndir[1] - 1
 else xdwndir[1];


plot zupup = if count_after_cross == xupdir and count_after_cross != xupdir[1] then low*0.999 else na;
plot zupdwn = if count_after_cross == -xupdir and count_after_cross != -xupdir[1] then high*1.001 else na;

zupup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zupup.SetDefaultColor(Color.green);
zupup.setlineweight(3);
zupup.hidebubble();

zupdwn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zupdwn.SetDefaultColor(Color.red);
zupdwn.setlineweight(3);
zupdwn.hidebubble();


input show_cross_wedges = yes;

plot zxup1 = if show_cross_wedges and xup then 1 else 0;
zxup1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zxup1.SetDefaultColor(Color.light_gray);
zxup1.setlineweight(2);
zxup1.hidebubble();
plot zxup2 = if show_cross_wedges and xup then 1 else 0;
zxup2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
zxup2.SetDefaultColor(Color.light_gray);
zxup2.setlineweight(2);
zxup2.hidebubble();


plot zxdwn1 = if show_cross_wedges and xdwn then 1 else 0;
zxdwn1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zxdwn1.SetDefaultColor(Color.light_gray);
zxdwn1.setlineweight(2);
zxdwn1.hidebubble();
plot zxdwn2 = if show_cross_wedges and xdwn then 1 else 0;
zxdwn2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
zxdwn2.SetDefaultColor(Color.light_gray);
zxdwn2.setlineweight(2);
zxdwn2.hidebubble();


#------------------------
addchartbubble(0, low,
xupdir
, color.yellow, no);
#


PFE 15min
match set to 3
wedges on the crossover bar
on the crossover, the bar is up, so look at future up bars
a green arrow on the 3rd up bar since crossover
6tZpStx.jpg
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
393 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top