Not logged in
Viewing 2 posts - 1 through 2 (of 2 total)

Forums>AlgoWizard / EA Wizard>Make my EA>Restrict to opening one trade (with Take Profit and Stop Loss) per bar

  • #256168 |
    Participant
    1 Posts

    Hi I would like to restrict my bot (MT4) to open one trade per bar

    via the AlgoWizard I have done the following:

    Buy: Bars since Order Open for Long to be greater than 0(so at least one new bar until last long order open)

    and Bars since Order Open for Short to be greater than or equal to 0 (I just use this because of the symmetrical conditions. It will always be True)

    and

    Sell: Bars since Order Open for Short to be greater than 0 (symmetrical to above)

    and Bars since Order Open for Long to be greater than or equal to 0 (symmetrical to above)

    I attach the strategy

    In MQL4 I have coded this as follows:

    datetime prevtimeb;
    datetime prevtimes;
    ...
    void OnTick()
    {
    // BUY
    if(buy_condition1 && buy_condition2 && prevtimeb!=Time[0])
    (
    Open_Order(OP_BUY,sl,tp);
    prevtimeb=Time[0];
    }
    // SELL
    if(sell_condition1 && sell_condition2 && prevtimes!=Time[0])
    (
    Open_Order(OP_SELL,sl,tp);
    prevtimes=Time[0];
    }
    
    }

    Backtesting both bots (with same conditions etc.) does not produce similar results.

    Any ideas?

    #256616
    tomas262
    Administrator
    1826 Posts

    Hello,

    by default a strategy made with Wizard is set to trade once per bar open – it evaluates conditions on bar open only

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.