Add more than one level to the Breakeven code

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #192449 quote
    normbeef
    Participant
    New

    Hi everyone..  hope I formatted this correctly ?

    I use the breakeven code a lot in my systems,  however I find myself requiring an additonal levels in one of my systems as the breakeven level Vs the Profit level are very wide..

    As below..  the points difference is 850 ..   to optimise the system further I would like to be able to add another breakeven (or stop move) when the profit gets to 600 points (i.e. after the first breakeven has executed at startbreakeven =150)..   many trades reach 600+ points but end up reverting to the 50 point stop..  which is costly..

    I dont want to use a stepped trailing stop as its not flexible enough.

    // Stops and targets
    SET STOP pLOSS 160
    SET TARGET pPROFIT 1000
    
    startBreakeven = 150 //how many point gain to activate the breakeven function
    PointsToKeep = 50 //how many points profit above or below the entry price when the breakeven is activated
    
    //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*pointsize THEN
    //calculate the breakevenLevel
    breakevenLevel = TRADEPRICE(1)+PointsToKeep*pointsize
    ENDIF
    
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    #192450 quote
    robertogozzi
    Moderator
    Master

    Replace lines 13-22 with these ones (not tested):

    //test if the price have moved favourably of "startBreakeven" points already
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pointsize AND breakevenLevel=0 THEN
    //calculate the breakevenLevel
    breakevenLevel = TRADEPRICE(1)+PointsToKeep*pointsize
    ENDIF
    IF LONGONMARKET AND close-tradeprice(1)>=600*pointsize THEN
    //calculate the breakevenLevel
    breakevenLevel = TRADEPRICE(1)+(PointsToKeep+300)*pointsize
    ENDIF
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF

    it will lock an additional 300 pips after a 600-pip temp gain.

    normbeef thanked this post
    #192451 quote
    JS
    Participant
    Veteran

    Maybe you can use the Standard Deviation:

    BreakEvenLevel = TradePrice(1) + Std[n](Close) or BreakEvenLevel = TradePrice(1) + 2 * Std[n](Close)

    When the price is going down the Standard Deviation (BreakEvenLevel) will rise…

    normbeef thanked this post
    #192464 quote
    normbeef
    Participant
    New

    Ciao Roberto,

    It Works really well on backtest.. thankyou so much..

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

Add more than one level to the Breakeven code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
normbeef @normbeef Participant
Summary

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

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