EA does not open any order in Demo Account

 

Hi, 

I am new here and I start my first EA, everything seem ok in backtest, the EA open orders when the conditions are met. When I put it in Demo account no orders are open, I try to catch the error but no works too...

Can anyone help me, please.

My broker is MIG and I am using a demo account with 100 000$ to test it.

 See the EA attached.

 

Thanks,

LinnuxFX 

Files:
 
LinnuxFX:

Hi, 

I am new here and I start my first EA, everything seem ok in backtest, the EA open orders when the conditions are met. When I put it in Demo account no orders are open, I try to catch the error but no works too...

Can anyone help me, please.

When you place a market order you MUST Buy at Ask and Sell at Bid . . .   ( checkOpenOrders() )

You need to know why and if your OrderSend() is failing . . .  check the return value from the OrderSend() call and report the error to the log . . .   read this and modify your code to report the error:  What are Function return values ? How do I use them ?


Is your Broker an ECN Broker ?

 
Also . . . what is the point in setting a Magic Number if you are never going to check it ?  this makes your EA incompatible with other EAs and manual trades . . .  your EA would end up managing the other EA's trades and any manually placed trades.
 

Hi, thanks for help 

Everything works fine now....

 

To improve my code I need to open a new order if any order of my EA is losing more than 100 pips.

Ex: If my EA have 5 open orders  and one start lose more than 100 pips I want open a new order to cover that one, then if another open order start lose more than 100 pips the EA open a new order to cover that order. Each loss order could only have one cover order even if the price still go agains the new order.

 

My ideia was manage orders with an dynamic array, where I put the orderticket() every time one order generate other, and then check the array, if the order exists in the array it means that new cover order was opened for such order, so now on no new orders could be opened for that one in the array.

 

I try do something like this: 

void cutDrawndraw()

{  

   int totalOrders=OrdersTotal();   

        for(int pos=0;pos<totalOrders;pos++){

         if(OrderSelect(pos, MODE_TRADES, SELECT_BY_POS)==true){  

            if(OrderMagicNumber() == magic){                

               if(MathAbs(OrderOpenPrice() - Bid) > 0.01000){

                   found = false;

                  count = ArraySize(lossOrders);   

                  if (count==0){

                     element_count = ArrayResize(lossOrders, count+1);

                     lossOrders[count] = OrderTicket();

                     Print("ORDER_0 ticket =================================== " + OrderTicket());

                     count=count+1;                     

                     if(OrderType() == OP_SELL){

                        ticket=OrderSend(Symbol(), OP_SELL, maxLOT*2, Bid, 30, 0, 0, "FPS2_" + Symbol() + "_DR", magic, 0, Yellow);

                        if(ticket<0)

                        {

                        Print("OrderSend failed with error #",GetLastError());

                        return(0);

                        }

                     }

                     if(OrderType() == OP_BUY){

                        ticket=OrderSend(Symbol(), OP_BUY, maxLOT*2, Ask, 30, 0, 0, "FPS2_" + Symbol() + "_DR", magic, 0, Yellow);

                        if(ticket<0)

                        {

                        Print("OrderSend failed with error #",GetLastError());

                        return(0);

                        }

                     }

                  }

                                       

                  for(int i=0; i<count; i++)

                  {

                     if(lossOrders[i] == OrderTicket()){found=true;} 

                     Print("========#################> ENCONTROU " + found);                                     

                     Print("TESTE do ARRAY");

                  }         

                  if(found==false){

                     element_count = ArrayResize(lossOrders, count+1);

                     lossOrders[count+1] = OrderTicket();                  

                  if(OrderType() == OP_SELL){

                     ticket=OrderSend(Symbol(), OP_SELL, maxLOT*2, Bid, 30, 0, 0, "FPS2_" + Symbol() + "_DR", magic, 0, Yellow);

                     if(ticket<0)

                     {

                        Print("OrderSend failed with error #",GetLastError());

                        return(0);

                     }

                  }

                  if(OrderType() == OP_BUY){

                     ticket=OrderSend(Symbol(), OP_BUY, maxLOT*2, Ask, 30, 0, 0, "FPS2_" + Symbol() + "_DR", magic, 0, Yellow);

                     if(ticket<0)

                     {

                        Print("OrderSend failed with error #",GetLastError());

                        return(0);

                     }

                  }

                  }

               }

             }

           }

      }

}

 

I think this code does not work because my order ticket() value is not the real value but 1 or 0. Don't knew why...

 

Hope you can help me..

Thanks 

 
LinnuxFX:


My ideia was manage orders with an dynamic array, where I put the orderticket() every time one order generate other, and then check the array, if the order exists in the array it means that new cover order was opened for such order, so now on no new orders could be opened for that one in the array.


What happens if MT4 crashes ?  what happens if your PC crashes or you need to reboot it unexpectedly ?  you will lose the data in your array, how will you pick up from where you left off ?
 

Hi RaptorUK,

 

Thanks for answer. I think you were right, so what is the best solution, if you understand my question.

 

tx

LinnuxFX 

 
LinnuxFX:

Hi RaptorUK,

 Thanks for answer. I think you were right, so what is the best solution, if you understand my question.

Write your array data to a file,  when the file changes copy it to offsite backup . . .  if you have a crash you can then recover from the file,  if the local copy is on a dead PC you have the offsite backup . . . .  alternatively use a method that does not depend on the array data at all.
 
RaptorUK:
Write your array data to a file,  when the file changes copy it to offsite backup . . .  if you have a crash you can then recover from the file,  if the local copy is on a dead PC you have the offsite backup . . . .  alternatively use a method that does not depend on the array data at all.

Hello,

I have another situation to try solve in my EA:

In my code I only want the EA open orders when the H1, H4, daily, weekly and monthly candles close respectively, but if the platform was disconnected in this periods it will loose a lot of orders.

Could you please help me build a piece of code that recalculate when the platform logged again. 

I have this code to open  orders when the H4 candle close:

   
        int hour = Hour();
        int min  = Minute();
        int day  = Day();
        int week = DayOfWeek();
    
        static datetime Time0; 
   
        if (Time0 != Time[0]){
        
        if(min == 0){   
        if(hour == 1 || hour == 5 || hour == 9 || hour == 13 || hour == 17 || hour == 21){
                totalOrder();
                if (canTrade == true){
                takeProfitPips = NormalizeDouble(MathAbs(closePriceH4 - PivotH4)*0.3, MarketInfo(Symbol(), MODE_DIGITS));
                if(closePriceH4 > PivotH4 && tradeH4 == true){   
                        ticket=OrderSend(Symbol(), OP_SELL, maxLOT, Bid, 30, 0, 0, "FPS2_" + Symbol() + "_H4", magic, 0, Red);
                        if(ticket<0){
                                Print("OrderSend failed with error #",GetLastError());
                                return(0);
                }else   {
                                OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
                                OrderModify(ticket,OrderOpenPrice(),0,Bid - takeProfitPips,0,Green);
                                                }
                } 

 Problem:

If the platform was disconnected from 00:59 to 1:10, when it connect again the EA will not open orders if the conditions were met.

 

Thanks, 

LinnuxFX 

Reason: