Code EA to open limited number of trades every time when there is a signal

 

Hello guy!

Huge respect for all the good hearted people who help the newbees. I searched 4 days for a solution but I couldn't find it anywhere, either it is an advanced code or I am to blind at this moment to find it.

So, I want to code a complex (from my point of view) EA and I'm stuck at sending orders. If I put only the condition for when to open a trade, my algo will open "infinite" orders. If I try to limit the orders by magic number, it won't open other positions when the conditions are met again.

For example, I use a MA and Volume to enter trades, algo should open 2 buy positions and one buyLimit when price is above MA and when there is enough buy volume. Simple until here. Now comes the mystery (for me) and where I need help. Algo should reenter in 2 buy position every time when the volume increases after a decrease as long price is above MA.

Somehow I can't figure it out how I can limit the algo to open 3 trades, and then 2 trades every time the conditions are met again.  

Thank you very much!

 
E.Cristian: If I put only the condition for when to open a trade, my algo will open "infinite" orders.

You are looking at a signal. So every tick you open another.

Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12

 
William Roeder:

You are looking at a signal. So every tick you open another.

Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12

Thank you very much for your reply!

You saved me!

 
I apologize for my lack of experience. I have tried the code, and it just delays the opening of orders. 
  static bool openCondition=false; static datetime firstSeen;
  bool prevCondition = openCondition; openCondition = (EntryIndi < Open[0] && kiju < Open[0] && wBuy >= wLine);
   if(openCondition)
   {
    if(!prevCondition) firstSeen = TimeCurrent(); // Remember first seen
    else if(TimeCurrent() - firstSeen >= 2)
    {
         OrderSend(NULL,OP_BUY,lotSize, Ask, 10,AtrStopLoss,AtrTakeProfit,NULL,magicNB);         
         OrderSend(NULL,OP_BUY,lotSize, Ask, 10,AtrStopLoss,0,NULL,magicNB);      
         OrderSend(NULL,OP_BUYLIMIT,lotSize2,priceLimit,10,AtrStopLoss,0,NULL,magicNB); 
 }
 else 
 {
   Alert("uuu");
 }

What did I do wrong?

 

You added firstSeen and broke the logic. Just use if(openCondition && !prevCondition)

If you really need firstSeen, make it part of your condition.

 

Hi Guys,

coded a system which compiled with no errors but 6 warnings of return value of'OrderClose','OderSend' and 'OrderSelect' should be checked. Secondly on strategy testing the trades are grouped together on one candle everytime trades are triggered, how to solve this please help

Reason: