ProRealCode - Trading & Coding with ProRealTime™
@MAKSIDE yes I tried that, but it didn’t go anywhere. I will’ve a look again.
I’ve been trying to apply ATR code to dynamically adjust the boxsize with little success. I tried optimising the strategy to 500 ticks (on the 10s version) and it prooved to be succesful in the short term with a very small box size.
So I tried to apply the Volatility Breakout Indicator (https://www.prorealcode.com/prorealtime-indicators/volatility-breakout-indicator/) to enter long only when it’s above the upper channel in timeframe 100seconds and vice verca for short conditions.
It seems to be that a small box size doesn’t work most of times as the price quickly retraces and gest stopped out, however from my backtest it looks like it could work when applying this indicator. Maybe this is a way to always use a small box size and having minimum drawdown? Although the % of winning trades are lower than 50% it seems that the losses are small (as momentum is no our side) and the gains are high.
I will test this on demo tomorrow – it would be amazing if we could have a set box size that worked all the time!
//variation of renko strategy with volatility cycle indicator to filter. This allows for a smaller box size to be used with high accuracy.
//————————————————————————-
// Hoofd code : renko v3.2 dji 10 sec(V2)
//————————————————————————-
// see notes for spread
defparam cumulateorders = false
defparam preloadbars = 1000
defparam flatbefore = 130000
defparam flatafter = 211500
timeframe (100 seconds)
myupperchannel, mylowerchannel = CALL “PRC_Volatility Cycle Breakout”[18, 2, 10, 0.1]
timeframe (default)
once spreadmode = 1 // [1]dji;[2]us500;[3]us100;[4]dax;[5]saf;[6]ftse;[7]cac40
once orderhandling = 1 // [0] default; [1] based on open v/d market order
once orderoffset = 1 // % average slippage & spread points if above=[1]
once trailingstoptype = 2 // [0]off [1]original [2]modified(faster)
once positionsize = 1
once tradetype = 1 // [1]long&short;[2]long;[3]short
once closeonreversal = 1 // break renko other side
once closeonbreak = 1 // close on breaking previous x high / low
once periodr = 1 //0all;1day;2week;3month;4year
once maxprofit = 100 //set high to make it useless, or to i.e. 2 %
once maxloss = 100 //set high to make it useless, or to i.e. 2 %
// boxsize settings
boxsize = 1.3
once renkomax = round(close / boxsize) * boxsize
once renkomin = renkomax – boxsize
if close > renkomax + boxsize and not (close < renkomin – boxsize) then
renkomax = renkomax + boxsize
renkomin = renkomin + boxsize
endif
if close < renkomin – boxsize and not (close > renkomax + boxsize) then
renkomax = renkomax – boxsize
renkomin = renkomin – boxsize
endif
//================================
// limit losses & secure profit
if periodr=0 then
if barindex=0 then
longperf=0
shortperf=0
tradecounter=0
tradecounterlong=0
tradecountershort=0
endif
elsif periodr=1 then
if day<>day[1] then
longperf=0
shortperf=0
tradecounter=0
tradecounterlong=0
tradecountershort=0
endif
elsif periodr=2 then
if dayofweek=0 then
longperf=0
shortperf=0
tradecounter=0
tradecounterlong=0
tradecountershort=0
endif
elsif periodr=3 then
if month<>month[1] then
longperf=0
shortperf=0
tradecounter=0
tradecounterlong=0
tradecountershort=0
endif
elsif periodr=4 then
if year<>year[1] then
longperf=0
shortperf=0
tradecounter=0
tradecounterlong=0
tradecountershort=0
endif
endif
if longonmarket[1] and (not onmarket or shortonmarket) then
if strategyprofit[1]>=strategyprofit[2] then
longperf=longperf+positionperf(1)*100
else
longperf=longperf-positionperf(1)*100
endif
endif
if shortonmarket[1] and (not onmarket or longonmarket) then
if strategyprofit[1]>=strategyprofit[2] then
shortperf=shortperf+positionperf(1)*100
else
shortperf=shortperf-positionperf(1)*100
endif
endif
if longperf>maxprofit or longperf<-maxloss then
tradelong=0
else
tradelong=1
endif
if shortperf>maxprofit or shortperf<-maxloss then
tradeshort=0
else
tradeshort=1
endif
//=================================
// strategy
once periodeb = 15
once nbchandelierb = 30
mmb = exponentialaverage[periodeb](totalprice)
pente = (mmb-mmb[nbchandelierb]*pipsize) / nbchandelierb
//buy conditions
condbuy = (pente > -0.5)
//short conditions
condsell = (pente < -1)
if range<>0 then
spreadOC=abs(open-close)
coeff=spreadOC/highest[6](spreadOC)*100
else
coeff=0
endif
// conditions
condbuy=condbuy and high > (renkomax + boxsize)
condbuy=condbuy and coeff<15
condsell=condsell and low < (renkomin – boxsize)
condsell=condsell and coeff<15
// entry
If (tradetype=1 or tradetype=2) and tradelong and close > myupperchannel then
if condbuy and not longonmarket then
buy positionsize contract at market
tradecounter=tradecounter+1
tradecounterlong=tradecounterlong+1
endif
endif
if (tradetype=1 or tradetype=3) and tradeshort and close < mylowerchannel then
if condsell and not shortonmarket then
sellshort positionsize contract at market
tradecounter=tradecounter+1
tradecountershort=tradecountershort+1
endif
endif
// closeonreversal
if closeonreversal then
if longonmarket then
sell at (renkomin – boxsize) stop
endif
if shortonmarket then
exitshort at (renkomax + boxsize) stop
endif
endif
// close on break previous high/low
if closeonbreak then
if longonmarket and (shortonmarket[1] or not onmarket[1]) then
breakvaluelow=lowest[10](low)
endif
if longonmarket then
sell at breakvaluelow stop
endif
if shortonmarket and (longonmarket[1] or not onmarket[1]) then
breakvaluehigh=highest[10](high)
endif
if shortonmarket then
exitshort at breakvaluehigh stop
endif
endif
// spread has to be set in the backtest-engine too
// spread
if spreadmode=1 then // wallstreet
if time > 090000 and time <= 153000 then
spread=2.4
elsif time > 153000 and time <= 220000 then
spread=1.6
elsif time > 221500 and time <= 223000 then
spread=9.8
elsif time > 230000 and time <= 235959 then
spread=9.8
elsif time = 000000 then
spread=9.8
else
spread=3.8
endif
elsif spreadmode=2 then // us500
if time > 090000 and time <= 220000 then
spread=0.4
elsif time > 221500 and time <= 223000 then
spread=1.5
elsif time > 223000 and time <= 235959 then
spread=1.5
elsif time = 000000 then
spread=1.5
else
spread=0.6
endif
elsif spreadmode=3 then // us100
if time > 153000 and time <= 220000 then
spread=1
elsif time > 221500 and time <= 223000 then
spread=5
elsif time > 230000 and time <= 235959 then
spread=5
elsif time = 000000 then
spread=5
else
spread=2
endif
elsif spreadmode=4 then // dax
if time > 090000 and time <= 173000 then
spread=1
elsif time > 173000 and time <= 220000 then
spread=2
elsif time > 220000 and time <= 235959 then
spread=7
elsif time >= 000000 and time <= 080000 then
spread=7
elsif time > 080000 and time <= 090000 then
spread=2
endif
elsif spreadmode=5 then // south african 40
if time > 073000 and time <= 163000 then
spread=8
else
spread=30
endif
elsif spreadmode=6 then // ftse100
if time > 080000 and time <= 163000 then
spread=1
elsif time > 163000 and time <= 210000 then
spread=2
elsif time > 070000 and time <= 075000 then
spread=2
else
spread=5
endif
elsif spreadmode=7 then // cac40
if time > 090000 and time <= 173000 then
spread=1
elsif time > 173000 and time <= 220000 then
spread=2
elsif time > 220000 and time <= 235959 then
spread=5
elsif time > 000000 and time <= 080000 then
spread=5
elsif time > 080000 and time <= 090000 then
spread=2
endif
endif
spread=spread/2
// orderhandling
if orderhandling then
once orderprice=close // prevent graph orderprice at 0 at start chart
offsetvalue=((close/10000)*orderoffset)*pointsize // adjustment spread & slippage
if longonmarket and not longonmarket[1] then
orderprice=open+offsetvalue+spread
elsif shortonmarket and not shortonmarket[1] then
orderprice=open-offsetvalue-spread
endif
if longonmarket then
pp=((close/orderprice)-1)*100
elsif shortonmarket then
pp=((orderprice/close)-1)*100
elsif not onmarket then
pp=0
endif
else
once orderprice=close // prevent graph orderprice at 0 at start chart
orderprice=tradeprice(1)
if longonmarket then
pp=((close/orderprice)-1)*100
elsif shortonmarket then
pp=((orderprice/close)-1)*100
elsif not onmarket then
pp=0
endif
endif
pp=pp // to use variable
//graphonprice orderprice
//graph spread
// trailing atr stop
//———————————————-
if trailingstoptype=1 then
once trailingstoplong = 2
once trailingstopshort = 2
once atrtrailingperiod = 14
once minstop = 10
atrtrail=averagetruerange[atrtrailingperiod]((close/10)*pipsize)/1000 //i.e. dow
//atrtrail=averagetruerange[atrtrailingperiod]((close/1)*pipsize) //i.e. forex
tgl = round(atrtrail*trailingstoplong)
tgs = round(atrtrail*trailingstopshort)
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) // original “close”
if maxprice-orderprice>=tgl*pointsize then
if maxprice-orderprice>=minstop then
newsl = maxprice-tgl*pointsize
else
newsl = maxprice – minstop*pointsize
endif
endif
endif
if shortonmarket then
minprice = min(minprice,close) // original “close”
if orderprice-minprice>=tgs*pointsize then
if orderprice-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
endif
// trailing stop atr
//———————————————-
if trailingstoptype=2 then
once steps=0.05 // set to 0 to ignore steps
once minatrdist=1
once atrtrailingperiod = 14 // atr parameter value
once minstop = 10 // minimum trailing stop distance
if barindex=tradeindex then
once trailingstoplong = 2 // trailing stop atr relative distance
once trailingstopshort = 2 // trailing stop atr relative 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 //i.e. dow
//atrtrail=averagetruerange[atrtrailingperiod]((close/1)*pipsize) //i.e. forex
//
tgl=round(atrtrail*trailingstoplong)
tgs=round(atrtrail*trailingstopshort)
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,high)
if maxprice-orderprice>=tgl*pointsize then
if maxprice-orderprice>=minstop then
newsl=maxprice-tgl*pointsize
else
newsl=maxprice-minstop*pointsize
endif
endif
endif
//
if shortonmarket then
minprice=min(minprice,low)
if orderprice-minprice>=tgs*pointsize then
if orderprice-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 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
endif
//
if onmarket then
once sl=0.5
once pt=0.5
if longonmarket then
slvalue=orderprice-(sl*(orderprice/100))
sell at slvalue stop
endif
if shortonmarket then
slvalue=orderprice+(sl*(orderprice/100))
exitshort at slvalue stop
endif
if longonmarket then
ptvalue=orderprice+(pt*(orderprice/100))
sell at ptvalue limit
endif
if shortonmarket then
ptvalue=orderprice-(pt*(orderprice/100))
exitshort at ptvalue limit
endif
endif
set stop %loss 1
//set target %profit 0.25
//graph longperf coloured(0,0,255,255) as “long performance”
//graph shortperf coloured(255,0,0,255) as “short performance”
//graphonprice renkomax + boxsize coloured(0,200,0) as “renkomax”
//graphonprice renkomin – boxsize coloured(200,0,0) as “renkomin”
//graphonprice newsl coloured(0,0,255,255) as “trailingstop atr”
//graphonprice avg coloured(0,0,255,255) as “average renko”
Sorry first time posting code here.. I clicked the insert prt function but it appears to have been entered incorrectly.
I tidied it up. Sometimes that happens.
I added hourly optimised renko boxsizes. Good idea?
// boxsize settings
IF (CurrentHour = 08) THEN
boxsize = 11.5
ENDIF
IF (CurrentHour = 09) THEN
boxsize = 21.4
ENDIF
IF (CurrentHour = 10) THEN
boxsize = 25
ENDIF
IF (CurrentHour = 11) THEN
boxsize = 33.7
ENDIF
IF (CurrentHour = 12) THEN
boxsize = 12.5
ENDIF
IF (CurrentHour = 13) THEN
boxsize = 11.6
ENDIF
IF (CurrentHour = 14) THEN
boxsize = 2.8
ENDIF
IF (CurrentHour = 15) THEN
boxsize = 24.7
ENDIF
IF (CurrentHour = 16) THEN
boxsize = 27.8
ENDIF
IF (CurrentHour = 17) THEN
boxsize = 14.5
ENDIF
IF (CurrentHour = 18) THEN
boxsize = 25.8
ENDIF
IF (CurrentHour = 19) THEN
boxsize = 6.5
ENDIF
IF (CurrentHour = 20) THEN
boxsize = 12.5
ENDIF
IF (CurrentHour = 21) THEN
boxsize = 28.9
ENDIF
hourly optimised renko boxsizes. Good idea?
Only time will tell? 🙂
We need to Forward Test 2 Systems side by side … one with hourly box opti and one without … I’ve done just that! 🙂
Is box size that critical that we need the value after the decimal point? (curve fitting to the extreme?? 🙂 Also be easier and quicker for opti without decimal values?
@GraHal
Yes indeed! It’s probably over optimised. I wonder also if it’s better to optimise only from yesterdays price action or if it’s good to take a 4 day period. Whilst the maket is so volatile it might be better to optimise against a shorter period? What’s your thougths on this?
I reckon best to use maximum data available (4 days) but to optimise every day at 14:00 ish UK time (before DJI open) .
Then optimised values will be up with latest price action, but also will take into account the last 4 days price action
@eckaw interesting, curious how it performs today!
My focus is on less parameters.
I.e. below
Still it gave me parameters long and/or short and period. That period I use range*10 now.
Maybe it doesn’t make sense, but it can work for the dax too.
if barindex>1 and range>0 then
spread = max(abs(open - close), 0.000000001)
coeff=spread/highest[range*10](spread)*100
trendup = coeff<cf
trenddown= coeff<cf
endif
One thing for sure. No point optimising with 1.6/2.4 spread. If it’s gonna be profitable, it has to be at 6!
during the test with renko / TF 1s, i saw difference between backtest and demo this afternoon
do you have an idea about the huge difference in the numbers of late candles regarding the last exit ? orange cross/backtest , red cross/demo IG
thanks
Yes, probably the entryprice is worse in the live demo that you had in the backtest. Did you have it with spread 6?
@ Paul
thanks
yes, probably the entryprice. For spread it was set to 6
2nd cause could be the trailing stop, if using the fast one. While it works good overall, sometimes it behaves inconsistent, regardless of entryprice.
here’s an inconsistency today.
short at the same time, backtest sells lower and gets out on trailing stop with small profit.
live demo short sells higher=better and no trailingstop is activated and results in a small loss.
Especially because the entryprice is better in the live demo makes it hard to understand why no ts is activated.
edit; Switched trailing-stops. Same results hopefully better consistency.
I’m having very bad results on every version of the strategy. What about you guys?
Discussion re Pure Renko strategy
This topic contains 345 replies,
has 24 voices, and was last updated by bertrandpinoy
5 years, 7 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 02/25/2020 |
| Status: | Active |
| Attachments: | 149 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.