BCParticipant
Master
Hi Grahal
Sound right, all I can do now is compare live result again, but no deal on yesterday and today.
Your Strat is very good Bin!
I tried 3 or 4 times to minus 7 hours from all your times (UTC +8) to get to my time (GMT +1 / UTC +1) but I’m sure due to my ‘finger trouble’ I got big overall loss.
So I changed my Platform to UTC +8 and now it works great, results attached.
When I get the GMT+1 times correct, I’ll post the code on here so others can test and we can compare Trades.
GraHal
EricParticipant
Master
I dont know why this strategy perform different live versus backtest
But generally speaking about this “spread” thing
When dealing with IG CFD/SB you have a midprice (that price we see on the charts and if nothing has changed lately also used in backtesting)
and then you have the spread we can call it bid and ask, if the spread are 12 points and the midprice is 1000 then the bid is 994 and ask 1006
when trading live with stop and limit you can get filled on a stoporder even if the midprice not touch the stop and to get filled on the limitorder the midprice must be 6 points higher then the limit
The problem is if the bid touch the stop and the midprice dont and if midprice touch the limit but not the ask
this problem is bigger with bigger spread (and many trades with small win/loss), if trading dax with 0,5 on each side you probably get filled on every trade
If i am wrong about this please enlighten me
(when using markets order this is not a problem, only stops and limits)
EricParticipant
Master
When thinking about it why not use one version in live and a version with spread added (in the code) in backtesting then the result would be similar?
when dealing with large spread and stop/limit
BCParticipant
Master
Hi Eric
Yes, that’s what I think (Wish I am wrong instead of PRT bugs).
I already start live (no spread built in, with little bit amend) 2 days ago, but no trade trigger due to market situtation.
//Market: Hong Kong HS50 Cash (HKD10 Mini)
//Time Zone: UTC+8:00
//Time Frame: 15 mins
//Please manual stop the system on Hong Kong public hoilday.
//Remark: Offical HSI future night trade start from 2013-04-08, 17:00-23:00, amended on 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
//Money management
ONCE PositionSize = 1
ONCE Capital = 10000
ONCE Risk = 5
ONCE MaxD = 50 // Quit system if highest 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(120,(max(30,((DailyHigh - DailyLow)))))
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/4))
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 pLOSS sl
SET TARGET pPROFIT tp
ENDIF
Hi!
@Grahal, Did you manage to translate it to CET? Ive tried a couple of times to but have the same problem.
Do you know why @Nicolas?
@Henrik ah I thought it was me! No I’ve not done it again since, forgot sorry and been out over Easter holiday.
I had 4 attempts to change all the times (to UTC+1) and was more deliberate and careful each successive time, I even used find & replace and none of my attempts worked / produced good results.
Weird … only thing I can think of is that not all Bins times are UTC +8?
What you reckon @Bin … is every time used in your code set to UTC + 8 please?
Thanks
GraHal
I tried also to change the code for +1GMT, even change all Asian market to +8GMT but nothing worked.
cheers Kasper
Worked good for me if I changed my whole Platform time to UTC +8 (see my results here #31949).
This is very odd, we need to find the reason?
I know it sounds daft, but please Bin say what time it is where you are and post the time on a message here. Whoever sees your post as soon as you post it then check what your clock is showing and post here?
GraHal
BCParticipant
Master
Hi Grahal
Yes, I think change whole platform time to UTC+8:00 before backtest or start live is the only choice. Just like Reiner Hang Seng PF, I try to many many setting to fit for UTC+8:00 but failed. Finally I change whole platform time to UTC+1:00 and then start the system. (May be the issue of summer and winter time? )
Hi Bin and Grahal!
I need CET time for my other strategies, so i need to figure something out here.
@BIN are you shore you have +8 setting on hs chart?
I ran original code with CET times and got a simular result but not the same, See lower test on picture on erlier post.
Regards
Henrik
BCParticipant
Master
No luck, live and back test result still different on no [spread] version.
Live exit on 19:00 but back test exit on 18:00.
@Bin when next you post, please type on this Page the time that the clock on your computer is shwoing when you press Submit below.
Thank You
GraHal