EA not trading - help

 

Good afternoon guys.

My EA is not trading. I tried all sorts of different testings (strategy, profiling, real time), and no error messages popped up yet my EA would not trade...

According to my judgement, my EA should trade using the parameters I set.

I can not comprehend what is wrong and I need some help :(

 

 

 

bool Buy_Condition_1 = (a);
bool Buy_Condition_2 = (b);
bool Buy_Condition_3 = (c);


//----- Putting it all together
 if (Buy_Condition_1 && Buy_Condition_2)
    {
     if(Buy_Condition_3)
      { 
     // alguma posiÁ„o aberta
      if (Buy_opened)
      {
        Alert ("We already have a Buy Position!!!");
        return; // Cancelamento de abrir mais ordens
      }
      ZeroMemory(mrequest);
      mrequest.action = TRADE_ACTION_DEAL;   //ordem imediata de execuÁ„o
      mrequest.price = NormalizeDouble (latest_price.ask,_Digits); // ⁄ltimos preÁos atualizados
      mrequest.sl = NormalizeDouble (latest_price.ask - STP*_Point,_Digits); // Stop Loss
      mrequest.tp = NormalizeDouble (latest_price.ask + TKP*_Point,_Digits); // Take Profit
      mrequest.symbol = _Symbol; //currency pair
      mrequest.volume = Lot; // Lotes de trade
      mrequest.magic  = EA_Magic;// N˙mero m·gico
      mrequest.type = ORDER_TYPE_BUY; // Ordem de compra
      mrequest.type_filling = ORDER_FILLING_FOK; //Tipo de execuÁ„o
      mrequest.deviation=100; //Desvio do preÁo atual
      //---------- Send Order
      if (OrderSend (mrequest,mresult));else;  
//pegar resultado
if (mresult.retcode==10009 || mresult.retcode==10008) // Request completed or placed
  {
   Alert ("A Buy Order has been successfuly placed with Ticket#: ", mresult.order,"!!");
  }
 else
  {
   Alert ("The Buy Order request could not be completed - error: ",GetLastError());    
   ResetLastError();
   return;
   }

//----- Declare bool type variables to hold our Sell Conditions
  bool Sell_Condition_1 = (a); //MÈdia MÛvel caindo
  bool Sell_Condition_2 = (b);
  bool Sell_Condition_3 = (c );

  
//-----Putting all together
  if(Sell_Condition_1 && Sell_Condition_2)
      {
       if(Sell_Condition_3)
          {
           // any opened Sell position?
            if (Sell_opened)
            {
               Alert("We already have a Sell Position!!!");
               return; // Cancelamento da ordem de venda
            }
             ZeroMemory(mrequest);
             mrequest.action = TRADE_ACTION_DEAL;   //ordem imediata de execuÁ„o
             mrequest.price = NormalizeDouble (latest_price.ask,_Digits); // ⁄ltimos preÁos atualizados
             mrequest.sl = NormalizeDouble (latest_price.ask - STP*_Point,_Digits); // Stop Loss
             mrequest.tp = NormalizeDouble (latest_price.ask + TKP*_Point,_Digits); // Take Profit
             mrequest.symbol = _Symbol; //currency pair
             mrequest.volume = Lot; // Lotes de trade
             mrequest.magic  = EA_Magic;// N˙mero m·gico
             mrequest.type = ORDER_TYPE_SELL; // Ordem de venda
             mrequest.type_filling = ORDER_FILLING_FOK; //Tipo de execuÁ„o
             mrequest.deviation=100; //Desvio do preÁo atual
         //--- send order
        if (OrderSend (mrequest,mresult)); else;
      
              
  
           

   
   

 

Kind regards,

Pedro 

By the way sorry for deleting the topic before. It was a silly decision on my behalf. 

 
Hi Pedro

Before anyone starts going through your code - are you with Alpari???
 

Nope, I am using the MetaTrader Brazil Demo server. 

Test the code to see if it works with your server, because mine does not work. Not even back testing it trades. It is pretty annoying considering that the code compiles pretty well. 

By the way I am sorry for deleting the topic before. In the heat of the moment I decided to delete it.  

 

Well I have tried one solution which was editing the bool Buy and Sell conditions, but it clearly did not work. This error is driving me insane. The worse, is not a single error message or warning is there to help me.....

 

Thank you for your attention, and once again sorry for deleting the topic before. 

 

People I am very sorry, for possibly saying stupid, but what could be resulting this error? I can not fathom what is wrong. 

I have now just tried to change the order send, and the codes, for mresult and mrequest. Once again no difference. :(

This is bugging me for a week.  

 
Hi Pedro

I'm not at my trading PC this morning so can't do much just now for you. To start with I would suggest putting in some more debugging code to check that variables and conditions are performing as expected.
 
PedroCamargo:

Good afternoon guys.

My EA is not trading. I tried all sorts of different testings (strategy, profiling, real time), and no error messages popped up yet my EA would not trade...

According to my judgement, my EA should trade using the parameters I set.

I can not comprehend what is wrong and I need some help :(

 

 

 

 

Kind regards,

Pedro 

By the way sorry for deleting the topic before. It was a silly decision on my behalf. 

  • You SELL conditions are inside your BUY block.
  • Your BUY block will never be called as...
  • Your second condition is always false, p_close is never initialized.
 
Thank you very much. I have began making the corrections. Just the second point I could not really comprehend what you meant. But other than that, the changes are being made and I shall put the code here once it is fixed. 
 
PedroCamargo:
Thank you very much. I have began making the corrections. Just the second point I could not really comprehend what you meant. But other than that, the changes are being made and I shall put the code here once it is fixed. 
bool Buy_Condition_1 = (maVal[0]>maVal [1]) && (maVal [1]>maVal [2]);
bool Buy_Condition_2 = (p_close >maVal [1]);                                ===> always false
bool Buy_Condition_3 = (MACDValues[2]<MACDLevel && MACDValues[1]>MACDLevel);


//----- Putting it all together
 if (Buy_Condition_1 && Buy_Condition_2)
   {
    ... // never executed
   }
 

Code so far.

 

bool Buy_Condition_1 = (a) && (b);
bool Buy_Condition_2 = (c);
bool Buy_Condition_3 = (d);

//--- Putting all together   
   if(Buy_Condition_1 && Buy_Condition_2)
     {
      if(Buy_Condition_3)
        {
         // any opened Buy position?
         if(Buy_opened)
           {
            Alert("We already have a Buy Position!!!");
            return;    // Don't open a new Buy Position
           }
         ZeroMemory(mrequest);
         mrequest.action = TRADE_ACTION_DEAL;                                  // immediate order execution
         mrequest.price = NormalizeDouble(latest_price.ask,_Digits);           // latest ask price
         mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits); // Stop Loss
         mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits); // Take Profit
         mrequest.symbol = _Symbol;                                            // currency pair
         mrequest.volume = Lot;                                                 // number of lots to trade
         mrequest.magic = EA_Magic;                                             // Order Magic Number
         mrequest.type = ORDER_TYPE_BUY;                                        // Buy Order
         mrequest.type_filling = ORDER_FILLING_FOK;                             // Order execution type
         mrequest.deviation=100;                                                // Deviation from current price
         //--- send order
           if (OrderSend (mrequest,mresult)); else;
         // get the result code
         if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
           {
            Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!");
           }
         else
           {
            Alert("The Buy order request could not be completed -error:",GetLastError());
            ResetLastError();           
            return;
           }
        }
     }
/*
    2. Check for a Short/Sell Setup : MA-8 decreasing downwards, 
    previous price close below it, ADX > 22, -DI > +DI
*/
//--- Declare bool type variables to hold our Sell Conditions
 bool Sell_Condition_1 = (a); //MÈdia MÛvel caindo
  bool Sell_Condition_2 = (b);
  bool Sell_Condition_3 = (c);                    
//--- Putting all together
   if(Sell_Condition_1 && Sell_Condition_2)
     {
      if(Sell_Condition_3)
        {
         // any opened Sell position?
         if(Sell_opened)
           {
            Alert("We already have a Sell position!!!");
            return;    // Don't open a new Sell Position
           }
         ZeroMemory(mrequest);
         mrequest.action=TRADE_ACTION_DEAL;                                // immediate order execution
         mrequest.price = NormalizeDouble(latest_price.bid,_Digits);           // latest Bid price
         mrequest.sl = NormalizeDouble(latest_price.bid + STP*_Point,_Digits); // Stop Loss
         mrequest.tp = NormalizeDouble(latest_price.bid - TKP*_Point,_Digits); // Take Profit
         mrequest.symbol = _Symbol;                                          // currency pair
         mrequest.volume = Lot;                                              // number of lots to trade
         mrequest.magic = EA_Magic;                                          // Order Magic Number
         mrequest.type= ORDER_TYPE_SELL;                                     // Sell Order
         mrequest.type_filling = ORDER_FILLING_FOK;                          // Order execution type
         mrequest.deviation=100;                                             // Deviation from current price
         //--- send order
           if (OrderSend (mrequest,mresult)); else;
         // get the result code
         if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
          

Corrections suggested have been made (except the second one, could not understand what was meant). Only one issue though, it still does not trade. This is indeed pretty frustrating to me

 
Have a check now. See if it works. In my PC it still does not do anything. Could be my server or internet. Not sure