MQL5 is double posting my orders

 

Just recently, when I "test" my advisor, everything runs as it should...Single order placed.  BUT...When I attach my advisor to my chart to do live trading, whenever it makes an order it places it twice...But NOT on the same OnTick.  I know because the amount I order for I've coded it to fluctuate the Amt by 1x-3x.

Now the first thing I see it that the orders are placed 2 seconds apart...This is not possible, as I have flags built in to prohibit such things.

// Place Buy Order
if (CyclePause < 1 && DoNotTradeTillAfterTime < time && OpenPositions < 1)
//  *** Even if there is a delay in the order posting, the setting of the above flags should prevent a secondary transaction
   if (TransactImmediately=="buy"||(plusorminuscount > 0 && TransactImmediately=="Buy"))
   {
        plusorminuscount=0;
        Print("*** - Buy TransactImmediately= ",TransactImmediately,"   RSI=",myRSIValue);
        TransactImmediately="";
        Print("Buy...(",Amt,",NULL,",Ask,",",(Ask-500* _Point),",",(Ask+150* _Point),",NULL)");
        trade.Buy(Amt,NULL,Ask,(Ask-550* _Point),(Ask+250* _Point),NULL);  
        CyclePause = 1;
        DoNotTradeTillAfterTime = time + 120;
    }

I understand that there is a delay in the fulfillment of the order, which is why the OpenPositions doesn't always work, but why are my flags not preventing the logic from happening a second time?


Thanks in Advance,

MK

<Edit>...After placing a SLEEP(2000) line in at the end, I woke up this morning to find 4 orders placed at 4 different times 1-2 seconds apart.

 

I have <Code> button, and I do not have any problem with images.

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button


Reason: