Green takes Red Bar

Sams

New member
Hello, I am looking to create a buy signal when a green bar takes over the red. So when the 8 ema above the 21 ema and a red bar closes or touches the 21 ema, the next green bar that takes over the high of the red bar creates a buy trigger. The trigger does not have to wait until the green bar closes but as long as that green bar breaks the high of the red bar. is it possible? Thank you in advance.
 
Last edited:

SleepyZ

Well-known member
Hello, I am looking to create a buy signal when a green bar takes over the red above the 8ema. So when a red bar touches the 8 ema, the next green bar takes over the red, creates a buy signal. is it possible? Thank you in advance.

This might get you started
Code:
plot ema   = expaverage(close,8);
def redbar = if close<open and low <= ema and high> ema then 1 else 0;

plot buysignal = if redbar[1] == 1 and close>open and high crosses above high[1] and close > ema then 1 else 0;
buysignal.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
buysignal.setdefaultColor(color.black);
buysignal.setlineWeight(4);
Capture.jpg
 

Sams

New member
This might get you started
Code:
plot ema   = expaverage(close,8);
def redbar = if close<open and low <= ema and high> ema then 1 else 0;

plot buysignal = if redbar[1] == 1 and close>open and high crosses above high[1] and close > ema then 1 else 0;
buysignal.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
buysignal.setdefaultColor(color.black);
buysignal.setlineWeight(4);
Capture.jpg
Thank you! It's definitely a great start. Not sure if you can help again but this is the whole script that I want to backtest. If the 8ema above the 21 ema and a red candle touches the 21 ema, once the next green candle breaks the previous red candle high, trigger a buy signal.
 

Similar threads

Top