Square Root funciton in PI

is there any function available in PI to find square root of a number

Square root function can not be defined by tradescript

Yes, using the LOG and EXP primitives. You can calculate the n-th root of any number. Here:

You want square root of X.

SET SQRT=EXP(LOG(X)/2)

For n-th root simply replace 2 with n.

1 Like

Thanks Abijt for your you valuble code and info, how can i get previous day OHLC, earlier i was told to REF or HHV functions but those are fetching highs and lows or bars not exact data OHLC of yesterday

thanks
but i can have it by using LOOP function, i need following logic to be coded if current price > Any Square Number, increase the square number by 1 and re check till condition gets false and get the final true number
example : Current Price 60
If CP (60) > (16) 4 Sqaure check for next square 5 and finally get 7 squares since 8 Squares is greater than CP

I am giving you code based on my understanding of your logic. Problem is, just today I was checking some previously backtested EAs on Pi, and all of them were generating errors(even simple moving average crossovers) for some reason. Maybe you should try Ninjatrader or Nest Trader for the time being.
SET X = LOOP(X,1,1,0,ADD)
SET B = COUNTIF(CLOSE>X*X)
The 1st line of code creates a series of integers 1,2,3,4,5,…,n
The second line checks the number of times the CMP(close) is greater than the square. Finally, when the CMP is less than the square, the COUNTIF function gives the value of that integer

For previous day’s OHLC data, I suggest using a Python library called nsepy or use Quandl(you need to register). You need to learn Python for this(or some other programming language for Quandl), but almost all algorithmic traders have to learn programming languages at some point of their trading career.