break even stop loss for multiple position s

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #87599 quote
    rama
    Participant
    Senior
    //-------------------------------------------------------------------------
    // Main code : MySystem(159)
    //-------------------------------------------------------------------------
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    x=3
    if not onmarket and time>=080000 and time<=210000  then
    // Conditions to enter long positions
    indicator1 = Average[7](high)
    c1 = (close >= indicator1)
    
    IF c1 THEN
    BUY 1 PERPOINT AT lowest[3](low)+2 limit
    ENDIF
    
    // Conditions to enter short positions
    indicator2 = Average[7](high)
    c2 = (close <= indicator2)
    
    IF c2 THEN
    SELLSHORT 1 PERPOINT AT highest[3](high)-x limit
    ENDIF
    endif
    if longonmarket then
    // Conditions to enter long positions
    indicator1 = Average[7](high)
    c1 = (close >= indicator1)
    
    IF c1 THEN
    BUY 1 PERPOINT AT lowest[3](low)+2 limit
    ENDIF
    
    endif
    if shortonmarket then
    
    // Conditions to enter short positions
    indicator2 = Average[7](high)
    c2 = (close <= indicator2)
    
    IF c2 THEN
    SELLSHORT 1 PERPOINT AT highest[3](high)-x limit
    ENDIF
    endif
    
    startBreakeven = 10//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)
    
    
    set stop loss 10
    
    set target profit 500
    
    
    
    //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
    // --- end of BUY SIDE ---
    
    
    // --- BUY SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    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 ---
    

    I want to use the above for n amount/pt

    will this work? if not what changed I need to make

    the idea when not market conditions c1 met open long and if the market moves in my favor, move the stop loss to break even

    add one more position move the stop loss to break keep adding till amount/pt “n” is reached

    #87899 quote
    Nicolas
    Keymaster
    Master

    Sorry, but I don’t understand your query. Do you need the breakeven calculation made with money?

    Add another order when the first one is at breakeven?

    #87905 quote
    rama
    Participant
    Senior

    Break even works for only one open position

    If I run the program with 1 amount/point this will work fine

    I I run the program for >= break even wont move ( once in profit I am trying to move to break even )

    #87952 quote
    Nicolas
    Keymaster
    Master

    You mean that if you “BUY 2 PERPOINT” instead of 1, the breakeven is not working? (while it does with 1 PERPOINT)

    #87956 quote
    rama
    Participant
    Senior

    let me explain in details

    say buy 1 perpoint at close+x stop

    if position is moved in my favour , the code moves to break even( based on points to keep)

    upto this point it works fine

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

    If I add one more position the this also need to be moved to break even if the profit is my favor based on the number of points to keep

    #87989 quote
    Nicolas
    Keymaster
    Master

    Ok, but that’s not possible to set individual stoploss this way. Once a pending order is triggered it closes all the orders at the same time.

    It could be managed with partial closure, but it is still not possible with a real account, but only in backtesting.

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

break even stop loss for multiple position s


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
rama @rama Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Nicolas
7 years, 1 month ago.

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