Renko automatic trading
Forums › ProRealTime English forum › ProOrder support › Renko automatic trading
- This topic has 66 replies, 17 voices, and was last updated 4 years ago by 孫榗溢.
-
-
12/31/2020 at 5:38 PM #155813
Hello,
Still working on this code. Algorithm still stop with “The stop is too short because of the broker.”
I have tested many trailing stops : 2,3,4 pips , error is still here.
Any idea?
Thanks to all,
i using 17.1 renko box size.
12/31/2020 at 10:42 PM #15582601/01/2021 at 6:56 PM #155878Thanks for your answer @GraHal
10 pips minimum for my broker, but i have already configured 20 pips stop.
I think maybe i have understand why my strategy stopped many times.
This system apply conditionnal orders to trade : sell stop and buy stop.
Sometimes, when the strategy tried to open position, the market is at this time at the same price as you can see in my book order.
i say that because most of the the time the others orders worked, indeed they not are at the same price at this time for the stop order.
1 user thanked author for this post.
01/02/2021 at 3:14 AM #155891a possible fix.
backtest with mode=1 and slow timeframe
if have good settings, set to mode 2 and on fast timeframe like 1s.
code below not intend to have good results, but as layout. Needs additional criteria. Chart set to 5 min.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156defparam cumulateorders = falsedefparam preloadbars = 2000defparam flatbefore = 090000defparam flatafter = 215500timeframe (default)//backtesting; slow timeframe chart = slow timeframe in code//live ; fast timeframe chart , slow timeframe in codeonce mode = 1 // [1]backtesting [2]liveonce tradetype = 2 // [1]long/short [2]long [3]shortonce positionsize = 1once boxsize=30timeframe (5 minutes,updateonclose)if openhour=9 thenrenkomax = round(close[12] / boxsize) * boxsizerenkomin = renkomax - boxsizeendifif high > renkomax + boxsize thenwhile high > renkomax + boxsizerenkomax = renkomax + boxsizerenkomin = renkomin + boxsizewendelsif low < renkomin - boxsize thenwhile low < renkomin - boxsizerenkomax = renkomax - boxsizerenkomin = renkomin - boxsizewendendif// other conditionscondbuy = 1condsell= 1timeframe (default)// entry conditionsif mode=1 then // backtesting on slow timeframeif (tradetype=1 or tradetype=2) and condbuy thenbuy positionsize contract at renkoMax + boxSize stopendifif (tradetype=1 or tradetype=3) and condsell thensellshort positionsize contract at renkoMin - boxSize stopendifelsif mode=2 then // live on fast timeframeif (tradetype=1 or tradetype=2) and condbuy thenif high > renkoMax + boxSize thenbuy positionsize contract at marketendifendifif (tradetype=1 or tradetype=3) and condsell thenif low < renkoMin - boxSize thensellshort positionsize contract at marketendifendifendiftimeframe (5 minutes,updateonclose)once trailingstop=1if trailingstop then//once ts2sensitivity= 1//if ts2sensitivity=1 thents2sensitivitylong=closets2sensitivityshort=closeelsif ts2sensitivity=2 thents2sensitivitylong=hights2sensitivityshort=lowendif//if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) thentrailstart2 = 0.1 //% start trailing profits from this pointbasepercent = 0.2 //20.0% profit percentage to keep when setting berakevenstepsize = 2 //10 pip chunks to increase percentagepercentinc = 0.2 //10.0% percent increment after each stepsize chunkbarnumber = 10 //10 add further % so trades don't keep running too longbarpercent = 0.2 //10% add this additional percentage every barnumber barsroundto = 0 //-0.5 rounds lower, +0.4 higher, 0 defaults prt behaviourpricedistance = 10 * pipsize // minimun distance from current pricey1 = 0 //reset to 0y2 = 0 //reset to 0profitpercent = basepercent //reset to desired default valuetradebar = barindextrailstart = ((close/100)*trailstart2) / pipsizeelsif longonmarket and ts2sensitivitylong > (tradeprice(1) + (y1 * pipsize)) thenx1 = (ts2sensitivitylong - tradeprice(1)) / pipsizeif x1 >= trailstart thendiff1 = abs(trailstart - x1)chunks1 = max(0,round((diff1 / stepsize) + roundto))profitpercent = basepercent + (basepercent * (chunks1 * percentinc))barcount = barindex - tradebarif barcount mod barnumber = 0 thenprofitpercent = profitpercent + barpercentendifprofitpercent = max(profitpercent[1],min(100,profitpercent))y1 = max(x1 * profitpercent, y1)endifelsif shortonmarket and ts2sensitivityshort < (tradeprice(1) - (y2 * pipsize)) thenx2 = (tradeprice(1) - ts2sensitivityshort) / pipsizeif x2 >= trailstart thendiff2 = abs(trailstart - x2)chunks2 = max(0,round((diff2 / stepsize) + roundto))profitpercent = basepercent + (basepercent * (chunks2 * percentinc))barcount = barindex - tradebarif barcount mod barnumber = 0 thenprofitpercent = profitpercent + barpercentendifprofitpercent = max(profitpercent[1],min(100,profitpercent))y2 = max(x2 * profitpercent, y2)endifendifendiftimeframe (default)if trailingstop thenif y1 thensellprice = tradeprice(1) + (y1 * pipsize)if abs(ts2sensitivitylong - sellprice) > pricedistance thenif ts2sensitivitylong >= sellprice thensell at sellprice stopelsesell at sellprice limitendifelsesell at marketendifendifif y2 thenexitprice = tradeprice(1) - (y2 * pipsize)if abs(ts2sensitivityshort - exitprice) > pricedistance thenif ts2sensitivityshort <= exitprice thenexitshort at exitprice stopelseexitshort at exitprice limitendifelseexitshort at marketendifendifendifset stop %loss 0.2set target %profit 0.4graphonprice renkoMax + boxSizegraphonprice renkomin - boxsize1 user thanked author for this post.
01/03/2021 at 3:42 AM #156039Hi @Paul
Thanks for posting your renko template. I’m interested in your approach to backtest in a larger timeframe and then run it in a shorter timeframe. I like the idea of using stop orders for backtest and buy at market for trading on short term trading. However I don’t understand how the trailing stop works in backtest vs real trading on shorter timeframes. Surely the trailing stop works differently on 5 minute timeframe vs 1 second timeframe? How can the 5min backtest be relevant in terms of the trailing stop when changing to 1 / 5 or 10 second timeframe?
01/03/2021 at 1:00 PM #156074How can the 5min backtest be relevant in terms of the trailing stop when changing to 1 / 5 or 10 second timeframe
The difference comes because the 5 minute bars are read at the closing of that bar, then the “candle data” is known.
Calculation of the exit lines should be the same as on a 1s timeframe live as to 5m timeframe backtest. That’s why the first part of the trailingstop has the slow timeframe and uses updateonclose.
The 1/5/10 second timeframe is much more responsive and a quick exit is more guaranteed.
So the second part is on a fast timeframe, because as soon as it hits the exit level, you want to get out. Even if it’s rejected because of the stop&limit order and the minimum order distance, it exits next (i.e. second) bar at market and the result will be about the same as the backtest which exits on stop/limit.
1 user thanked author for this post.
01/07/2021 at 1:53 PM #156747 -
AuthorPosts
Find exclusive trading pro-tools on