Do not take a trade for x bars after trade closed

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #97518 quote
    richarjo
    Participant
    Senior

    Hi.

    I am unfamiliar with coding and am still trying to learn PRT, and I have a problem with an algo that I am working on. My problem as follows:

    When taking buy/sell orders, the algo will e.g take the buy order, and at a point sell at market when the sell criteria have been met. (and vice versa for sell orders)

    The problem that arises is when the candles go into a small range, the algo continues to buy/sell contracts.

    Is there a way of coding to prevent this from happening? e.g. Do not take a long for x bars after the long contract has been sold and the opposite for short orders?

    Any help is appreciated

     

    Regards

    #97525 quote
    robertogozzi
    Moderator
    Master

    You need to count bars elapsed after a trade ended:

    ONCE WaitBars = 10   
    ONCE TradeON  = 1     //1=enable trading   0=disable trading
    ONCE Count    = 0     //tallies bars as they elapse after a trade exits
    IF Count > 0 THEN
       Count = Count + 1  //tally bar after bar
    ENDIF
    IF Not OnMarket AND OnMarket[1] THEN  //as soon as a trade exists start tallying
       Count   = 1                        //set counter to 1 to start tallying
       TradeON = 0                        //disable trading
    ENDIF
    IF Count > WaitBars THEN   //after desired number of bars elapsed reenable trading
       Count   = 0             //clear counter
       TradeON = 1             //enable trading
    ENDIF
    IF MyConditions AND Not OnMarket AND TradeON THEN //add TradeON to your conditions
       BUY/SELLSHORT...
    ENDIF
    #97531 quote
    richarjo
    Participant
    Senior

    Thank you for the displayed code Robert, I have incorporated it into my algo. However it has a problem with the “TradeOn” instruction which in the error message states SYNTAX ERROR: THIS VARIABLE IS NOT USED IN THE CODE:TRADEON

     

    Regards

    #97536 quote
    robertogozzi
    Moderator
    Master

    Use it like I did in line 15.

    #97551 quote
    richarjo
    Participant
    Senior

    Thanks Robert, It works great

     

    Regards

    #97556 quote
    Vonasi
    Moderator
    Master

     

    richarjo – Please use topic titles that actually mean something to help others know what your topic is about. I have changed your topic title from ‘Code’ to something more meaningful. 🙂

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

Do not take a trade for x bars after trade closed


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
richarjo @richarjo Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by Vonasi
6 years, 10 months ago.

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