PROBLEM WITH ORDER PLACING MT4

 

In my EA order is not placed by EA. The code is given below Any solution?

if(manualshort){
if(Close[0]< sellline){ 
if ((CurTime()- Time[0])>= 360){  
if(cnt<2){
res=  OrderSend(Symbol(),OP_SELL,Lots,Bid,1*PipFactor,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),SellOrder,0,Red);
 cnt++;
 longone=false;
longtwo=false;
  }
  }
  }
  }
 
sunilkumarks46:

In my EA order is not placed by EA. The code is given below Any solution?

When writing codes, try to write them as neat as possible, otherwise you may need this (https://www.mql5.com/en/forum/139579). If you have problem with your code, try to print whatever happen in your code, so you can tell precisely what's going on. for example

if (a > b)
  {
  print (" a is bigger than b);
  // do the code
  }

And always print the error message from your order send, there's example for that, look at MetaEditor > script folder > trade.mq4

If your order send is successful then do cnt++, if not, don't !

 
sunilkumarks46:

In my EA order is not placed by EA. The code is given below Any solution?

Is the value of cnt less than 2 ?

Don't use CurrrentTime() use TimeCurrent()

Also, read this: What are Function return values ? How do I use them ?

 
RaptorUK:

Is the value of cnt less than 2 ?

Don't use CurrrentTime() use TimeCurrent()

Also, read this: What are Function return values ? How do I use them ?


value of cnt is 1 only which is less than 2
 
sunilkumarks46:

value of cnt is 1 only which is less than 2

Did you do like my suggestion ?, at least like this below ?

 int res =  OrderSend(Symbol(),OP_SELL,Lots,Bid,1*PipFactor,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),SellOrder,0,Red);
   if(res < 1)
     {
      Print("Error = ",GetLastError());
     }
 

When I added the following include functions it is working. But the time required for compiling code is high, which is coming to 30 seconds


#include <stdlib.mqh>
#include <WinUser32.mqh>



if(manualshort){
if(Close[0]< sellline){ 
if ((CurTime()- Time[0])>= 300){  
if(cnt<2){
res=  OrderSend(Symbol(),OP_SELL,Lots,Bid,1*PipFactor,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),SellOrder,0,Red);
 if(res<1)
     {
       error=GetLastError();
      Print("Error = ",ErrorDescription(error));
      return;
     }
 cnt++;
 longone=false;
longtwo=false;
  }
  }
  }
  }
 
sunilkumarks46:

When I added the following include functions it is working. But for compiling code is high which is coming to 30 seconds

I think I told you to print everything, so you can see by your self. It's impossible for us to help here in mql4 forum, coz we all see nothing but some part of the code.

   if(manualshort)
     {
     Print ("manual short in on");
      if(Close[0] < sellline)
        {
        Print ("close 0 is less than selllin");
         if((CurTime()-Time[0]) >= 300)
           {
           Print ("time is bigger than 300");
            if(cnt < 2)
              {
              Print ("cnt is less than 2. sending order");
               string koment = "Volume: "+Volume[0]+"Time: "+ TimeToStr (TimeCurrent(), TIME_DATE|TIME_SECONDS);
               res = OrderSend(Symbol(),OP_SELL,Lots,Bid,1*PipFactor,0,0,koment,SellOrder,0,Red);
               if(res < 1)
                 {
                  error=GetLastError();
                  Print("Error = ",ErrorDescription(error));
                  return;
                 }
               cnt++;
               longone=false;
               longtwo=false;
              }
           }
        }
     }
 
sunilkumarks46:

When I added the following include functions it is working. But the time required for compiling code is high, which is coming to 30 seconds

Sorry I miss read that. instead including stdlib.mqh, you can also drag, stdlib.mq4 from libraries and drop it onto top of your code

#include "..\libraries\stdlib.mq4"
 
My doubt here is where it will print? whether in the log file or screen?
 
sunilkumarks46:
My doubt here is where it will print? whether in the log file or screen?

Terminal window > expert tab. It won't print on chart, that Comment() function :).

Just be careful, make sure it wont print on every tick. Just print after "if" or "switch" or after un-successful operation (OrderSend() fail, etc..). If you print this on every tick, you will have huge big size of log that can not be opened with notepad.

 
sunilkumarks46:
My doubt here is where it will print? whether in the log file or screen?
The best place to debug code is in the Strategy Tester, if you are doing that the output from the Print statements will appear in the .log file in the tester/logs folder and in the Journal tab.