HOW-TO: Scripting AND/OR/IF rules to generate trade entry/exit signales

As the scripting engine was updated for performance reasons, AND/OR conditions must now be coded in mathematical terms. The follwing examples show how to code AND/OR statements to produce final trade entry/exit signals in comparison to the “old” scripting format.

 


 

Example 1 – Bollinger Bands Script:

Old Version:

SET BOTTOM = BBB(CLOSE, $N3, $N4, EXPONENTIAL)
SET TOP = BBT(CLOSE, $N3, $N4, EXPONENTIAL)
((REF(CLOSE, 1) > REF(TOP, 1)) AND CLOSE < TOP) OR CLOSE < BOTTOM * 0.98


New Version:

SET BOTTOM = BBB(CLOSE, $N3, $N4, EXPONENTIAL)
SET TOP = BBT(CLOSE, $N3, $N4, EXPONENTIAL)
SET s1 = ((REF(CLOSE, 1) > REF(TOP, 1)) + (CLOSE < TOP))
SET s2 = (CLOSE < (BOTTOM * 0.98))
SET sellsignal = (s1>1) + (s2>0)
if (sellsignal>=1,true,false)

 


 

Example 2 – Simple CSI Turnover Script:

Idea: Generate sell signal if indicator is above dynamic OB line and turns down and generate buy signal if indicator is below dynamic OS line and turns up. Here is the script to capture the turns of the indicator if it is above/below the bands:

 

Buy Script:

#set values
set csi = lvtcsi(40,0.1)
set lowband = lvtcsilb(40,0.1)

#generate critea
set oversold = csi < lowband
set upturn = CROSSOVER(csi> REF(csi,1), 0.5)

#build AND signal condition
set buysignal = upturn + oversold

#check if signal was generated
if (buysignal=2,true,false)

 

– SHORT BUY SCRIPT VERSION –

set csi = lvtcsi(40,0.1)
set buysignal = (CROSSOVER(csi> REF(csi,1), 0.5) + (csi<lvtcsilb(40,0.1)))
if (buysignal=2,true,false)

 

Sell Script:

#set values
set csi = lvtcsi(40,0.1)
set highband = lvtcsiub(40,0.1)

#generate critea
set overbought = csi > highband
set downturn = CROSSOVER(csi< REF(csi,1), 0.5)

#build AND signal condition
set sellsignal = downturn + overbought

#check if signal was generated
if (sellsignal=2,true,false)

 

– SHORT SELL SCRIPT VERSION –

set csi = lvtcsi(40,0.1)
set sellsignal = (CROSSOVER(csi< REF(csi,1), 0.5) + (csi>lvtcsiub(40,0.1)))
if (sellsignal=2,true,false)

 

Example 3 – Combination of Indicators


OLD SCRIPT:

TREND(EMA(CLOSE,20),15) = DOWN
AND TREND(MACD(13,26,9,SIMPLE),5) = DOWN

 

NEW SELL SCRIPT:

# setup indicators
SET T1 = TREND(EMA(CLOSE,20),15)
SET T2 = TREND(MACD(13,26,9,SIMPLE),5)

# build final signal with AND condition
# make sure that no UP or SIDEWAYS trend is active in T1 AND T2
set sellsignal = (t1<3) + (t1>1) + (t2>1) + (t2<3)

# evaluate to true if AND statement is given (sellsignal must be =4)
if(sellsignal=4,true,false)


[…]
You must have membership level. Please go to whentotrade.com to configure your account.
[…]

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply