moving profit target automatically as moving stop loss to Break Even

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #104410 quote
    traderrs
    Participant
    New

    Hello everyone ! I use the following code for break-even trades. This works perfectly (for example: when I have 5 pips profit on the EUR/USD my stop loss change from -10 pips change to +1 pip so I can’t lose anymore on this position:

    startBreakeven = 5 //how much pips/points in gain to activate the breakeven function?
    PointsToKeep = 1 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
    
    //reset the breakevenLevel when no trade are on market
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    
    //test if the price have moved favourably of "startBreakeven" points already
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)-PointsToKeep*pipsize
    ENDIF
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    EXITSHORT AT breakevenLevel STOP
    ENDIF
    

    I searched this forum but can’t find anything about it. Does anyone know if it is possible to do something similar with a profit target ? For example my system opens a trade as follows:

    Stop loss: 10 pips
    Profit target: 10 pips

    If I lose 5 pips (-5) in an open losing position then I want to move my profit target automatically from +10 pips to -1 pips. From here there are 2 scenarios:

    Losing 1 pip (profit target)
    Losing 10 pips (stop loss)

    Thank you.

    #104413 quote
    robertogozzi
    Moderator
    Master

    I never heard about this technique.

    You can use the same code reversing conditions, look for losses and as soon as you reach -startbreakeven you set breakeven to Tradeprice – PointsToKeep.

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

moving profit target automatically as moving stop loss to Break Even


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
traderrs @traderrs Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
6 years, 6 months ago.

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