Problem with setting a break even level

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #192872 quote
    pdrh
    Participant
    Average

     

    IF (c1 AND a2 ) AND ST<2 AND Not ShortOnMarket AND Not Daysforbidden And timeEnterBefore AND timeEnterAfter THEN
    SELLSHORT 2 Perpoint AT c2 limit
    ST=ST+1
    ENDIF
    // Conditions to exit short positions
    IF SHORTONMARKET AND close < tradeprice - 6 THEN // if the price moves 5pts in my favour...
    if countofshortshares = 2 then
    Exitshort 1 PERPOINT at market  //close half of the trade
    //SoldHalf = 1
    breakevenlevel = tradeprice //...calculate the level for a stop 5pts below the trade open price...
    endif
    If COUNTOFSHORTSHARES=1 then
    Exitshort 1 PERPOINT at breakevenlevel limit
    endif
    Endif
    
    // Stops and targets
    SET STOP ploss 8
    SET TARGET pPROFIT 14
    graph tradeprice
    graph breakevenlevel
    

     

    I have an algo that closes half my position and sets a breakeven level .

    My problem is that the instruction to exit at the break even level is ignored and exit happens at the stop level

    Fractal-MK1-V2-Sell-Half.itf
    #192876 quote
    pdrh
    Participant
    Average
    #192878 quote
    robertogozzi
    Moderator
    Master

    It’s due to narrow SL and TP, try changing both to, say, 40 or 50 andit’ll work.

    pdrh thanked this post
    #192879 quote
    pdrh
    Participant
    Average

    That did not work sadly.Still ignoring the breakeven .

    #192883 quote
    robertogozzi
    Moderator
    Master

    Yes, there were a couple of additional issues:

    • use STOP instead of LIMIT to exit, as you are placing a pending order to exit at WORSE price
    • use a variable (I named it FLAG)  to signal that an exit at breakeven has been triggered, as it must be placed each new bar until hit (or TP is hit, of course); the exit order must be outside the conditional IF…ENDIF block.

    I tested this code on Dax, 4h TF:

    IF close crosses under average[100] and not onmarket THEN
       SELLSHORT 2 Perpoint AT market
       flag = 0
    ENDIF
    // Conditions to exit short positions
    IF SHORTONMARKET AND close < tradeprice - 6 THEN // if the price moves 5pts in my favour…
       if countofshortshares = 2 then
          Exitshort 1 PERPOINT at market //close half of the trade
          //SoldHalf = 1
          breakevenlevel = tradeprice //…calculate the level for a stop 5pts below the trade open price…
       endif
       If COUNTOFSHORTSHARES=1 then
          flag = 1
       endif
    Endif
    IF flag = 1 then
       Exitshort 1 PERPOINT at breakevenlevel stop
    endif
    // Stops and targets
    SET STOP ploss 500  //8
    SET TARGET pPROFIT 500  //14
    //
    graphonprice tradeprice(1)
    graphonprice breakevenlevel coloured(255,0,0,255)
    graph close < (tradeprice - 6)
    pdrh thanked this post
    #192885 quote
    pdrh
    Participant
    Average
    #192913 quote
    Nicolas
    Keymaster
    Master

    Keep in mind that you can now use the SET STOP BREAKEVEN instruction which is the best way to ask the broker your stoploss at breakeven

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

Problem with setting a break even level


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
pdrh @pdrh Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Nicolas
3 years, 9 months ago.

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