Trailing SL and SL and TP?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #97652 quote
    bullbear
    Participant
    Senior

    Is this code ok as a trailing SL.

    Can i have a solid SL and TP at the same time as i have trailing SL?

    trailingstop = 34
    
    //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)-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
    
    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    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
    
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
    
    SET STOP ploss 50
    SET TARGET pPROFIT 50
    #97653 quote
    robertogozzi
    Moderator
    Master

    You can!

    #97654 quote
    bullbear
    Participant
    Senior

    Thanks 🙂

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

Trailing SL and SL and TP?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
bullbear @bullbear Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by bullbear
6 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/04/2019
Status: Active
Attachments: No files
Logo Logo
Loading...