I'm trying to make a startegy that will buy when current price crosses above close of last bar after a consecutive amount of bars were lower than the previous bar if someone can help. I know how to put
def buy = low[1] < low[2] and low[2] < low[3] and low[3] < low[4] and close > close[1];
def sell = close < close; But I'm try to have the inputs so I can just change them from a selection instead of changing the code for backtesting with other studies in the same code.
input ConsecutiveBarsDown = 3;
input ConsecutiveBarsUp = 1;
def cbd = ConsecutiveBarsDown;
def cbu = ConsecutiveBarsUp;
#def Buy = cbd and cbu;
#def sell = close < close;
AddOrder(OrderType.BUY_TO_OPEN, buy, name = "Buy",tickcolor = Color.BLUE, arrowcolor = Color.BlUE);
AddOrder(OrderType.SELL_TO_ClOSE, sell,name = "Sell",tickcolor = Color.RED, arrowcolor = Color.RED);
Ex: from 4 bars ago the close < close each time until current price crossed above close of last bar.
def buy = low[1] < low[2] and low[2] < low[3] and low[3] < low[4] and close > close[1];
def sell = close < close; But I'm try to have the inputs so I can just change them from a selection instead of changing the code for backtesting with other studies in the same code.
input ConsecutiveBarsDown = 3;
input ConsecutiveBarsUp = 1;
def cbd = ConsecutiveBarsDown;
def cbu = ConsecutiveBarsUp;
#def Buy = cbd and cbu;
#def sell = close < close;
AddOrder(OrderType.BUY_TO_OPEN, buy, name = "Buy",tickcolor = Color.BLUE, arrowcolor = Color.BlUE);
AddOrder(OrderType.SELL_TO_ClOSE, sell,name = "Sell",tickcolor = Color.RED, arrowcolor = Color.RED);
Ex: from 4 bars ago the close < close each time until current price crossed above close of last bar.
Last edited by a moderator: