ProRealCode - Trading & Coding with ProRealTime™
TimeHunter v1p MOD FIFI
Hey interesting … with no optimisation or even adjustment of Time (yet) for UK Timezone see attached on DJI @ H2 TF.
Well done Paul and Fifi!
Hello,
Cannot add backtest “TIMEHUNTER V1P MODFIFI” PRT wants me to edit the variables.
But the variables are already in the code I don’t understand where is the problem?
Thank you @Grahal !
see attached on DJI @ H2 TF.
Even better on DJI H1 with EntryHour = 15 at Line 42.
Hour 15 being 15:00 to 16:00 UK time is logical as the DJI opens at 14:30 so after half an hour to settle down?
0.2 size
You are showing Size = 1 on your results?
I haven’t yet got decent results on DAX 1 Hour … have you Francesco?
Maybe they were okay. but I was so impressed with the DJI results!? I’ll go back and have a look now I have got the DJI running in Forward Test on Demo.
All hail Paul and Fifi ! 🙂
Yes it’s size 1, I was wrong to write, that’s why I also edited the post
that’s why I also edited the post
We are too quick for each other! 🙂
I have added to my previous with a question for you anyway.
Yes we are 🙂
Anyway, I was not even able to get close to the results of the DAX.
It is probably due to the nature of the asset which is much more versatile for strategies in terms of volatility and trend.
Could someone help in pointing out where I can adjust this?
Change mindist in the code to 15.
But you may still get Rejected as IG ‘Flash widen’ (for several seconds) the spread often.
//-------------------------------------------------------------------------
// Hoofd code : BarHunter v3p
//-------------------------------------------------------------------------
//Germany //24 uur
//01.15-08.00 = 4
//08.00-09.00 = 2
//09.00-17.30 = 1
//17.30-22.00 = 2
//22.00-01.15 = 5
//South Africa 40 //24 uur ZAR50 ZAR10
//07.30-16.30 8
//Alle andere tijden 30
//Wall Street 24 uur $10 / $2
//09.00-15.30 2,4
//15.30-22.00 1,6
//22.15-22.30 9,8
//23.00-00.00 9,8
//Alle andere tijden 3,8
defparam cumulateorders = FALSE
defparam preloadbars = 1000
once enablets = 1 // trailing stop
once enabletsvir = 1 // trailing stop virtual
once displayts = 0 // trailing stop
once holiday = 1
once closebeforeweekend = 0
once closebeforeweekendinloss =0
once securebeforeweekendprofit=0
once entrytype= 1
//entrytype=1 first version with error minimum distance stop
//entrytype=2 entry modified with stop
//entrytype=3 entry modified with market
//entrytype=4 stop distance defnined first entry as entrytype 1
tds= 4// trend detection system off when optimising barnumbers
// separate long/short or go both
once longtrading =1
once shorttrading=1
// select which intradaybar should be analysed (depends on timeframe settings)
once barnumberlong = 3 //long (timezone dependent)
once barnumbershort= 3 //short (timezone dependent)
// select the number of points above/below the breakvaluelong/short
breakpoint=5
//=========
once limitSLbroker=0
if time >210000 and time<070000 and CurrentDayOfWeek>=0 then
limitSLbroker=12
elsif time>070000 and time<210000 and CurrentDayOfWeek>=0 then
limitSLbroker =10
elsif time>210000 and CurrentDayOfWeek>5 then
limitSLbroker=271
endif
//fixed value 10 for dax (the minimum distance the stop can be place to the current close)
if breakpoint <= limitSLbroker then
if (15-breakpoint)>=0 and (15-breakpoint)<=15 then
once minstopdistance=(15-breakpoint)
else
once minstopdistance = 15
endif
else
once minstopdistance = 0
endif
// main criteria
if intradaybarindex=0 then
tradecounter=0
breakvaluelong=99999
breakvalueshort=0
tradeday=1
endif
// holiday
if holiday then
if (Month = 5 AND Day = 1) OR (Month = 12 AND Day >=15) then
tradeday=0
else
tradeday=1
endif
endif
tradecount = tradecounter < 1 //perhaps 2 if using seperate bars for long & short
//
if entrytype>=1 and entrytype<4 then
if longtrading or (longtrading and shorttrading) then
if intradaybarindex=barnumberlong then
breakvaluelong=high
endif
endif
if shorttrading or (longtrading and shorttrading) then
if intradaybarindex=barnumbershort then
breakvalueshort=low
endif
endif
elsif entrytype=4 then
if longtrading or (longtrading and shorttrading) then
if intradaybarindex=barnumberlong then
breakvaluelong=high
if high-close<minstopdistance then
breakvaluelong=close+minstopdistance
else
breakvaluelong=breakvaluelong
endif
endif
endif
if shorttrading or (longtrading and shorttrading) then
if intradaybarindex=barnumbershort then
breakvalueshort=low
if close-low<minstopdistance then
breakvalueshort=close-minstopdistance
else
breakvalueshort=breakvalueshort
endif
endif
endif
endif
// trend detection
if tds=0 then
trendup=1
trenddown=1
else
if tds=1 then
trendup=(Average[10](close)>Average[10](close)[1])
trenddown=(Average[10](close)<Average[10](close)[1])
else
if tds=2 then
bbup=BollingerUp[20](close)
bbdn=BollingerDown[20](close)
bbav=(bbup+bbdn)/2
trendup=bbav>bbav[1]
trenddown=bbav<bbav[1]
else
if tds=3 then
Period= 3
inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
HULL = weightedaverage[round(sqrt(Period))](inner)
trendup = HULL > HULL[1]
trenddown = HULL < HULL[1]
else
if tds=4 then
Period= 2
inner = 2*weightedaverage[round( Period/2)](totalprice)-weightedaverage[Period](totalprice)
HULL = weightedaverage[round(sqrt(Period))](inner)
trendup = HULL > HULL[1]
trenddown = HULL < HULL[1]
endif
endif
endif
endif
endif
// POINT PIVOT HEBDOMADAIRE
IF dayofweek < dayofweek[1] THEN
weeklyhigh = prevweekhigh
weeklylow = prevweeklow
weeklyclose = prevweekclose
prevweekhigh = high
prevweeklow = low
weeklyPivot = (weeklyHigh + weeklyLow + weeklyclose) / 3
ENDIF
prevweekhigh = max(prevweekhigh, high)
prevweeklow = min(prevweeklow, low)
prevweekclose = close
// POINT PIVOT JOURNALIER
IF dayofweek = 1 THEN
dayhigh = DHigh(2)
daylow = DLow(2)
dayclose = DClose(2)
ENDIF
IF dayofweek >=2 and dayofweek < 6 THEN
dayhigh = DHigh(1)
daylow = DLow(1)
dayclose = DClose(1)
ENDIF
Pivot = (dayhigh + daylow + dayclose) / 3
S3 = daylow - 2 * (dayhigh- Pivot)
R3 = dayhigh + 2* (Pivot - daylow)
ecart=4
ecartWP=5
EC= HIGH-low/pointsize
//SP=call"filtre_barhunter"
// entry criteria
if entrytype=1 and tradeday=1 then
// entry criteria
if hour<=21 then
if longtrading then
if intradaybarindex >= barnumberlong then
if trendup and tradecount and (close>pivot or (close <pivot and (pivot-close)/pointsize >ecart)) and (close>weeklypivot or (close <weeklypivot and (weeklypivot-close)/pointsize >ecartWP))and ec>3.9 then
buy 1 contract at breakvaluelong+breakpoint stop
ppf=0
tradecounter=tradecounter+1
endif
endif
endif
if shorttrading then
if intradaybarindex >= barnumbershort then
if trenddown and tradecount and (close<pivot or (close>pivot and (close-pivot)/pointsize >ecart))and (close<weeklypivot or (close>weeklypivot and (close-weeklypivot)/pointsize >ecartWP)) and ec>3.1 then
sellshort 1 contract at breakvalueshort-breakpoint stop
ppf=0
tradecounter=tradecounter+1
endif
endif
endif
endif
elsif entrytype=2 then
if hour<=23 then
if longtrading then
if intradaybarindex >= barnumberlong then
if trendup and tradecount then
if ((breakvaluelong+breakpoint)-close)>=minstopdistance then
buy 1 contract at breakvaluelong+breakpoint stop
tradecounter=tradecounter+1
else
buy 1 contract at close+(minstopdistance+breakpoint) stop
tradecounter=tradecounter+1
endif
endif
endif
endif
if shorttrading then
if intradaybarindex >= barnumbershort then
if trenddown and tradecount then
if (close-(breakvalueshort-breakpoint))>=minstopdistance then
sellshort 1 contract at breakvalueshort-breakpoint stop
tradecounter=tradecounter+1
else
sellshort 1 contract at close-(minstopdistance-breakpoint) stop
tradecounter=tradecounter+1
endif
endif
endif
endif
endif
elsif entrytype=3 then
if hour<=23 then
if longtrading then
if intradaybarindex >= barnumberlong then
if trendup and tradecount then
if high crosses over (breakvaluelong+breakpoint) then
buy 1 contract at market
endif
endif
endif
endif
if shorttrading then
if intradaybarindex >= barnumbershort then
if trenddown and tradecount then
if low crosses under (breakvalueshort-breakpoint) then
sellshort 1 contract at market
tradecounter=tradecounter+1
endif
endif
endif
endif
endif
elsif entrytype=4 then
if hour<=23 then
if longtrading then
if intradaybarindex >= barnumberlong then
if trendup and tradecount then
buy 1 contract at breakvaluelong+breakpoint stop
tradecounter=tradecounter+1
endif
endif
endif
if shorttrading then
if intradaybarindex >= barnumbershort then
if trenddown and tradecount then
sellshort 1 contract at breakvalueshort-breakpoint stop
tradecounter=tradecounter+1
endif
endif
endif
endif
endif
// trailing atr stop
if enablets then
//
once steps=0.05
once minatrdist=3
once atrtrailingperiod = 14 // atr parameter
once minstop = 15 // minimum distance
if barindex=tradeindex then
trailingstoplong = 5 // trailing stop atr distance
trailingstopshort = 5 // trailing stop atr distance
else
if longonmarket then
if newsl>0 then
if trailingstoplong>minatrdist then
if newsl>newsl[1] then
trailingstoplong=trailingstoplong
else
trailingstoplong=trailingstoplong-steps
endif
else
trailingstoplong=minatrdist
endif
endif
endif
if shortonmarket then
if newsl>0 then
if trailingstopshort>minatrdist then
if newsl<newsl[1] then
trailingstopshort=trailingstopshort
else
trailingstopshort=trailingstopshort-steps
endif
else
trailingstopshort=minatrdist
endif
endif
endif
endif
//
atrtrail=averagetruerange[atrtrailingperiod]((close/10)*pipsize)/1000
trailingstartl=round(atrtrail*trailingstoplong)
trailingstarts=round(atrtrail*trailingstopshort)
tgl=trailingstartl
tgs=trailingstarts
//
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
maxprice=0
minprice=close
newsl=0
endif
//
if longonmarket then
maxprice=max(maxprice,close)
if maxprice-tradeprice(1)>=tgl*pointsize then
if maxprice-tradeprice(1)>=minstop then
newsl=maxprice-tgl*pointsize
else
newsl=maxprice-minstop*pointsize
endif
endif
endif
//
if shortonmarket then
minprice=min(minprice,close)
if tradeprice(1)-minprice>=tgs*pointsize then
if tradeprice(1)-minprice>=minstop then
newsl=minprice+tgs*pointsize
else
newsl=minprice+minstop*pointsize
endif
endif
endif
//
if longonmarket then
if newsl>0 then
sell at newsl stop
endif
endif
if shortonmarket then
if newsl>0 then
exitshort at newsl stop
endif
endif
if displayts then
//graphonprice newsl coloured(0,0,255,255) as "trailingstop atr"
endif
endif
// ================trailing atr stop VIRTUAL==================
if enabletsvir then
//
once stepsvir=0
once minatrdistvir=0
once atrtrailingperiodvir = 2 // atr parameter
once minstopvir = 10 // minimum distance
if barindex=tradeindex then
trailingstoplongvir = 5 // trailing stop atr distance
trailingstopshortvir = 5 // trailing stop atr distance
else
if longonmarket then
if newslvir>0 then
if trailingstoplongvir>minatrdistvir then
if newslvir>newslvir[1] then
trailingstoplongvir=trailingstoplongvir
else
trailingstoplongvir=trailingstoplongvir-stepsvir
endif
else
trailingstoplongvir=minatrdistvir
endif
endif
endif
if shortonmarket then
if newslvir>0 then
if trailingstopshortvir>minatrdistvir then
if newslvir<newslvir[1] then
trailingstopshortvir=trailingstopshortvir
else
trailingstopshortvir=trailingstopshortvir-stepsvir
endif
else
trailingstopshortvir=minatrdistvir
endif
endif
endif
endif
//
atrtrailvir=averagetruerange[atrtrailingperiodvir]((close/10)*pipsize)/1000
trailingstartlvir=round(atrtrailvir*trailingstoplongvir)
trailingstartsvir=round(atrtrailvir*trailingstopshortvir)
tglvir=trailingstartlvir
tgsvir=trailingstartsvir
//
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
maxpricevir=0
minpricevir=close
newslvir=0
endif
//
if longonmarket then
maxpricevir=max(maxpricevir,close)
if maxpricevir-tradeprice(1)>=tglvir*pointsize then
if maxpricevir-tradeprice(1)>=minstopvir then
newslvir=maxpricevir-tglvir*pointsize
else
newslvir=maxpricevir-minstopvir*pointsize
endif
endif
endif
//
if shortonmarket then
minpricevir=min(minpricevir,close)
if tradeprice(1)-minpricevir>=tgsvir*pointsize then
if tradeprice(1)-minpricevir>=minstopvir then
newslvir=minpricevir+tgsvir*pointsize
else
newslvir=minpricevir+minstopvir*pointsize
endif
endif
endif
//
if longonmarket and close <newslvir and newslvir>0 then
sell at market
endif
if shortonmarket and close>newslvir and newslvir>0 then
exitshort at market
endif
if displayts then
//graphonprice newsl coloured(0,0,255,255) as "trailingstop atr"
endif
endif
//======================AJOUTER PAR FIFI
PP=positionperf(0)*100
if pp>ppf then
ppf=pp
endif
filtre=call"Forme_bougie"
spread=abs(OPEN-CLOSE)
coeff=spread/highest[200](spread)*100
//=================
// coefficient de la bougie
if longonmarket and barindex-tradeindex>1 AND ppf>0.5 and pp<ppF and coeff<4 and close<positionprice then
sell at market
endif
if longonmarket AND coeff[1]<3 and coeff>80 and close>positionprice then
sell at market
endif
//===============SHORT
if shortonmarket and barindex-tradeindex<3 and pp<ppF and coeff>55 and close>positionprice then
exitshort at market
endif
if shortonmarket and barindex-tradeindex>6 AND ppf>0.1 and pp<ppF and coeff<3 and close>positionprice then
exitshort at market
endif
if shortonmarket AND coeff[1]<6 and coeff>70 and close<positionprice then
exitshort at market
endif
//===================FORME DE BOUGIE
if filtre[1]=-1 and barindex-tradeindex<4 and pp<ppF and longonmarket and close>positionprice then
sell at market
endif
if filtre[1]=-1 and pp>0.7 and pp<ppF and longonmarket and close>positionprice then
sell at market
endif
if filtre=1 and pp>2.5 and pp<PPF and shortonmarket and close<positionprice then
exitshort at market
endif
if filtre[1]=1 and barindex-tradeindex<7 and pp<PPF and shortonmarket and close<positionprice then
exitshort at market
endif
//=====================CROSS POINT DE PIVOT
If longonmarket and close[1] < R3 and high[1]>R3 and open>close and pp>ppF-pp and close>positionprice then
sell at market
endif
if shortonmarket and close[1]>S3 and low[1]<S3 and open<close and pp>ppF-pp and close<positionprice then
exitshort at market
endif
//=======================================
if longonmarket and pp>ppF-pp and close>positionprice and open>close and( (high-open>18)or(open=high and open-close>9)or(open[1]<close[1] and close[1]=high[1] and open[1]>close)) then
sell at market
endif
if shortonmarket and pp>ppF-pp and close<positionprice and open<close and open[1]>close[1] and close[1]=LOW[1] and open[1]<close then
exitshort at market
endif
// test de nombre de bar negative ajouter fifi743
if longonmarket and barindex-tradeindex>138 and close<positionprice then
sell at market
endif
if shortonmarket and barindex-tradeindex>11 and close>positionprice then
exitshort at market
endif
//===============AJOUTER FERMETURE DES POSITIONS RSI ET barindex-tradeindex =====
Myrsi=RSI[15](close)
//34
if Myrsi<47 and barindex-tradeindex>3 and longonmarket and close>positionprice then
sell at market
endif
if Myrsi>69 and barindex-tradeindex>1 and shortonmarket and close<positionprice then
exitshort at market
endif
//=========================NB bar
for i=0 to 3
if longonmarket and barindex-tradeindex<4 AND COEFF[i]>60 AND COEFF<10 and coeff[i]>coeff and ppf=0 then
sell at market
break
endif
if shortonmarket and barindex-tradeindex<5 AND COEFF[i]>60 AND COEFF<10 and coeff[i]>coeff and ppf=0 then
exitshort at market
endif
next
// =================== FORME DE BOUGIE DOJI ====================
if longonmarket and abs(open-close)<1 and high-close>18 and high[1]<high and close>positionprice then
sell at market
endif
if shortonmarket and abs(open-close)<1 and low[1]<low and close<positionprice then
exitshort at market
endif
//====================PAUL
if closebeforeweekend then
if onmarket then
if (dayofweek=5 and hour>=22) then
sell at market
exitshort at market
endif
endif
endif
if securebeforeweekendprofit then
if (dayofweek=5 and hour>=18) then
if longonmarket then
if close>positionprice+15 then
sell at tradeprice(1)+10 stop
//else
//if hour>=22 then
//sell at market
//endif
endif
endif
if shortonmarket then
if close<positionprice-15 then
exitshort at tradeprice(1)-10 stop
else
if hour>=22 then
exitshort at market
endif
endif
endif
endif
endif
if closebeforeweekendinloss then
if (dayofweek=5 and hour>=22) then
if longonmarket then
if close<positionprice then
sell at market
endif
endif
if shortonmarket then
if close>positionprice then
exitshort at market
endif
endif
endif
endif
//==============================
if CurrentDayOfWeek=1 and time>060000 and time<180000 then
SL=160
elsif CurrentDayOfWeek=2 and time>060000 and time<180000 then
SL=160
elsif CurrentDayOfWeek=3 and time>060000 and time<180000 then
SL=170
elsif CurrentDayOfWeek=4 and time>060000 and time<180000 then
SL=130
elsif CurrentDayOfWeek=5 and time>060000 and time<180000 then
SL=150
elsif time>180000 and time<060000 then
sl=270
endif
SET STOP PLOSS sl
//set stop %loss 2
//set target %profit 3
Florian Legeard – I removed your ‘bad’ code and replaced it with the second code that you posted. I also removed the French part of your post.
here’s an early strategy I based on barhunter. It had to be very simple and it isn’t perfect by any stretch but it shows that there’s some predictable behaviour at certain times in the market. Uses market orders, based on 15 minutes, dax.
and here’s TimeHunter v1.01p VS crude oil
take into account, when going back in time and a index is half the value, a stoploss using points or percentage matters.
Same goes using points for a break or percentage. Using percentage can lower the equity curve.
Change mindist in the code to 15. But you may still get Rejected as IG ‘Flash widen’ (for several seconds) the spread often.
Have you been rejected at mindist = 15 Florian?
Try below (for mindist = 30) just so you can understand what goes on and hopefully you may get a trade triggered.
Below relates to Lines 51 to 71 in the code you posted.
Only try on Demo (Not Real Live).
breakpoint=5
//=========
once limitSLbroker=0
if time >210000 and time<070000 and CurrentDayOfWeek>=0 then
limitSLbroker=30
elsif time>070000 and time<210000 and CurrentDayOfWeek>=0 then
limitSLbroker =10
elsif time>210000 and CurrentDayOfWeek>5 then
limitSLbroker=271
endif
//fixed value 10 for dax (the minimum distance the stop can be place to the current close)
if breakpoint <= limitSLbroker then
if (30-breakpoint)>=0 and (30-breakpoint)<=25 then
once minstopdistance=(30-breakpoint)
else
once minstopdistance = 30
endif
else
once minstopdistance = 0
endif
strategy BarHunter DAX v1p
This topic contains 255 replies,
has 11 voices, and was last updated by sfl
2 years, 6 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 01/15/2020 |
| Status: | Active |
| Attachments: | 136 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.