Need support on this code with breakeven level

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #69040 quote
    rama
    Participant
    Senior

    Set stop loss 25

    set target profit 200
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF

    // — BUY SIDE —
    //test if the price have moved favourably of “startBreakeven” points already
    IF longonmarket AND close-tradeprice>=12*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice+2*pipsize
    ENDIF

    IF longonmarket AND close-tradeprice>=20*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice+10*pipsize
    ENDIF

     

    ******************************************************

    The above code is working exactly the way I wanted the problem when I am in profit >= stop loss moves to 10

    when the floating profit falls <=20 then stop loss moves to 2. I want to keep the stop loss at 10 once my floating profit was 20 then fallen below 20

    #69062 quote
    JC_Bywan
    Moderator
    Master

    Please avoid double posts, thanks, the other copy of this post inserted in another thread has been deleted to keep the potential answers from other users in only one thread (this one) and not split across separate multiple threads. Thanks for your understanding.

    #69066 quote
    robertogozzi
    Moderator
    Master

    To write code, please use the <> “insert PRT code” button, to make code easier to read.

    You should post the whole strategy to test it and try to spot any issue.

    At first glance I warn you that

    Set stop loss 25

    will never be executed (at least on forex pairs), you should either write:

    Set stop loss 0.0025  //in Forex pairs, not Dax or oher indeces, it must be a difference in price
    //    or
    Set stop Ploss 25     //this is 25 pips
    #69088 quote
    raphaelopilski
    Participant
    Senior
    // --- BUY SIDE ---
    //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
    // --- end of BUY SIDE ---
    #69090 quote
    raphaelopilski
    Participant
    Senior

    sorry, mistake. I meant this one:

    startBreakeven = 5 //how much pips/points in gain to activate the breakeven function?
    PointsToKeep = 3 //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
    
    // --- BUY SIDE ---
    //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
    // --- end of BUY SIDE ---
    
    #69109 quote
    rama
    Participant
    Senior

    This code works only one stop loss

    not for variable stop loss

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

Need support on this code with breakeven level


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
rama @rama Participant
Summary

This topic contains 5 replies,
has 4 voices, and was last updated by rama
7 years, 10 months ago.

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