Good Day
We can use this thread to further discuss possible enhancements on the Combined Supertrend EURUSD 4Hr strategy posted in the Library:
https://www.prorealcode.com/prorealtime-trading-strategies/combined-supertrend-eurusd-4hr/
Hi @Juanan71 please might you share the changes you made to Juanj code?
Juanj code is well good, your changes make the equity curve look sooo good, you will understand we are interested in, and want to learn from, the coding details!?
Did it take you long?
Thank You
GraHal
Is no good..other backtest bug…does not work on real
@juanan71 it be good to share your version of the code anyway, others may spot the problem and then we all good to go!?
Or was it that you did not have the tick by tick box checked??
Cheers
GraHal
Problem is backtest does not work like demo mode in real time.Backtest make many neutral trades in 0 but really in demo mode is not like that…these trades close at stop loss ..never in be and i dont know why
Just i’ve added the trailing stop made for Nicolas time ago but this trailing is aplyed at the close of candle and no follow the price…problem…when sl or trailing step is in the same candle backtest can not calculate and return very good results but are not reals.
Code of trailing is this but i dont know how integrate it because does not work properly…try this…copy and paste this code at final of any system you have and check resuts in 2h,4h,1h… you will see are amazing but no real
128 line to final add to any other code
Defparam cumulateorders = false
possize = 1
//////////////////////////////////////////////////////////////
//Andrew Abraham Trend Trader
//Posted by @Nicolas in PRC Library
/////////////////////////////////////////////////////////////
Length = 21
Multiplier = 3
avrTR = weightedaverage[Length](AverageTrueRange[1](close))
highestC = highest[Length](high)
lowestC = lowest[Length](low)
hiLimit = highestC[1]-(avrTR[1]*Multiplier)
lolimit = lowestC[1]+(avrTR[1]*Multiplier)
if(close > hiLimit AND close > loLimit) THEN
ret = hiLimit
ELSIF (close < loLimit AND close < hiLimit) THEN
ret = loLimit
ELSE
ret = ret[1]
ENDIF
/////////////////////////////////////////////////////////////
//Simplified supertrend (without volatility component ATR)
//Posted by @verdi55 in PRC Library
/////////////////////////////////////////////////////////////
ONCE direction = 1
ONCE STlongold = 0
ONCE STshortold = 1000000000000
factor = 0.005
indicator1 = medianprice
indicator3 = close
indicator2 = indicator3 * factor
STlong = indicator1 - indicator2
STshort = indicator1 + indicator2
If direction = 1 and STlong < STlongold then
STlong = STlongold
endif
If direction = -1 and STshort > STshortold then
STshort = STshortold
endif
If direction = 1 and indicator3 < STlong then
direction = -1
endif
If direction = -1 and indicator3 > STshort then
direction = 1
endif
STlongold = STlong
STshortold = STshort
If direction = 1 then
ST = STlong
else
ST = STshort
endif
/////////////////////////////////////////////////////////////
//PRC_adaptive SuperTrend (r-square method) | indicator
//Posted by @Nicolas in PRC Library
/////////////////////////////////////////////////////////////
Period = 10
mult = 2
Data = customclose
SumX = 0
SumXX = 0
SumXY = 0
SumYY = 0
SumY = 0
if barindex>Period then
// adaptive r-squared periods
for k=0 to period-1 do
tprice = Data[k]
SumX = SumX+(k+1)
SumXX = SumXX+((k+1)*(k+1))
SumXY = SumXY+((k+1)*tprice)
SumYY = SumYY+(tprice*tprice)
SumY = SumY+tprice
next
Q1 = SumXY - SumX*SumY/period
Q2 = SumXX - SumX*SumX/period
Q3 = SumYY - SumY*SumY/period
iRsq=((Q1*Q1)/(Q2*Q3))
avg = supertrend[mult,round(Period+Period*(iRsq-0.25))]
EndIf
//////////////////////////////////////////////////////////////////
OriginalST = Supertrend[3,5]
/////////////////////////////////////////////////////////////////
margin = 7*pointsize
If countofposition = 0 and abs(ret[1]-ST[1]) > margin and abs(ret-ST) > margin Then
If close > ret and close > ST and close > avg Then
Buy possize contract at market
ElsIf close < ret and close < ST and close < avg Then
Sellshort possize contract at market
EndIf
ElsIf longonmarket and ((abs(ret[1]-ST[1]) < margin and abs(ret-ST) < margin) or ((close < ret and close < ST and close < avg and close < OriginalST) and (close[1] < ret[1] and close[1] < ST[1] and close[1] < avg[1] and close[1] < OriginalST[1]))) Then
Sell at market
ElsIf shortonmarket and ((abs(ret[1]-ST[1]) < margin and abs(ret-ST) < margin) or ((close > ret and close > ST and close > avg and close > OriginalST) and (close[1] < ret[1] and close[1] < ST[1] and close[1] > avg[1] and close[1] < OriginalST[1]))) Then
Exitshort at market
EndIf
SL = 20//15//20 // Initial SL
TP = 0//30
TSL = 1 // Use TSL?
TrailingDistance =5// 20//20//20 // Distance from close to TSL
TrailingStep =5// 20//20//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
set target pprofit tp
ENDIF
@Juanan71 thanks for sharing.
Your problem … Backtest make many neutral trades in 0 … is due to the tick by tick box not being checked during backtesting. See attached image.
To make backtest work like real trading it has to be in tick by tick mode … because that is what happens in real trading.
If you want more information then search for zero bars on this site. Or, as it is quite boring, save yourself time and just accept the explanation above 🙂 (0 bars / zero bars is called other names also on here, but it’s so long since I’ve looked at this I’ve forgotten the other names! 🙂 )
Cheers
GraHal
So you mean should make backtest ithout tick by tick? my english is not so good…and really the good resuts was without tick by tick in this case?
No it has to be with tick by tick selected to work as near as possible to Live Trading.
Also, I think your setting of TP = 0 in your code is why there’s massive difference between the optimised results table (shows bad) and the equity curve (shows good!) … even with tick by tick selected. See attached.
I will continue to think on this while I have a shave! Often have brainwaves while shaving / cleaning teeth and away from the screen! 🙂
I haven’t studied / understood your code, but when there is a zero bar / 0 bar then on the equity curve it is showing as 0 profit but in reality it has been a SL value loss (in my case attached SL = £55 loss!
But the odd thing is … some 0 bars / zero bars do show as -£55 loss (see attached) so still some thinking to do! 🙂
I went over a few trades bar by bar on a 1 min TF and the anomaly (see line above) doesn’t seem to be related to whether a profit is hit before the -55 loss or vice versa.
Any comments anyone??
GraHal
Often have brainwaves while shaving / cleaning teeth and away from the screen!
I should try it.
You should – I have my best ideas in the shower. I am sometimes in there for far too long though!
I still dont know whats exactly the problem….my idea is keep these neutral trades because are important….If can not be neutral maybe loss 1 or 2 points but if i have more winning trades it will be good..any idea for make this neutral trades if price turn back? i mean if price go up for later go down…be sure will not arrive to sl but if price goes down at the beggining of the trade is no problem if arrives to sl…
If you have a good strategy and a good entry system winning the most times and keeping neutral others….we’ll have a good system i think but
if i’m working on a system and after a hard job tested with tic by tic and results are so good but no real…why work? maybe you’ll found other prt bug and all your job is lost again
Often have brainwaves while shaving / cleaning teeth and away from the screen!
I should try it.
Vonasi wrote
You should – I have my best ideas in the shower. I am sometimes in there for far too long though!
Maybe Nicolas means he should try just getting away from the screen !!?? 🙂 🙂
Por ejemplo este sistema…de que me sirve trabajar en él si resuta que luego no va a hacer lo que debe hacer…quién me dice que cualquier otro que haga no pasará lo mismo y seguira fallando una y otra cosa???…no me fio para nada ya de los backtest ni del propio prorealtime…creo que tiene muchas cosas que pulir y arreglar.
Me siento decepcionado
@Juanan71 logically the value TP = 0 (your code above line 129 & line 175) is corrupting all the figures. Why have a Take Profit / TP at 0??
Best you read up on the 0 bars / zero bars issue (search on this site) as maybe this is the only way to appreciate what is happening?
Also you have the settings below on Nicolas Trailing Stop. These are not realistic as a trailing distance of 5 would get hit all the time?? The minimum on Dax is 6 points anyway and price retraces 6 points (in a few seconds) at almost every move up / down > 10 to 12 points.
TrailingDistance =5// 20//20//20 // Distance from close to TSL
TrailingStep =5// 20//20//3 // Pips locked at start of TSL
GraHal