need help with MFE trailing stop

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #53481 quote
    jebus89jebus89
    Participant
    Master
    https://www.prorealcode.com/blog/learning/trailing-stop-max-favorable-excursion-mfe/   Hi, is it possible for someone to help me to code the following: I want the MFE trailing stop to be activated after X amounts of pips in profit. So i want it to be activated if i reach say 50 pips.   Big thanks 🙂
    #53493 quote
    AutoStrategistAutoStrategist
    Participant
    Veteran

    You will need to add the lines I have highlighted in bold to be able to set the value at which your trailing stop begins. You can create separate ones for long and short if you wanted that.

    //trailing stop
    trailingstop = 20
    StartTrailingStopValue = <Set this value>
    
    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE = 0
    MINPRICE = close
    priceexit = 0
    endif
    
    //case SHORT order
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
    if tradeprice(1)-close > StartTrailingStopValue*pointsize then
    if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
    endif
    endif
    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
    

     

    manel and Nicolas thanked this post
    #53494 quote
    AutoStrategistAutoStrategist
    Participant
    Veteran

    It didn’t bold it but it is the lines that are tagged with ‘strong’

    #53516 quote
    jebus89jebus89
    Participant
    Master
    Awsome seems to be working fine 🙂 Big thanks
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

need help with MFE trailing stop


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jebus89 @jebus89 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by jebus89jebus89
8 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/21/2017
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...