Hi’ guys,
Some feedback on this topic. I’ve tested the code written by @Despair with a slight modfication, where I added: Bullish Engulfing, Aroon Up/Down and volume. Further, I tried to add the Support and Resistance lines as defined by Demark, but without any luck – hence code is disabled. Also, I added some exit conditions.
It started out very well for the first three months, but then the performance worsened. Pictures added.
However, I still see a potential in it…so maybe we can collaborate around an enhanced version, where we add:
- Support and Resistance lines as defined by Demark and ensure the TDemark setup only triggers if the price stays within these lines
- Add enhanced 2nd and 3rd “confirming” signals
- Add improved exit conditions, profit and SL
Code is here:
//-------------------------------------------------------------------------
// Main code : TDemark_DAX v2 1m
//-------------------------------------------------------------------------
DEFPARAM CUMULATEORDERS = FALSE
//DEFPARAM FLATBEFORE = 080000
//DEFPARAM FLATAFTER = 230000
/////****** TDE SETUP / COUNTDOWN
once TDSL=0
once TDSS=0
once BuySetup=0
once SellSetup=0
Once BuyCountdown=0
once SellCountdown=0
Once BuyConditionTDSetup = 0
Once BuyConditionTDSetup = 0
Once BuyConditionTDCount = 0
Once ShortConditionTDCount = 0
if close[1]>close[5] and close<close[4] then
bearishflip=1
bullishflip=0
elsif close[1]<close[5] and close>close[4] then
bullishflip=1
bearishflip=0
endif
if close<close[4] and bearishflip then
TDSL=TDSL+1
TDSS=0
elsif close>close[4] and bullishflip then
TDSS=TDSS+1
TDSL=0
endif
//if TDSL>0 and TDSL<10 then
//SetSellLimit1 = Lowest[TDSS](price)
//TDSTSupport = Lowest[TDSS](Close) //drawtext("#TDSL#",barindex,low-10*pipsize) coloured(0,255,0)
//endif
if TDSL=9 then
L=(low<low[3] and low<low[2]) or (low[1]<low[2] and low[1]<low[3])
bearishflip=0
TDSL=0
BuySetup=1
if L then
BuyConditionTDSetup = 1 //DRAWARROWUP(barindex,low-20*pipsize) coloured(0,255,0)
endif
endif
//if TDSS>0 and TDSS<10 then
//SetBuyLimit1 = Highest[TDSL](price)
//TDSTResistance = Highest[TDSL](Close) //drawtext("#TDSS#",barindex,high+10*pipsize) coloured(255,0,0)
//endif
if TDSS=9 then
S=(high>high[2] and high>high[3]) or (high[1]>high[3] and high[1]>high[2])
bullishflip=0
TDSS=0
SellSetup=1
if S then
ShortConditionTDSetup = 1 //DRAWARROWDOWN(barindex,high+20*pipsize) coloured(255,0,0)
endif
endif
if BuySetup then
if close<=low[2] then
BuyCountdown=BuyCountdown+1
//drawtext("#BuyCountdown#",barindex,low-10*pipsize) coloured(0,0,255)
endif
if BuyCountdown=8 then
Bar8=barindex
elsif BuyCountdown=13 then // TD Countdown perfection buy
if low<=close[barindex-Bar8] then
BuyConditionTDCount = 1 //DRAWARROWUP(barindex,low-20*pipsize) coloured(0,0,255)
endif
BuySetup=0
BuyCountdown=0
endif
elsif SellSetup then
if close>=high[2] then
SellCountdown=SellCountdown+1
//drawtext("#SellCountdown#",barindex,high+10*pipsize) coloured(0,0,255)
endif
if SellCountdown=8 then
Bar8=barindex
elsif SellCountdown=13 then //TD Countdown perfection sell
if high>=close[barindex-Bar8] then
ShortConditionTDCount = 1 //DRAWARROWDOWN(barindex,high+20*pipsize) coloured(0,0,255)
endif
SellSetup=0
SellCountdown=0
endif
endif
//OTHER indicators
//indicator1 = SMI[11,3,5](close)
//Indicator1 = Stochastic[11,3](close)
//Indicator2 = Average[5](indicator1)
//Indicator1 = Volume
//indicator1, indicator2, indicator3 = CALL "Super BandPass(1)"
//Indicator4 = Williams[11](close)
//Indicator5 = RSI[11](close)
Indicator6 = AroonUp[9]
Indicator7 = AroonDown[9]
Indicator8 = Volume
//Buy Conditions
b0 = BuyConditionTDSetup = 1
b1 = BuyConditionTDCount = 1
//b2 = Lowest[t1](close)>TDSTSupport
// Detection of TD Setup buy signal
//b0 = Close[10]>Close[14] AND Close[9]< Close[13]
//b1 = Close < Close[5] AND Close [2] < Close[6] AND Close[3] < Close[7] AND Close[4] < Close[8] AND Close[5] < Close[9] AND Close[6] < Close[10] AND Close[7] < Close[11] AND Close[8] < Close[12] AND Close[9] < Close[13]
// Detection of TD Setup buy signal - perfection
//b2 = Close OR Close[2] < Low[6]
//b3 = Close OR Close [2] < Low[7]
// Bullish Engulfing
b2 = Close[2]>Close[3]
b3 = Close[1]>Open[2] AND Open[1]<Close[2]
b4 = Open>Close[1]
//b5 = Indicator3 CROSSES OVER Indicator1
//b4 = Indicator1 CROSSES OVER Indicator3
//b4 = Indicator1 CROSSES OVER Indicator2 //AND Indicator1 > t5 ///Indicator1 CROSSES OVER Indicator2 AND
//b5 = Indicator4 < - t3
//b6 = Indicator5 < t2
b7 = Indicator6 > 70
b8 = Indicator7 < 30
b9 = Indicator8 > 400
BuyConditions = b0 AND b1 AND b2 AND b3 AND b4 AND b7 AND b8 AND b9 //AND b4 //b2 AND b3 AND b4 AND b5
// Conditions to enter long positions
IF NOT LongOnMarket AND BuyConditions THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
// Conditions to exit long positions
be1 = Open[1]>Close[2] AND Close[1]<Open[2] AND Open<Open[1]
//be2 = POSITIONPERF > 1.5 AND Lowest[7](Close) < Lowest[14](Close)
be2 = Average[20](close) CROSSES UNDER Average[55](Close)
/// Close > Average[20](Close)
LongExitConditions = be1 AND be2//AND be2
If LongOnMarket AND LongExitConditions THEN
SELL AT MARKET
ENDIF
// ***** Short Conditions *****
s0 = ShortConditionTDSetup = 1
s1 = ShortConditionTDCount = 1
//s3 = Highest[t1](close) < TDSTResistance
// Detection of TD Setup Sell signal
//s0 = Close[10]<Close[14] AND Close[9]>Close[13]
//s1= Close > Close[5] AND Close [2] > Close[6] AND Close[3] > Close[7] AND Close[4] > Close[8] AND Close[5] > Close[9] AND Close[6] > Close[10] AND Close[7] > Close[11] AND Close[8] > Close[12] AND Close[9] > Close[13]
// Detection of TD Setup Sell signal - perfection
//s2 = Close OR Close[2] > Low[6]
//s3 = Close OR Close [2] > Low[7]
// Engulfing
s2 = Close[2]<Close[3]
s3 = Close[1]<Open[2] AND Open[1]>Close[2]
s4 = Open<Close[1]
//s5 = Indicator3 CROSSES UNDER Indicator2
///s5 = Indicator4 > -t1
//s6 = Indicator5 > t4
//s4 = Indicator1 CROSSES UNDER Indicator2
//s4 = Indicator1 CROSSES UNDER Indicator2 //AND Indicator1 < 80 //Indicator1 CROSSES UNDER Indicator2 AND Indicator1 < t2
s7 = Indicator6 < 30
s8 = Indicator7 > 70
s9 = Indicator8 > 400
ShortConditions = s0 AND s1 AND s2 AND s3 AND s4 AND s7 AND s8 AND s9// AND s5 //s2 AND s3 AND s4 AND s5
// Conditions to enter short positions
IF NOT ShortOnMarket AND ShortConditions THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
//// ***** SHORT EXIT CONDITIONS
se1 = Open[1]<Close[2] AND Close[1]>Open[2] AND Open>Open[1]
//se2 = Close>Open AND High = Close AND (Open-Low) >= 3*(Close-Open)
//se3 = POSITIONPERF > t1 AND Highest[7](Close) > Highest[14](Close)
se2 = Average[20](close) CROSSES OVER Average[55](Close)
ShortExitConditions = se1 AND se2 //AND se3 //OR se2) AND se3
// Conditions to exit short positions
IF ShortOnMarket AND ShortExitConditions THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets : Enter your protection stops and profit targets here
//IF LongOnMarket Then
//SET TARGET PPROFIT SetLimit1
//SET STOP LOSS SetLimit2
//ENDIF
//IF ShortOnMarket Then
//SET TARGET PROFIT SetLimit1
//SET STOP LOSS SetLimit2
//ENDIF
SET TARGET PROFIT 100 //90//prof
SET STOP PLOSS 40 //30 //los1// 30
// **** Stops and targets ***
//DYNAMIC TRAILING STOP
SL = 40 //30 //los1 //30 // Initial SL
//TP = 30
TSL = 1 // Use TSL?
TrailingDistance = Round(0.85*SL) //Round(0.5*SL) // Distance from close to TSL
TrailingStep = 9 //15 //3 // Pips locked at start of TSL
//************************************************************************
IF TSL = 1 THEN
//reset the stoploss value
IF NOT ONMARKET THEN
newSL = 0
CAND = 0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL = 0 AND CLOSE - TRADEPRICE(1) >= TrailingDistance*PipSize THEN
newSL = TRADEPRICE(1) + TrailingStep*PipSize
ENDIF
//next moves
CAND = BarIndex - TradeIndex
IF newSL > 0 AND CLOSE[1] >= HIGHEST[CAND](CLOSE) THEN
newSL = CLOSE[1] - TrailingDistance*PipSize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL = 0 AND TRADEPRICE(1) - CLOSE[1] >= TrailingDistance*PipSize THEN
newSL = TRADEPRICE(1) - TrailingStep*PipSize
ENDIF
//next moves
CAND = BarIndex - TradeIndex
IF newSL > 0 AND CLOSE[1] <= LOWEST[CAND](CLOSE) THEN
newSL = CLOSE[1] + TrailingDistance*PipSize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL > 0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
SET STOP pLOSS SL
ENDIF
//trailing stop
//longtrail = 13
//shorttrail = 7
//resetting variables when no trades are on market
//if not onmarket then
//MAXPRICE = 0
//MINPRICE = close
//priceexit = 0
//endif
//case SHORT order
//if shortonmarket then
//MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
//if tradeprice(1)-MINPRICE>=shorttrail*pointsize then //if the MFE is higher than the trailingstop then
//priceexit = MINPRICE+shorttrail*pointsize //set the exit price at the MFE + trailing stop price level
//endif
//endif
//case LONG order
//if longonmarket then
//MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
//if MAXPRICE-tradeprice(1)>=longtrail*pointsize then //if the MFE is higher than the trailingstop then
//priceexit = MAXPRICE-longtrail*pointsize //set the exit price at the MFE - trailing stop price level
//endif
//endif
//exit on trailing stop price levels
//if onmarket and priceexit>0 then
//EXITSHORT AT priceexit STOP
//SELL AT priceexit STOP
//endif