A reader of this blog wanted a conversion from my Ratchet Trailing Stop indicator into a Strategy. You will notice a very close similarity with the indicator code as the code for this strategy. This is a simple N-Bar [Hi/Lo] break out with inputs for the RatchetAmt and TrailAmt. Remember RatchetAmt is how far the market must move in your favor before the stop is pulldown the TrailAmt. So if the RatchetAmt is 12 and the TrailAmt is 6, the market would need to move 12 handles in your favor and the Trail Stop would move to break even. If it moves another 12 handles then the stop would be moved up/down by 6 handles. Let me know if you have any questions – this system is similar to the one I just posted.
Notice how the RED line Ratchets Up by the Fixed Amount [8/6]
If d <> d[1] then Begin longMult = 0; shortMult = 0; myBarCount = 0; mp = 0; lep = 0; sep = 0; buysToday = 0; shortsToday = 0; end;
myBarCount = myBarCount + 1;
If myBarCount = 6 then // six 5 min bars = 30 minutes Begin stb = highD(0); //get the high of the day sts = lowD(0); //get low of the day end;
If myBarCount >=6 and t < calcTime(sess1Endtime,-3*barInterval) then Begin if buysToday = 0 then buy("NBar-Range-B") next bar stb stop; if shortsToday = 0 then sellShort("NBar-Range-S") next bar sts stop; end;
mp = marketPosition; If mp = 1 then begin lep = entryPrice; buysToday = 1; end; If mp =-1 then begin sep = entryPrice; shortsToday = 1; end;
// Okay initially you want a X point stop and then pull the stop up // or down once price exceeds a multiple of Y points // longMult keeps track of the number of Y point multipes of profit // always key off of lep(LONG ENTRY POINT) // notice how I used + 1 to determine profit // and - 1 to determine stop level
If mp = 1 then Begin If h >= lep + (longMult + 1) * ratchetAmt then longMult = longMult + 1; Sell("LongTrail") next bar at (lep + (longMult - 1) * trailAmt) stop; end;
If mp = -1 then Begin If l <= sep - (shortMult + 1) * ratchetAmt then shortMult = shortMult + 1; buyToCover("ShortTrail") next bar (sep - (shortMult - 1) * trailAmt) stop; end;
setExitOnClose;
I Used my Ratchet Indicator for the Basis of this Strategy
Backtesting with [Trade Station,Python,AmiBroker, Excel]. Intended for informational and educational purposes only!