Tradescript or operator

Hello all,

I am facing issue with OR operator.

OBV(CLOSE) <0 AND SMA(OBV(CLOSE),30) <0 AND OBV(CLOSE) < 1.5* SMA(OBV(CLOSE),30)

OR

OBV(CLOSE) >0 AND SMA(OBV(CLOSE),30)>0 AND OBV(CLOSE) > 1.5* SMA(OBV(CLOSE),30)

The above two codes without OR operator work perfectly (separately) as individual codes

but when using OR operator it gives error in tradescript.

What is the problem??

It appears that you want to include both contra condition code by putting OR. You are for example asking system to do some thing when some is greater and less than same number. Hence you are expecting code to find some thing equal to which is not coded.

Let’s say x= 30
29<x and 31>x
System would throw error because
29<X or 31>x would let give any out put.
Try putting brackets for each statement (ssssssss) or (dddddd)
It may work, I am not sure.

Thanks for your reply. I had indeed put more brackets so that OR is clearly separated.

My code is something like this, and mathemetically they are not a void:

OBV and SMA of OBV, both positive.

OR

OBV and SMA of OBV, both negative.

So something wrong with tradescript not with the code.

@nithin Can we have some one technical look into this please??

@siva-reddy @AlgoGeek

Are you using this tradescript in backtesting or scanner? also, you didn’t mention the error, I have checked the above code,I guess the two conditions which you are combining with OR is buy and sell conditions, you can use those by putting each in buy and sell columns of pi backtest or in 2 scanners separately, I have verified and it’s working fine.
The problem while combining two opposite conditions into one using OR is, In backtest the buy signal is followed by sell and vise-versa, and it needs at least one buy and sell script to give signal otherwise it will throw error of " the script generated no trades needs buy and sell"
so you can use both conditions separately in buy and sell columns and try. check my below screenshot for reference

@AlgoGeek Thanks for the effort.

but the assumption is not correct. I want to use it as scanner not for backtest on a single stock/future.
Both the conditions are Buy side only.

The sell side is manual not coded.

Can you put this code and run in scanner. It throws a pop up error: Your script generated error.

(OBV(CLOSE) <0 AND SMA(OBV(CLOSE),30) <0 AND OBV(CLOSE) < 1.5* SMA(OBV(CLOSE),30))

OR

(OBV(CLOSE) >0 AND SMA(OBV(CLOSE),30)>0 AND OBV(CLOSE) > 1.5* SMA(OBV(CLOSE),30))

Same is working fine in Amibroker as coded below:

Buy = ((obv() > 1.5* ma(OBV(), 30) AND obv()>0 AND ma(OBV(),30 )>0) OR (obv()/ma(OBV(),30) <0.67 AND obv()<0 AND ma(OBV(), 30 )<0)) ;

click on edit script when you get error and see " OR " would have got mixed with other scrip without space, give more space on both sides as shown below screenshots and try it will work fine
image
image

@nithin @AlgoGeek

Thanks. It worked.

Few questions and a request:

  1. Can we scan all the futures in a single scanner? About 180 symbols?

  2. Is Zerodha Pi capable of running 2 scanners simultaneously? Each containing 180 symbols?

  3. Can you please provide a default market watch of all futures. I know current limit is 50 symbols.

  4. Whenever alert is generated in scanner, the scrip should move up and come on top of the scanner. But their position changes only when we click on alert time column 2 times for sorting in descending order of time.

there is no limit for adding symbols, you can add as many scrip and number of scanner which your PC and internet speed supports, as scanner fetches every LTP tick and computes with your given condition, the PC goes hang when it reaches its capacity. so I recommend to go with 50 scrips and then try to increase more if it is working fine.

yes, there is a limitation in the number of scrips on Market watch and the scanner doesn’t sort automatically.

You can try advanced web version of backtesting and scanners of streak.zerodha.com