OrderClose not working - page 4

 

Hi,

I compile the following it got errors like this: May I know which part went wrong?


'postin forum.mq4'      postin forum.mq4        1       1
',' - unexpected token  postin forum.mq4        59      53
expression has no effect        postin forum.mq4        59      54
1 error(s), 1 warning(s)                2       2
//+------------------------------------------------------------------+
//|                                                       chuale.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.abc.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.abc.com"
#property version   "1.00"
#property strict

extern double   TakeProfit=500;
extern double   Lots=0.1;
extern double   StopLoss=300;

double     bar1;
double     bar2;
double     bar3;
int        total,ticket;
//datetime   previousTime; 

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
  
//---
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {

  total=OrdersTotal();
      bar1=(iClose(Symbol(),PERIOD_M1,2)-iClose(Symbol(),PERIOD_M1,3))*100;
      bar2=(iClose(Symbol(),PERIOD_M1,1)-iClose(Symbol(),PERIOD_M1,2))*100;
      bar3=(iClose(Symbol(),PERIOD_M1,0)-iClose(Symbol(),PERIOD_M1,1))*100;
     Comment("Bar1="+DoubleToString(bar1,Digits)+"\n"+
             "Bar2="+DoubleToString(bar2,Digits)+"\n"+
             "Bar3="+DoubleToString(bar3,Digits)+"\n"
             );
                         
   if(total>0)
   {
   OrderSelect(0,SELECT_BY_POS);
   if (bar3<-2) OrderClose(OrderTicket(),Lots,Bid,3),Green;
   if (bar3>2) OrderClose(OrderTicket(), Lots,Ask,3,Red);
   }
   //if(Time[0]==previousTime) return(0);
   //previousTime=Time[0];
   if(total<1)
     {
      if (bar3>1)
      {  
      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Chua EA",12345,0,Green);
      //if(ticket<0)Print("Error OP_BUY order failed, error:"+GetLasterror());
      return(0);
      }
      
      if (bar3<-1)
      {
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid+-TakeProfit*Point,"Chua EA",12345,0,Red);
      //if(ticket<0)Print("Error OP_SELL order failed, error:"+GetLasterror());
      return(0);
      }
     }
   
   return(0);
  }
//+------------------------------------------------------------------+
 
Compare the two lines.
   if (bar3<-2) OrderClose(OrderTicket(),Lots,Bid,3),Green;
   if (bar3>2)  OrderClose(OrderTicket(),Lots,Ask,3,Red);
 

The error report tells you where the error is

',' - unexpected token postin forum.mq4 59 53

and if you double click on the error, the cursor is taken straight to the problem

 

Hi GumRai,


Thanks, I got it fixed. The error comes from the parentheses accidentally inserted.

 

Thank you WHRoeder.

Is

 

Hi thrdel,

Is Time[0] refering to the time of bar 0? Is there Time[1], Time [2] etc? I tried googled it but not much information in the internet. Also, if I attach this EA to two currency pairs, does it mean that OrderSelect only select the orders in the chart itself or all the orders in the terminal?

 

Hi thrdel,


Why I get this warning message "implicit conversion from 'number' to 'string' postin forum.mq4 69 61" for the coding " if(ticket<0)Print("Error OP_BUY order failed, error:"+GetLastError());"?

 
chuale:

Is Time[0] refering to the time of bar 0? Is there Time[1], Time [2] etc?

Yes

chuale:

I tried googled it but not much information in the internet.

http://bit.ly/1fJi4XA

chuale:

Also, if I attach this EA to two currency pairs, does it mean that OrderSelect only select the orders in the chart itself or all the orders in the terminal?

depends on your code

 
Thanks qiol
 
chuale:

Hi thrdel,


Why I get this warning message "implicit conversion from 'number' to 'string' postin forum.mq4 69 61" for the coding " if(ticket<0)Print("Error OP_BUY order failed, error:"+GetLastError());"?


"implicit conversion from 'number' to 'string'" can be a pain in the butt when you have large loops.

It means having to scroll through loads of lines in the error report.

In your case GetLastError() is an integer code, so it is just warning you that it will be converted to a string for the print statement.

If you are happy that it is not a problem then you can add (string) to stop these annoying warnings.

if(ticket<0)   Print("Error OP_BUY order failed, error:" + (string) GetLastError());

Incidently, if you didn't know-

I usually place this after the Externs/Inputs

#include <stdlib.mqh>

and then you can use

if(ticket<0)   Print("Error OP_BUY order failed, error: " + ErrorDescription(GetLastError() ) );

So that the description of the error prints, not just the code

Reason: