Hi Paul, massive bedankt for all your work on this algo – looking good! Just to confirm, these all optimize @ 1h and run @ 1m — is that right?
And the key variables are the barnumber and the breakpointpercentage?
PaulParticipant
Master
@nonetheless yes your correct. With exception of the oil-strategy which runs in backtest 1h and the same live.
Key variables are the ones you said. You can also finetune fifi743 pivot points.
Anyone else get a rejection on the SAF last night?
“Order level too close to the current market level. Minimum distance is 100 points.”
yes i got the same eroor – the system has stoppend
PaulParticipant
Master
I don’t have it running in demo.
So I assume you guys have it on mode 0 on 1 minute right?
Couldn’t be the stoploss & profit target, since it’s at 2 %
So then it is the trailingstop. Since it’s on 1 minute, you can use cross over/under to exit on market.
// trailing atr stop exits on low timeframe
if longonmarket then
if newsl>0 then
if low crosses under newsl then
sell at market
endif
//sell at newsl stop
endif
endif
if shortonmarket then
if newsl>0 then
if high crosses over newsl then
exitshort at market
endif
//exitshort at newsl stop
endif
endif
Oops, my bad — I’ve got mode = 1 on 1m. Duh…
Thanks Paul.
The reason that that the system has stopped was the uncorrect positionsize , it should set to =2 in the code
No, the positionsize I had right. And that would have given a different error message for the rejection. For me, i’m sure the problem was the mode. We’ll see if it happens again…
Hello Paul,
For SAF the spread is 15 pips ? But Outside market openings the spread is 58 pips no ?
SAF spread is 8 from 6.30 to 15.30 and for all other times is 30.
I remind you that in the last period, with turbulent markets, spreads are generally higher.
Something else to remember … SAF Margin is 10% for retail clients! 🙁
Thanks Francesco and Grahal, tbh I hadn’t checked the spread or the margin – just seemed like a good idea. On second thoughts…
As for indices ‘down under’ I’m getting interested in the ASX. Small spread, good margin rate but almost no one codes for it. With such a large mining sector it must be a lively market. And I esp like the idea of an algo that works while I sleep!
On real account there are no rejections as in demo account for information. Before version 4.5 of PAUL, I launched V4.3 by optimizing the stop.
//-------------------------------------------------------------------------
// hoofd code : barhunter v4.3p mtf mod fifi
//-------------------------------------------------------------------------
// dax 1 hour timeframe
// spread 4
// fm (fifi43 mods)
//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
//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 = 10000
timeframe (default)
once mode = 1 // use [1] for 1 hour timeframe, [0] for 1 minute timeframe
once tds = 3 // trend detection system off when optimising barnumbers
once closebeforeweekend = 0
once securebeforeweekendprofit = 1
// separate long/short or go both
once longtrading =1
once shorttrading =1
once holiday =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
once breakpoint=5
// reset
if intradaybarindex=0 then
tradecounter=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
//
timeframe (1 hour,updateonclose)
if intradaybarindex=0 then
breakvaluelong=99999
breakvalueshort=0
endif
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
// trend detection system
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
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=3 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
// 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
ecart=4
ecartwp=5
// conditions
condbuy=intradaybarindex = barnumberlong
condbuy=condbuy and trendup
condbuy=condbuy and (close>pivot or (close <pivot and (pivot-close)/pointsize >ecart))
condbuy=condbuy and (close>weeklypivot or (close <weeklypivot and (weeklypivot-close)/pointsize >ecartwp))
condsell=intradaybarindex = barnumbershort
condsell=condsell and trenddown
condsell=condsell and (close<pivot or (close>pivot and (close-pivot)/pointsize >ecart))
condsell=condsell and (close<weeklypivot or (close>weeklypivot and (close-weeklypivot)/pointsize >ecartwp))
timeframe (default)
// entry criteria
if mode then
if tradeday and tradecounter < 1 then
if longtrading and condbuy then
buy 1 contract at breakvaluelong+breakpoint stop
tradecounter=tradecounter+1
endif
if shorttrading and condsell then
sellshort 1 contract at breakvalueshort-breakpoint stop
tradecounter=tradecounter+1
endif
endif
else
if tradeday and tradecounter < 1 then
if longtrading and condbuy then
if high > breakvaluelong+breakpoint then
buy 1 contract at market
tradecounter=tradecounter+1
endif
endif
if shorttrading and condsell then
if low < breakvalueshort-breakpoint then
sellshort 1 contract at market
tradecounter=tradecounter+1
endif
endif
endif
endif
timeframe (1 hour, updateonclose)
// trailing atr stop
once trailingstoptype = 1 // trailing stop - 0 off, 1 on
once trailingstoplong = 4 // trailing stop atr relative distance
once trailingstopshort = 4 // trailing stop atr relative distance
once atrtrailingperiod = 14 // atr parameter value
once minstop = 10 // minimum trailing stop distance
// trailingstop
//----------------------------------------------
atrtrail = averagetruerange[atrtrailingperiod]((close/10)*pipsize)/1000
trailingstartl = round(atrtrail*trailingstoplong)
trailingstarts = round(atrtrail*trailingstopshort)
if trailingstoptype = 1 then
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
endif
timeframe (default)
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
//graphonprice newsl coloured(0,0,255,255) as "trailingstop atr"
timeframe (1 hour, updateonclose)
// mod fifi43
once enabletsvir =0 //trailing atr stop virtual
once bna =0 //test de nombre de bar negative ajouter fifi743
once afprsi =0 //ajouter fermeture des positions rsi et barindex-tradeindex
once bougiedoji =1 //
once timeadjustablestoploss=0 //
// ================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
//graphonprice newsl coloured(0,0,255,255) as "trailingstop atr"
endif
// test de nombre de bar negative ajouter fifi743
if bna then
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
endif
//=============== ajouter fermeture des positions rsi et barindex-tradeindex =====
if afprsi then
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
endif
// =================== forme de bougie doji ====================
if bougiedoji then
if longonmarket and abs(open-close)<1 and high[1]<high and close>positionprice and high-close>18 then
sell at market
endif
if shortonmarket and abs(open-close)<1 and low[1]<low and close<positionprice then
exitshort at market
endif
endif
//==============================
if timeadjustablestoploss then
if hour>6 and hour<18 then
sl=160
else
sl=270
endif
set stop ploss sl
else
set stop ploss 230
endif
timeframe (default)
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+20 then
sell at tradeprice(1)+10 stop
//else
//if hour>=22 then
//sell at market
//endif
endif
endif
if shortonmarket then
if close<positionprice-20 then
exitshort at tradeprice(1)-10 stop
else
if hour>=22 then
exitshort at market
endif
endif
endif
endif
endif
set target %profit 1
//graph barindex-tradeindex
//graph intradaybarindex
//graphonprice breakvaluelong
//graphonprice breakvalueshort
//graph breakvaluelong
//graph breakvalueshort