Don't execute next trade

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #46510 quote
    Yngve
    Participant
    Senior

    Hi

    How would the code look like if i want the following outcome

    • Don’t enter the trade when the conditions come true, if the last trade taken by the system was a losing trade

    Thankfull for any help!

    Yngve

    #46517 quote
    robertogozzi
    Moderator
    Legend

    Try this one, it should work. It will disable only ONE trade after any loss, not all trades (this is what you asked, insn’t it?):

    DEFPARAM CumulateOrders = false
    ONCE LosingTrade = 0                   //initialize variable to allow trading
    Cond = close CROSSES OVER Average[10]  //condition to buy
    IF POSITIONPERF(1) < 0 THEN            //if the last one was a losing trade...
       IF LosingTrade = 0 THEN             //... and yhis is the firsr trade afterwards....
          LosingTrade = 1                  //... then disable trading
       ELSE
          Cond        = 0                  //if one losing trade already occurred do not trade and...
          LosingTrade = 0                  //... enable next trades
       ENDIF
    ENDIF
    IF Cond THEN                           //Buy if condition is met (unless disabled)
       BUY AT MARKET
       LosingTrade = 0                     //set variable to its initial value
    ENDIF
    SET TARGET pPROFIT 50
    SET STOP   pLOSS   20
    #46521 quote
    Yngve
    Participant
    Senior

    Yes, perfect!

    Thank you

    #46527 quote
    robertogozzi
    Moderator
    Legend

    I have found a logic bug, because I forgot to take note that one trade had already been skipped (after being skipped) despite conditions.

    So I added the variable “TradeSkipped” :

    DEFPARAM CumulateOrders = false
    ONCE LosingTrade  = 0                  //initialize variable to allow trading
    ONCE TradeSkipped = 0                  //initialize variable to mark a trade as skipped (after a loss)
    Cond = close CROSSES OVER Average[10]  //condition to buy
    IF POSITIONPERF(1) < 0 THEN            //if the last one was a losing trade...
       IF TradeSkipped = 0 THEN
          IF LosingTrade = 0 THEN          //... and this is the firsr trade afterwards....
             LosingTrade = 1               //... then disable trading
          ELSE
             Cond        = 0               //if one losing trade already occurred do not trade and...
             LosingTrade = 0               //... enable next trades
             TradeSkipped= 1               //mark this trade as skipped 
          ENDIF
       ENDIF
    ENDIF
    IF Cond THEN                           //Buy if condition is met (unless disabled)
       BUY AT MARKET
       LosingTrade  = 0                    //set variable to its initial value
       TradeSkipped = 0
    ENDIF
    SET TARGET pPROFIT 50
    SET STOP   pLOSS   20

    It should work fine now. Let me know after testing it. Sorry for the inconvenience.

    Roberto

    Nicolas thanked this post
    #46600 quote
    Yngve
    Participant
    Senior

    Thanks again @robertogozzi!

    It did reduce the number of consecutive losses on the strategy. But overall the performance was not improved. But thank you for the help!!!

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Don't execute next trade


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Yngve @yngve Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Yngve
8 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/18/2017
Status: Active
Attachments: No files
Logo Logo
Loading...