Pause system after 2 losses

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #173502 quote
    ProRealP
    Participant
    Senior

    Hello!
    I’m trying to add a parameter that won’t allow my system to continue trading after 2 consecutive losses in the same day, but without quitting the system. I’ve copy pasted from a couple of old threads here, but can’t quite get it to work. This is what I’ve “come up with”

    Once TradeON = 1
    If IntraDayBarIndex = 0 then
    TradeON = 1
    Endif
    
    if strategyprofit <> strategyprofit[1] then
    if positionperf(1)<0 then
    perte=perte+1
    else 
    perte=0
    endif
    endif
    
    if perte >=2 then
    TradeON = 0
    endif

    Does anyone know what I’m doing wrong or have any ideas about how to code this?

    #173504 quote
    Nicolas
    Keymaster
    Master

    Seems fine to me, TRADEON variable should  be tested before entries:

     

    if buycondition and TRADEON then 
     buy at market 
    endif
    #173506 quote
    ProRealP
    Participant
    Senior

    I’ve added TRADEON to the buy conditions like you show, but it still seems to take more positions then “allowed”. Here is an example, though i reckon it’s not enough to go on. It shouldn’t have taken the position on the 6th at 19.18 with this code, am I right?

    ClosedPositionList.jpg ClosedPositionList.jpg
    #173509 quote
    robertogozzi
    Moderator
    Master

    You should add this line just after line 3 (before ENDIF):

    perte=0

    but this has nothing to do with your issue.

    It’s a nother issue, since you never reset PERTE at the beginning of a new day, it may happen that you never enter at market again after 2 losses as STERATEGYPROFIT will never change again!

    The question you asked is to stop after 2 LOSSES, not after 2 trades.

    #173510 quote
    robertogozzi
    Moderator
    Master

    Your issue is due to using POSITIONPERF instead of STRATEGYPROFIT.

    Try this code:

    Once TradeON = 1
    If IntraDayBarIndex = 0 then
       TradeON = 1
       perte   = 0
    Endif
     
    if strategyprofit < strategyprofit[1] then
       perte=perte+1
    elsif strategyprofit > strategyprofit[1] then
       perte=0
    endif
    
    if perte =2 then
       TradeON = 0
    endif
    #173513 quote
    ProRealP
    Participant
    Senior

    I believe I understand the logic of your code. Perte is set to 0 at new day and if two losses are recorded then tradeon=0. Makes sense.

    But it still takes positions after 2 losses. The positions are exactly the same as with the code I first used.

    It’s quite odd because if I change “if perte =2″ then to “if perte =1” it seems to work flawlessly, but then closes after 1 loss..

    ClosedPostionPerte1.jpg ClosedPostionPerte1.jpg
    #173515 quote
    ProRealP
    Participant
    Senior

    Pauses after 1 loss*

    #173516 quote
    robertogozzi
    Moderator
    Master

    I think yoy haven’t added TradeON to your conditions to enter a position.
    My code works like a charm:

    Once TradeON = 1
    If IntraDayBarIndex = 0 then
       TradeON = 1
       perte   = 0
    Endif
     
    if strategyprofit < strategyprofit[1] then
       perte = perte + 1
    elsif strategyprofit > strategyprofit[1] then
       perte=0
    endif
     
    if perte = 2 then
       TradeON = 0
    endif
    IF close CROSSES OVER average[20] and not onmarket and TradeON THEN
       BUY AT Market
    ENDIF
    IF close CROSSES UNDER average[20] and not onmarket and TradeON THEN
       SELLSHORT AT Market
    ENDIF
    SET TARGET pPROFIT 100
    SET STOP   pLOSS   50
    graph perte   coloured(255,0,0,255)
    graph TradeON coloured(0,0,255,255)
    x-3.jpg x-3.jpg
    #173523 quote
    ProRealP
    Participant
    Senior

    I’ve definitely added it, see that portion of my code here.
    As you can see from the other picture it still takes a position after the second loss just before 20.00.
    Shouldn’t it have paused after that loss?

    2wins2losses1blackSameDay.jpg 2wins2losses1blackSameDay.jpg and-TradeOn.jpg and-TradeOn.jpg
    #173527 quote
    robertogozzi
    Moderator
    Master

    If you write the code AFTER any entry, it will be evaluated correctly the next bar.
    As lines dealing with TradeON and perte affect entries, they should be place BEFORE them.
    Code is read and executed sequentially.

    ProRealP and Jalinor thanked this post
    #173531 quote
    ProRealP
    Participant
    Senior

    I was not aware of that. It’s working perfectly now.

    Thanks!

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

Pause system after 2 losses


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ProRealP @prorealpierre Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/12/2021
Status: Active
Attachments: 5 files
Logo Logo
Loading...