Renko automatic trading

Viewing 7 posts - 61 through 67 (of 67 total)
  • Author
    Posts
  • #155813 quote
    ActuallyNM
    Participant
    Average

    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.

    #155826 quote
    GraHal
    Participant
    Master

    What is broker minimum stop loss  for the instrument you are trading?

    Try 15 or 20 pips?

    #155878 quote
    ActuallyNM
    Participant
    Average

    Thanks 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.

    GraHal thanked this post
    book-order.png book-order.png
    #155891 quote
    Paul
    Participant
    Master

    a 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.

    defparam cumulateorders = false
    defparam preloadbars = 2000
    defparam flatbefore = 090000
    defparam flatafter  = 215500
    
    timeframe (default)
    
    //backtesting; slow timeframe chart = slow timeframe in code
    //live       ; fast timeframe chart , slow timeframe in code
    
    once mode      = 1 // [1]backtesting [2]live
    once tradetype = 2 // [1]long/short  [2]long [3]short
    
    once positionsize = 1
    
    once boxsize=30
    
    timeframe (5 minutes,updateonclose)
    
    if openhour=9 then
    renkomax = round(close[12] / boxsize) * boxsize
    renkomin = renkomax - boxsize
    endif
    
    if high > renkomax + boxsize then
    while high > renkomax + boxsize
    renkomax = renkomax + boxsize
    renkomin = renkomin + boxsize
    wend
     
    elsif low < renkomin - boxsize then
    while low < renkomin - boxsize
    renkomax = renkomax - boxsize
    renkomin = renkomin - boxsize
    wend
    endif
    
    // other conditions
    condbuy = 1
    condsell= 1
    
    timeframe (default)
    
    // entry conditions
    if mode=1 then // backtesting on slow timeframe
    if (tradetype=1 or tradetype=2) and condbuy then
    buy positionsize contract at renkoMax + boxSize stop
    endif
    if (tradetype=1 or tradetype=3) and condsell then
    sellshort positionsize contract at renkoMin - boxSize stop
    endif
    elsif mode=2 then // live on fast timeframe
    if (tradetype=1 or tradetype=2) and condbuy then
    if high > renkoMax + boxSize then
    buy positionsize contract at market
    endif
    endif
    if (tradetype=1 or tradetype=3) and condsell then
    if low < renkoMin - boxSize then
    sellshort positionsize contract at market
    endif
    endif
    endif
    
    timeframe (5 minutes,updateonclose)
    
    once trailingstop=1
    if trailingstop then
    //
    once ts2sensitivity= 1
    //
    if ts2sensitivity=1 then
    ts2sensitivitylong=close
    ts2sensitivityshort=close
    elsif ts2sensitivity=2 then
    ts2sensitivitylong=high
    ts2sensitivityshort=low
    endif
    //
    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    trailstart2   = 0.1 //%      start trailing profits from this point
    basepercent   = 0.2 //20.0%  profit percentage to keep when setting berakeven
    stepsize      = 2   //10     pip chunks to increase percentage
    percentinc    = 0.2 //10.0%  percent increment after each stepsize chunk
    barnumber     = 10  //10     add further % so trades don't keep running too long
    barpercent    = 0.2 //10%    add this additional percentage every barnumber bars
    roundto       = 0   //-0.5   rounds lower, +0.4 higher, 0 defaults prt behaviour
    pricedistance = 10 * pipsize // minimun distance from current price
    y1            = 0           //reset to 0
    y2            = 0           //reset to 0
    profitpercent = basepercent //reset to desired default value
    tradebar      = barindex
    trailstart    = ((close/100)*trailstart2) / pipsize
    elsif longonmarket and ts2sensitivitylong > (tradeprice(1) + (y1 * pipsize)) then
    x1 = (ts2sensitivitylong - tradeprice(1)) / pipsize
    if x1 >= trailstart then
    diff1         = abs(trailstart - x1)
    chunks1       = max(0,round((diff1 / stepsize) + roundto))
    profitpercent = basepercent + (basepercent * (chunks1 * percentinc))
    barcount      = barindex - tradebar
    if barcount mod barnumber = 0 then
    profitpercent = profitpercent + barpercent
    endif
    profitpercent = max(profitpercent[1],min(100,profitpercent))
    y1 = max(x1 * profitpercent, y1)
    endif
    elsif shortonmarket and ts2sensitivityshort < (tradeprice(1) - (y2 * pipsize)) then
    x2 = (tradeprice(1) - ts2sensitivityshort) / pipsize
    if x2 >= trailstart then
    diff2         = abs(trailstart - x2)
    chunks2       = max(0,round((diff2 / stepsize) + roundto))
    profitpercent = basepercent + (basepercent * (chunks2 * percentinc))
    barcount      = barindex - tradebar
    if barcount mod barnumber = 0 then
    profitpercent = profitpercent + barpercent
    endif
    profitpercent = max(profitpercent[1],min(100,profitpercent))
    y2 = max(x2 * profitpercent, y2)
    endif
    endif
    endif
    
    timeframe (default)
    
    if trailingstop then
    if y1 then
    sellprice = tradeprice(1) + (y1 * pipsize)
    if abs(ts2sensitivitylong - sellprice) > pricedistance then
    if ts2sensitivitylong >= sellprice then
    sell at sellprice stop
    else
    sell at sellprice limit
    endif
    else
    sell at market
    endif
    endif
    if y2 then
    exitprice = tradeprice(1) - (y2 * pipsize)
    if abs(ts2sensitivityshort - exitprice) > pricedistance then
    if ts2sensitivityshort <= exitprice then
    exitshort at exitprice stop
    else
    exitshort at exitprice limit
    endif
    else
    exitshort at market
    endif
    endif
    endif
    
    set stop %loss 0.2
    set target %profit 0.4
    
    graphonprice renkoMax + boxSize
    graphonprice renkomin - boxsize
    
    eckaw thanked this post
    #156039 quote
    eckaw
    Participant
    Veteran

    Hi @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?

    #156074 quote
    Paul
    Participant
    Master

    How 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.

    eckaw thanked this post
    #156747 quote
    孫榗溢
    Participant
    Junior

    @eckaw, sir I want to know how to set up for the SL point, cause this code run with IG, call out trategy failed related with the SL setup , IG min. SL is set as 10 point

Viewing 7 posts - 61 through 67 (of 67 total)
  • You must be logged in to reply to this topic.

Renko automatic trading


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
eckaw @eckaw Participant
Summary

This topic contains 66 replies,
has 17 voices, and was last updated by 孫榗溢
5 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/29/2020
Status: Active
Attachments: 25 files
Logo Logo
Loading...