maverickmitch
Member
If you can help me, it would GREATLY appreciated.
On a 2m chart with a SMA of 200. I am looking to write thinskcript code for when the price crosses and closes above the 200MA and another "confirmation" candlestick closes higher than that original crossing-over candlestick. The tricky part is that the "confirmation" candlestick can be a few candlesticks later. This is the part I can't figure out with code.
After that is figured out, I want a boolean value to oscilate between ABOVE 200SMA and BELOW200SMA (which i have in the code) based on whether that confirmation above is true.
On a 2m chart with a SMA of 200. I am looking to write thinskcript code for when the price crosses and closes above the 200MA and another "confirmation" candlestick closes higher than that original crossing-over candlestick. The tricky part is that the "confirmation" candlestick can be a few candlesticks later. This is the part I can't figure out with code.
After that is figured out, I want a boolean value to oscilate between ABOVE 200SMA and BELOW200SMA (which i have in the code) based on whether that confirmation above is true.
HERE IS MY CODE
#MOVING AVERAGES
def Short_MA = 200;
plot Short = SimpleMovingAvg(length = Short_MA); #pink line
def CrossUp = open < short and high > short and close > short; #CROSS AND CLOSE ABOVE
def CrossDn = open > short and low < short and close < short;
def CrossUpConfirmed = close > high[1]; #I want this to be true if the close is greater than the original crossover bar, even if it's 5 bars later
def CrossDnConfirmed = close < low[1];
def CrossingUp = CrossUp[1] and CrossUpConfirmed;
def CrossingDown = CrossDn[1] and CrossDnConfirmed;
plot MA_Buy = CrossingUp;
plot MA_Sell = CrossingDown;
MA_BUY.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
MA_Sell.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
#OSCILATE
def MA;
if MA_Sell is true {
MA = yes;
} else if MA_Buy is true {
MA = no;
} else {
MA = MA[1];
}
plot Buy = !MA;
plot Sell = MA;
BUY.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
Sell.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);