Prevent a rolling channel exit from loosening

A conventional rolling low can fall when a new lower low enters its window. If the same channel is used as a close-based trailing exit, its reference may loosen during an open position. This MultiCharts design separates the raw ten-bar low from a ratcheted exit level that can only rise during a long trade.

Rules and example

Enter long at the next bar market after a completed close exceeds the highest high of the preceding 20 bars, while flat. On the first bar where the position is observed, initialize the exit level to the lowest low of the prior ten bars. Subsequently set the exit level to the greater of its previous value and the current raw channel. If raw levels are 96, 98, 97, 100, 99 and 101, the ratcheted values are 96, 98, 98, 100, 100 and 101. This sequence illustrates level construction, assuming no intervening exit. Submit a next-bar market exit when the completed close is at or below the ratchet.

Non-Decreasing Donchian Exit Levels in PowerLanguage

Hypothetical rolling channel values in blue and a non-decreasing decision level in green.

PowerLanguage strategy example

Inputs: EntryLen(20), ExitLen(10), StopCash(200);
Vars: RawExit(0), Ratchet(0);

SetStopContract;
SetStopLoss(StopCash);

If MarketPosition = 0 then begin
    Ratchet = 0;
    If Close > Highest(High[1], EntryLen) then
        Buy ("ChannelLE") next bar at market;
end
else if MarketPosition = 1 then begin
    RawExit = Lowest(Low[1], ExitLen);
    If MarketPosition[1] <> 1 then
        Ratchet = RawExit
    else
        Ratchet = MaxList(Ratchet, RawExit);
    If Close <= Ratchet then
        Sell ("RatchetLX") next bar at market;
end;

Use bar-close calculation without intrabar order generation, sufficient MaxBarsBack and one entry per position. SetStopContract applies the illustrative cash stop per contract or share; choose a suitable amount and quantity for the instrument. The channel exit is a close-based market decision, not a resting stop order. The separate built-in cash stop provides intrabar protection subject to execution assumptions. The ratchet resets when flat; strategies with reversals, scaling or multiple data series need more explicit position-transition logic.

Testing and execution limitations

Compare the ordinary rolling channel against the ratchet with identical entry rules, initial cash stops, commission and slippage. Test 5-, 10- and 20-bar exit windows, gaps below the decision level, and competing protective and market exits. Verify actual fills and broker order synchronization in simulation. A tighter exit may cut drawdown or end profitable trades too early. The code has not been compiled or backtested here, and protective orders do not guarantee their specified loss. Leveraged trading can cause substantial losses.

For custom strategy implementation and execution controls, see Custom MultiCharts strategy Development Services.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.