Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trailing Stop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Trailing Stop

    I ahve tried to write my own trailing stop in the strategy but has encountered some problems

    I wish to turn on the trailling stop once the order PnL is more than trailingStop,

    my code is as follow

    (within the OnOrderUpdate)

    if((GetCurrentBid()-OrderOne.AvgFillPrice)>trailingStop &&
    (GetCurrentBid()-OrderOne.AvgFillPrice)>LockedUpProfit)
    {
    LockedUpProfit=GetCurrentBid()-OrderOne.AvgFillPrice;
    }
    else
    {
    if(GetCurrentBid()-LongOrder.AvgFillPrice<LockedUpProfit)
    {
    LockedUpProfit=0;
    ExitLong("###Trailing###","LongOrderOne");
    }
    }

    it turns out that the trailing stop is not working as expected

    what will be the right place for me to define the LockedUpProfit variable??
    (etc. in OnBarUpdate, Initialize)

    and what's wrong with the coding??

    I would be really appreciate for your reply and thank you very much for reading.

    #2
    I would suggest you calculate the needed variable in the OnBarUpdate() to have it updated the calculated values as new bars and PnL info comes in...for a basic start into modifying a stop loss order to become a trailing one, please see our reference sample on this and then proceed from there -

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    656 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    371 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    579 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X