How to put breakeven stop in after makes move 3-5 bars

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #10372 quote
    James B Eddon
    Participant
    New

    Can anyone help with code for: put breakeven stop in, after makes move 3-5 bars

    #261453 quote
    Nicolas
    Keymaster
    Legend
    // ============================================================
    // BREAKEVEN STOP — triggers if price moves X points within bars 3–5
    // ============================================================
    
    
    // ---- PARAMETERS (adjust to your instrument) ----
    BreakevenPoints = 20   // Points/pips needed to trigger breakeven
    MinBars = 3            // Earliest bar to check (from entry)
    MaxBars = 5            // Latest bar to check (from entry)
    
    
    // ---- TRACK BARS IN TRADE ----
    IF NOT ONMARKET THEN
      barsInTrade = 0
      beTriggered = 0
      entryPrice  = 0
    ELSIF barsInTrade = 0 THEN
      entryPrice  = TRADEPRICE(1)
      barsInTrade = 1
    ELSE
      barsInTrade = barsInTrade + 1
    ENDIF
    
    
    // ---- CHECK FOR THE MOVE (within bars 3–5) ----
    IF LONGONMARKET AND beTriggered = 0 THEN
      IF barsInTrade >= MinBars AND barsInTrade <= MaxBars THEN
        IF HIGH >= entryPrice + BreakevenPoints THEN
          beTriggered = 1
        ENDIF
      ENDIF
    ELSIF SHORTONMARKET AND beTriggered = 0 THEN
      IF barsInTrade >= MinBars AND barsInTrade <= MaxBars THEN
        IF LOW <= entryPrice - BreakevenPoints THEN
          beTriggered = 1
        ENDIF
      ENDIF
    ENDIF
    
    
    // ---- PLACE THE BREAKEVEN STOP ORDER ----
    IF beTriggered = 1 AND ONMARKET THEN
      SET STOP BREAKEVEN
    ENDIF
    

    How it works:

    • BreakevenPoints – How many points price must move before breakeven triggers. Set this to match your instrument (e.g. 20 points on DAX, 10 pips on forex).
    • MinBars / MaxBars – The window in which the move is checked. Set to 3 and 5, so the code only looks for the move between bar 3 and bar 5 after entry.
    • barsInTrade – A counter that tracks how many bars have passed since the trade was opened. Resets to 0 when not in a trade.
    • beTriggered – A latch variable. Once the conditions are met it flips to 1 and stays there for the rest of the trade, keeping the breakeven stop active.
    • entryPrice – Captured from TRADEPRICE(1) on the first bar the trade is open. This is the level the stop gets moved to.


    Key behaviours:

    Works automatically for both long and short trades. For longs it checks the HIGH of each bar; for shorts it checks the LOW.

    If the required move does not happen within bars 3 to 5, beTriggered stays 0 and no breakeven stop is placed. Your original stop remains in control.

    Once beTriggered equals 1, the breakeven stop order is placed every bar until the trade closes, so it cannot be accidentally dropped.

    To use this code, paste the block after your entry logic inside your existing ProRealCode trading system. Adjust BreakevenPoints to suit your instrument and timeframe.

    robertogozzi thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

How to put breakeven stop in after makes move 3-5 bars


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Nicolas
1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/10/2016
Status: Active
Attachments: No files
Logo Logo
Loading...