Swingtrade
New member
HI
I am trying to test a strategy and I want to buy shares when the condition is met for buy side and also close the current buy and sell shares if sell signal Is issued. similarly when the sell signal becomes buy then close the short position and open a long one. Below is the code I have which does open a long position on buy condition met and sells the shares when a sell signal is met. I am unable to code for opening a short position and closing the short position
def G = if E >= F and E[1] < F[1] then E else Double.NaN;
AddOrder(OrderType.BUY_TO_OPEN, G, open[-1], tradesize, Color.Green, Color.Green);
def Z = if E <= F and E[1] > F[1] then E else Double.NaN;
AddOrder(OrderType.SELL_TO_CLOSE, Z, open[-1], tradesize, Color.Red, Color.Red);
I am trying to test a strategy and I want to buy shares when the condition is met for buy side and also close the current buy and sell shares if sell signal Is issued. similarly when the sell signal becomes buy then close the short position and open a long one. Below is the code I have which does open a long position on buy condition met and sells the shares when a sell signal is met. I am unable to code for opening a short position and closing the short position
def G = if E >= F and E[1] < F[1] then E else Double.NaN;
AddOrder(OrderType.BUY_TO_OPEN, G, open[-1], tradesize, Color.Green, Color.Green);
def Z = if E <= F and E[1] > F[1] then E else Double.NaN;
AddOrder(OrderType.SELL_TO_CLOSE, Z, open[-1], tradesize, Color.Red, Color.Red);