PI Script error


i’ve written the following code to create a buy alert.


What i wanted to check is when the market opens it should calculate the first 10mins candle open, high, low and close to calculate the avg (SET Ag = (OPEN+LOW+CLOSE+HIGH)/4)

now it should give me a buy alert when the price is greater than avg but its showing me an error when i run the script any help would be appreciative.


Hi Prdyk,

Ur Code 'll never give Buy Signal.


Ag+(Ag*0.5)) means 50% increase from Avg Price…

Secondly with TradeScript,U can’t get the First 10Min candle OHLC…

Since the TradeScript Runs on BarHistory…

Thanks dude for the answer, Yes you are right i realised that later cos its always taking the latest bars it never give buy or sell signals.
Is there any work around? at least i need the avg constant for 40bars then for the next 40bars new avg can be calculated. does it make any sense?