Hello, can someone help me create a filter :
– which starts when a condition appears
– which ends when another condition occurs.
This filter will be included in a robot and will be used to take sales on a lower TF.
The filter starts when :
– the SMA7 > SMA20 AND the SMA7 turns down,
The filter disappears when :
– the SMA7 turns upwards
I tried to create a code to accept trades only between these conditions but it doesn’t seem to work the way I want it to.
Using graph it only shows the first condition and I can’t create an indicator that could color the background (with backgroundcolor) so I don’t realize where the error comes from.
Maybe you should use a While loop but I haven’t found the solution.
Here is the code:
defparam cumulateorders = false
SMA7 = Average[7](close)
SMA20 = Average[20](close
timeframe(daily)
// ***************** FILTER START *******
// SMA7 > SMA20
C1 = (SMA7 > SMA20)
// Downtrend start
C2 = (SMA7[1] > SMA7[2]) AND (SMA7[1] > SMA7)
// ***************** END OF FILTER *******
// End of Downtrendown
C3 = (SMA7[1] < SMA7[2]) AND (SMA7[1] < SMA7)
// *****************
FILTERSTART = C1 AND C2
ENDofFILTER = C3
ONCE TradeOn = 0
IF FILTERSTART AND Not OnMarket THEN
TRADEON = 1
Endif
IF (TradeOn = 1) AND ENDofFILTER THEN
TradeON = 0
ENDIF
timeframe(default)
// Engulfing
c4 = high>high[1] and close < low[1]
ConditionsSell = (TradeOn = 1) AND C4
IF NOT ShortOnMarket AND ConditionsSell THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
SET TARGET pPROFIT 50
SET STOP pLOSS 20