Fractional Trades + Breakeven Stop Loss

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #134614 quote
    tradetrader101
    Participant
    Junior

    Hi there’s two issues I’m having, once does the code I’m using below have a built even break even stop loss in it somewhere? For some reason it keeps closing trades they hit 0 and I’m really not sure why.

    An secondly whenever I’m trading 1 point + on anything the trailing stop, trailing step and take profit levels populate on IG as per my instructions but for some reason when I say buy 0.1 instead of buy 1.0 it never populates any trailing stop, trailing step and take profit levels. So basically it’s just an open trade which can obviously get really expensive on things like the lumber market.

    I set it to 0.1 and nothing came up on IG at the time it was moving hundreds of points in minutes where the lumber market is bigger. An I had no trailing stop no nothing but a live trade. An it’s happened on smaller markets like the French market yesterday, it didn’t give me any trailing stop, take profit etc. So I had to exit the trade at a loss as my stop and take profit is set by the ATR and I didn’t want to guess the ATR and work out values while live trading something moving fast. This also happened with the Australian market once even when I had a buy 1.0 order but it happens pretty much every time with 0.5 star orders and anything under 1.0.

    DEFPARAM CumulateOrders = True // Cumulating positions deactivated
    
    ATR = AverageTrueRange[168]
    
    //take profit
    SET TARGET pPROFIT TKPROFIT
    
    IF NOT ONMARKET AND (PositionPerf(1) + PositionPerf(2) +  PositionPerf(3) + PositionPerf(4)) <  -100 OR STRATEGYPROFIT < -100 THEN
    QUIT
    ENDIF
    
    //trailing stop function (make equal to absolute value when trailing stop and absolute value)
    IF CountOfPosition < 2 AND ONMARKET AND PositionPerf(1) > 0 THEN
    //trailing will start @trailinstart points profit
    TRSTART = (ATR*0.50)*40
    //trailing step to move the "stoploss"
    TRSTEP = (ATR*0.50)*4
    // Target profit = S*T
    TKPROFIT = (ATR*0.50)*16
    ENDIF
    IF CountOfPosition < 2 AND ONMARKET AND PositionPerf(1) <= 0 THEN
    //trailing will start @trailinstart points profit
    TRSTART = (ATR*0.45)*40
    //trailing step to move the "stoploss"
    TRSTEP = (ATR*0.45)*4
    // Target profit = S*T
    TKPROFIT = (ATR*0.45)*16
    ENDIF
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    SPLOSS = 0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    
    //first move (breakeven)
    IF SPLOSS = 0 AND close-TradePrice(1)>=TRSTART THEN
    SPLOSS = TradePrice(1)+TRSTEP
    ENDIF
    
    //next moves
    IF SPLOSS > 0 AND close-SPLOSS>TRSTEP THEN
    SPLOSS = SPLOSS+TRSTEP
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF SPLOSS = 0 AND TradePrice(1)-close>=TRSTART THEN
    SPLOSS = TradePrice(1)-TRSTEP
    ENDIF
    
    //next moves
    IF SPLOSS> 0 AND SPLOSS-close>TRSTEP THEN
    SPLOSS = SPLOSS-TRSTEP
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF SPLOSS > 0 THEN
    SELL AT SPLOSS STOP
    EXITSHORT AT SPLOSS STOP
    ENDIF
    
    //put the first stoploss
    IF ONMARKET AND SPLOSS = 0 THEN
    SET STOP pTRAILING TRSTART
    ENDIF
    #134615 quote
    robertogozzi
    Moderator
    Master

    At line 6 you are setting  TP at 0, because TKPROFIT is defined below that line and only when some conditions are met.

    I suggest adding this line 4:

    ONCE TKPROFIT = (ATR*0.50)*16

    or something similar.

    tradetrader101 thanked this post
    #134686 quote
    tradetrader101
    Participant
    Junior

    Thanks for your help, it’s definitely really appreciated. I’m going to add that to the code now. Do you have any idea why if I try to buy 0.1 of lumber for example the trailing stop, trailing step and take profit won’t appear on IG? but if I order 1.0 of anything then 99% of the time it’s fine?

    #134716 quote
    robertogozzi
    Moderator
    Master

    I have no clue about that, sorry!

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

Fractional Trades + Breakeven Stop Loss


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzi
5 years, 8 months ago.

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