BCParticipant
Master
This is a Breakout system made for IG market [ Hong Kong HS50 Cash (HKD10 Mini)], Time Frame: 15 mins.
All components were found from PRT forum, the core idea was from Reiner DAX Breakout system and Nicolas trailing stop. Walk forward test was not 100% perfect, Monte Carlo simulation with latest 12-month back test record show HKD$10,000 for the initial capital is ok.
But unfortunally, my live test result was not same as back test, I can’t find what’s wrong with my limited knowledge, hope you guys can help and determine what mistake inside.
// Market: Hong Kong HS50 Cash (HKD10 Mini)
//Time Frame: 15 mins
//Remark: HSI night trade start from 2013-04-08, 17:00-23:00,
//amended from 2014-11-03, 17:15-23:45
// code-parameter
DEFPARAM FlatAfter = 234500 //234500
// window high/low calculation
ONCE StartTime = 90000//91500
ONCE EndTime = 93000//100000
// trading window
ONCE BuyTime = EndTime
ONCE SellTime = 234500 //234500
//Spread
Spread=6
//Money management
ONCE PositionSize = 1
ONCE Capital = 10000
ONCE Risk = 5
ONCE MaxD = 50 // Quit system if highestc close account balance drop over xx%
equity = Capital + StrategyProfit
maxrisk = round(equity*(Risk/100))
//Check system account balance
if equity<QuitLevel then
quit
endif
recordhighest = MAX(recordhighest,equity)
QuitLevel = recordhighest*((100-MaxD)/100)
//MA Filter
FMA=Average[80](close)
SMA=Average[200](close)
// calculate breakout box high/low and sl/tp
IF Time >= StartTime AND Time <= EndTime THEN
IF TIME = StartTime THEN
DailyHigh = High
DailyLow = Low
ENDIF
IF High > DailyHigh THEN
DailyHigh = High
ENDIF
IF Low < DailyLow THEN
DailyLow = Low
ENDIF
sl = min(110,(max(30,((DailyHigh - DailyLow)+Spread))))
tp = sl*4
PositionSize = min(10,(max(1,abs(round((maxrisk/sl)/PointValue)*pipsize))))
TradeCounterLong = 0
TradeCounterShort = 0
ENDIF
//Define the best trading day and time and avoid trading at lunch & teakbreak high spread period, please manual stop system on Hong Kong public hoilday.
//Long
LOK1=currentdayofweek=1 and ((time>=091500 and time<120000) or (time>=130000 and time<160000) or (time>=171500 and time<230000))
LOK2=currentdayofweek=2 and ((time>=091500 and time<120000) or (time>=130000 and time<160000) or (time>=171500 and time<230000))
LOK3=currentdayofweek=3 and ((time>=091500 and time<120000) or (time>=130000 and time<160000) or (time>=171500 and time<230000))
LOK5=currentdayofweek=5 and ((time>=130000 and time<160000) or (time>=171500 and time<230000))
//Short
SOK1=currentdayofweek=1 and ((time>=091500 and time<120000) or (time>=130000 and time<160000) or (time>=171500 and time<230000))
SOK2=currentdayofweek=2 and ((time>=130000 and time<160000) or (time>=171500 and time<230000))
SOK4=currentdayofweek=4 and ((time>=091500 and time<120000) or (time>=171500 and time<230000))
SOK5=currentdayofweek=5 and ((time>=091500 and time<120000) or (time>=130000 and time<160000) or (time>=171500 and time<230000))
// Position management
IF Time >= BuyTime AND Time <= SellTime THEN
//Long Entry
IF Not LONGONMARKET and (LOK1 or LOK2 or LOK3 or LOK5) and close>DailyHigh and FMA>SMA and TradeCounterLong=0 THEN
BUY PositionSize CONTRACT AT MARKET
TradeCounterLong = TradeCounterLong + 1
ENDIF
//Short Entry
IF Not SHORTONMARKET and (SOK1 OR SOK2 OR SOK4 OR SOK5) and close<DailyLow and FMA<SMA AND TradeCounterShort=0 THEN
SELLSHORT PositionSize CONTRACT AT MARKET
TradeCounterShort = TradeCounterShort + 1
ENDIF
// trailing stop function
ONCE trailingStepLong = 0.08// in %
ONCE trailingStepShort = 0.08 // in %
trailingStartLongInPoints = max(30,(TP/5))
trailingStartShortInPoints = max(30,(TP/5))
trailingStepLongInPoints = max(10,(tradeprice(1) * trailingStepLong / 100))
trailingStepShortInPoints = max(10,(tradeprice(1) * trailingStepShort / 100))
// reset the stoploss value
IF NOT ONMARKET THEN
newSL = 0
ENDIF
// manage long positions
IF LONGONMARKET THEN
// first move (breakeven)
IF newSL = 0 AND close - tradeprice(1) >= trailingStartLongInPoints * pipsize THEN
newSL = tradeprice(1) + trailingStepLongInPoints * pipsize
ENDIF
// next moves
IF newSL > 0 AND close - newSL >= trailingStepLongInPoints * pipsize THEN
newSL = newSL + trailingStepLongInPoints * pipsize
ENDIF
ENDIF
// manage short positions
IF SHORTONMARKET THEN
// first move (breakeven)
IF newSL = 0 AND tradeprice(1) - close >= trailingStartShortInPoints * pipsize THEN
newSL = tradeprice(1) - trailingStepShortInPoints * pipsize
ENDIF
// next moves
IF newSL > 0 AND newSL - close >= trailingStepShortInPoints * pipsize THEN
newSL = newSL - trailingStepShortInPoints * pipsize
ENDIF
ENDIF
// stop order to exit the positions
IF newSL > 0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
// close positions
IF Time = SellTime THEN
IF LONGONMARKET THEN
SELL AT MARKET
ENDIF
IF SHORTONMARKET AND Time = SellTime THEN
EXITSHORT AT MARKET
ENDIF
ENDIF
// stops and targets
SET STOP LOSS sl
SET TARGET PROFIT tp
ENDIF
BCParticipant
Master
1st pic: no money management
2nd pic: with money management
3rd pic: MB Result
BCParticipant
Master
Walk forward test attached.
Your “limited knowledge” give great result as far as I can see on what you are sharing here! WF test seems great too with nice OOS results. So far I didn’t see something ‘strange’ in your code. I’m not used to trade or develop system with Hang Seng myself so please excuse my “limited knowledge” about it 🙂
What are exactly the difference between backtest and real trading? How did you simulate the HS50 spread in backtests?
Your ‘spread’ variable defined at line 18, may be the cause of differences, I remembered have read the same thing in the Pathfinder thread long time ago (I think it comes from there?), since you made calculation with it to define price levels and because this value may surely be different in real life, some dissimilarities should occur I think.
EricParticipant
Master
Yes the spread can be a problem (when using it in the code)
Say you have a spread of 12 (6 on each side) and you put a stoporder to buy at 10 000 (that would be 10 006)
and if price hit 10 001 the trade is open in real trading
but in backtest the price never hit the stoporder and no trade
EricParticipant
Master
Its late and i am tired so i try again
If the spread is 12 (6+6) and you want to put a stoporder to sell if price hit 10 000 minus spread (9 994 in the code)
then when the price hit 10 000 in real trading the trade is executed
but in backtest price have to hit 9 994
the problem is if price turns and never reach 9 994 then you have a difference real versus BT
BCParticipant
Master
Hi Nicolas
Thanks for your comment, I start PRT and found this nice website on Sep 2016, although spend many hours on it, still not well equipped to create some new idea.
Back to this system, I use 6 spread for backtest (pic attached).
About line 16, my thinking is let the SL don’t affect by the IG spread, but your advise may be right. I already take out this [spread] and put in Live trade again to test the different between backtest result.
BCParticipant
Master
Hi Eric
Thanks for your advise, it seems logical. I will try again without this [spread].
BCParticipant
Master
Hi Nicolas and Eric
I check again live and backtest record, most big different came from exit which close to 6.
Although entry price got little bit different, but it can accept.
Really hope all mistake and error is come from me, not PRT. 🙏🙏
What do you mean by “which close to 6”?
IMO, if you made changes in the code, you should make a new comparison between live and backtests in a few days.
Hi!
I tested your strat, but i cant get the same results. What timezone do you use? What spread do you use in backtests? When i use CET time with original code and without spread i get a result simular to yours but not so good (see picture).
About the spread i the code it should just be a number called spread to calculate the sl. So i dont think thats the diffrense.
Whats the diffrence for you between live/demo and backtests?
Regards
Henrik
BCParticipant
Master
Hi Nicolas
I will test again and make a new comparison.
Hi Henrik
Thanks for your test, Time zone is UTC+8:00 andI use 6 spread for backtest (pic attached at post #31804).
Different between live and backtest pic attached at post #31808.
Hi Bin and Nicolas?!
Thanks! I looked pic attached at post #31808. and i think its mostly slippage. But look att the time where the orders are done. I did the same with my hs Pathfinder, a couple of sec fine for me but hours? Look at order on mars 21 and 16…..
Regards
Henrik
BCParticipant
Master
Hi Henrik
I remember the original HS pathfinder use 12 spread at backtest, may be that’s the reason of difeerent, because the highest spread of HS at IG is 20.
For my system, 90% of time trade at 6 spread peroid.
I agree Henrik use of term ‘spread’ in code is misleading because it bears no relation to spread applied by the dealer (PRT does not link to dealer spread)?
Whatever value is put against spread it is just another variable value, so maybe we should not use the term ‘spread’ in code then we stop confusing our brains and others / newbies?
Or am I wrong in my assertions / conclusions?
GraHal