Need help coding new trailing stop loss

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #91163 quote
    jebus89
    Participant
    Master

    So im using this alot:

    //************************************************************************
    // MFE trailing stop function
    //************************************************************************
    ///trailing stop
    trailingstop = 50
    StartTrailingStopValue = 10
     
    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE = 0
    priceexit = 0
    endif
     
     
     
    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if close-tradeprice(1) > StartTrailingStopValue*pointsize then
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    endif
     
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif

    And my question is: Could someone help me change this trailing stop to include:

    When trade is profitable and the trailing stop loss begins, i want the stop loss to move up (more tight) for every Bar that has passed where trade is not hitting new highs.

    Example: see pic.

     

    Edit: So lets say a trade is going your way, your 100 pips in profit, the MTF stop loss is now = 50 pips profit.

    Lets say that the trade is not hitting new highs, so for every Bar/candle that goes by without a new high, the stop loss keeps tightening up.

    The idea is that If tthe market continues to rally up, the stop loss will follow the price higher and higher, as is normal with the MTF trailing stop loss today. But if the market stops rallying up andf starts moving sideways the market MIGHT come crashing down. Lets say it goes sideways for 15 bars before crashing down. I would love my stop loss to not be 50, but maybe 70 by that time..

    Hope this is clear.

    #91171 quote
    robertogozzi
    Moderator
    Master

    Instead of using it as an increasing step, you could turn it into a downward step, that is instead of 10 being added to your TRADEPRICE, whay don’t you subtract it from HIGH (if it was a higher HIGH)?

    #91174 quote
    robertogozzi
    Moderator
    Master

    I attach a pic to make it clearer.

    #91177 quote
    jebus89
    Participant
    Master

    Im not sure that would do what i want?

    I would like the MTF trailing stop to work as it is today, just to add a feature thats saying

     

    “If there is no new higher close, then move trailing stop +n pips higher, but if the next candle has a higher close than close[1] then it should not move the stop loss, unless the new higher close is the highest close in the trade, then the normal MTF code would move the stop loss as it does today.”

    #91184 quote
    Vonasi
    Moderator
    Master

    This thread might be of interest to you.

    Self adjusting trailing stop based on market movements

    #91234 quote
    robertogozzi
    Moderator
    Master

    I tried this modified code, but I could not find any trade to fully test it:

    //************************************************************************
    // MFE trailing stop function
    //************************************************************************
    ///trailing stop
    trailingstop           = 20
    StartTrailingStopValue = 10
    KeepUpPace             = 5  //move SL these Pips only when no new higher has formed, but still price is higher than treshold and higher than previous SL
    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE  = 0
    priceexit = 0
    TempHigh  = 0
    endif
    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if close-tradeprice(1) > StartTrailingStopValue*pointsize then
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    TempHigh = high
    elsif close-tradeprice(1) > priceexit AND priceexit > 0 THEN
    IF high <= TempHigh AND close <= close[1] THEN
    priceexit = priceexit + (KeepUpPace * pointsize)
    endif
    endif
    endif
    endif
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
    //graph close
    //graph high
    //graph priceexit
    //graph TempHigh
    //graph close[1]
    jebus89 thanked this post
    #91328 quote
    jebus89
    Participant
    Master

    Nice, will test it and report back. Thanks

    #91403 quote
    Mkyr
    Participant
    New

    Hi guys,

    Anyone interested in a bit of freelance coding work? Need help with a simple tool to help me manage my stops.

    #91408 quote
    Vonasi
    Moderator
    Master

    Mkyr – you can either post your idea in this forum and someone might be able to assist you out of the kindness of their heart or alternatively you can use the programming services available here:

    Trading Programming Services

    I also notice that you have posted a very similar request in another topic. Please do not double post as it just leads to confusion and wasted effort for those trying to help you.

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

Need help coding new trailing stop loss


ProOrder support

New Reply
Author
author-avatar
jebus89 @jebus89 Participant
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by Vonasi
6 years, 11 months ago.

Topic Details
Forum: ProOrder support
Language: English
Started: 02/12/2019
Status: Active
Attachments: 2 files
Logo Logo
Loading...