Can anyone help me out with this one simple piece of thinkscript code..
The problem is this last line of code.. it is not allowing me to write over this variable since i have defined it in the 3rd line above..
What i am trying to do is prevent more than one buy... In other words once i buy the first time it will not buy again until the cnt variable is changed.. To allow a new buy...
But the cnt = 0 is not passing the smell test and its telling me that once i have defined a variable i am stuck with it... I have seen something like cnt += 0; or maybe cnt := 0; and that allowed a write over but i have searched near and far and cannot find anything that works....
The first time thur i set the cnt to 1 to allow a buy but once the buy is done i can find no way to shut off buy till i am ready to order the next buy... Any assist will be greatly appreciated.. Thanks
Code:
input positionsize = 5000;
plot sma = SimpleMovingAvg(length = 200);
def cnt = 1;
def buy = (close > sma and RSI() < 30 and cnt);
def sell = RSI() > 80;
AddOrder(OrderType.BUY_TO_OPEN, buy, close);
AddOrder(OrderType.SELL_TO_CLOSE, sell, close);
cnt = 0;
The problem is this last line of code.. it is not allowing me to write over this variable since i have defined it in the 3rd line above..
What i am trying to do is prevent more than one buy... In other words once i buy the first time it will not buy again until the cnt variable is changed.. To allow a new buy...
But the cnt = 0 is not passing the smell test and its telling me that once i have defined a variable i am stuck with it... I have seen something like cnt += 0; or maybe cnt := 0; and that allowed a write over but i have searched near and far and cannot find anything that works....
The first time thur i set the cnt to 1 to allow a buy but once the buy is done i can find no way to shut off buy till i am ready to order the next buy... Any assist will be greatly appreciated.. Thanks
Last edited by a moderator: