I'm trying to addorder if the open position reaches a certain profit or loss. Seems pretty simple but for some reason I cant get it to work. Mind you this is in conjunction with a bunch of other stuff, but this would be an AddOrder if ExitG is 1, and then a separate one if ExitB is 1. Cant seem to figure out why this isnt working.
input gainz = 20;
input lossz = -20;
def exitG;
def exitB;
if GetOpenPL() > gainz { exitG = 1;} else { exitG = 0;}
if GetOpenPL() < lossz { exitB = 1;} else { exitB = 0;}
AddOrder(OrderType.SELL_TO_CLOSE, exitG == 1, price = close, quantity, tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "gainz profit");
input gainz = 20;
input lossz = -20;
def exitG;
def exitB;
if GetOpenPL() > gainz { exitG = 1;} else { exitG = 0;}
if GetOpenPL() < lossz { exitB = 1;} else { exitB = 0;}
AddOrder(OrderType.SELL_TO_CLOSE, exitG == 1, price = close, quantity, tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "gainz profit");