Warning on EA, Please help me!!!

Back to topics list To post a new topic, please log in or register
avatar
4
orangkere 2016.04.09 10:00
 

Warning


Please help me, i am newbie in this things. i have tried to build my own ea with custom indicator but i have some warning. please help me to solve this!

i do not know what to do :(

//+------------------------------------------------------------------+
//|                                                  ArrowSignal.mq4 |
//|                                       Copyright 2016, Orangkere. |
//|                                               facebook.com/arsya |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Orangkere."
#property link      "facebook.com/arsya"
#property version   "1.00"
#property strict

extern string  Nama_EA                 = "ArrowSignal";
extern int     TP                      = 6;
extern int     SL                      = 20;
extern double  Lot                     = 0.1;
extern int     Slippage                = 3;
extern int     dis                     = 24;
extern double  arrowPosition           = 0.25;
double         dPoint                  = 0;

int Buy,Sell;       

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
       if(Digits==3 || Digits==5) 
       {
         dPoint = Point*10;
       }
       else if(Digits==2 || Digits==4)
       {
         dPoint = Point;
       } 
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//----
   int      iTrade=0;
   double RedArrow   = iCustom(Symbol(),0,"ArrowSignal",dis,arrowPosition,0,0);
   double BlueArrow  = iCustom(Symbol(),0,"ArrowSignal",dis,arrowPosition,1,0);
   
   if (OrdersTotal()<1)
      {
       if((RedArrow>0) && (BlueArrow==0))
         {
            Sell=1;
         }
       }
       else
       {
        if((BlueArrow>0) && (RedArrow==0))
         {
            Buy=1;
         }
       }
   
   if(Buy==1)
     {
      OrderSend(Symbol(),OP_BUY,Lot,Ask,Slippage,Bid-SL*dPoint,Ask+TP*dPoint,0,Blue);
     }
   if(Sell==1)
     {
      OrderSend(Symbol(),OP_SELL,Lot,Bid,Slippage,Ask+SL*dPoint,Bid-TP*dPoint,0,Red);
     }
     

   for(iTrade=0;iTrade<OrdersTotal();iTrade++)
     {
      OrderSelect(iTrade,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
      {
         if((RedArrow>0) && (BlueArrow==0))
         {
            OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);
         }
      }
      else
      {
         if((BlueArrow>0) && (RedArrow==0))
         {
            OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Violet);
         }
      }
     }
   } 

//+------------------------------------------------------------------+






avatar
1200
FMIC 2016.04.09 10:40 #
 

In your code, you explicitly requested that the compiler use "strict" compilation, but in your code you have used some code in the "old" style of code which is not so strict.

For example, the functions "OrderSend()" and "OrderClose()" return status results, yet you have not assigned those return values to any variable or compared them as a means of checking if the functions executed correctly.


The warnings, about the number to string conversion, are in fact due to errors/bugs in your code where you missed out parameters, namely the "Comment" and the "Expiration" or "MagicNumber" (not sure which one you intended), on  the "OrderSend()" function. Always use a specific Magic Number (defined as an "extern" or "input") for orders in "OrderSend()" and when processing the orders, check the "OrderMagicNumber()" too. The Magic number value of "0" is for manual trades, so do not use that value.

// Your Code is "bugged":
OrderSend(Symbol(),OP_BUY,Lot,Ask,Slippage,Bid-SL*dPoint,Ask+TP*dPoint,0,Blue);

// Missing Parameters inserted (allways use a magic number):
OrderSend(Symbol(),OP_BUY,Lot,Ask,Slippage,Bid-SL*dPoint,Ask+TP*dPoint,"Comment",magicNumber,0,Blue);


Also, you should count down and not up when processing the orders (especially when closing orders as you are doing):

// Your code (incorrect)
for(iTrade=0;iTrade<OrdersTotal();iTrade++)

// Count down:
for( iTrade=OrdersTotal()-1; iTrade >= 0; iTrade-- )


There are actually a few more things that should be corrected or improved but I don't want to overwhelm you all at once.

avatar
Moderator
3206
avatar
4
orangkere 2016.04.09 12:42 #
 
FMIC:

In your code, you explicitly requested that the compiler use "strict" compilation, but in your code you have used some code in the "old" style of code which is not so strict.

For example, the functions "OrderSend()" and "OrderClose()" return status results as a boolean value, yet you have not assigned those return values to any variable or compared them as a means of checking if the functions executed correctly.


The warnings, about the number to string conversion, are in fact due to errors/bugs in your code where you missed out parameters, namely the "Comment" and the "Expiration" or "MagicNumber" (not sure which one you intended), on  the "OrderSend()" function. Always use a specific Magic Number (defined as an "extern" or "input") for orders in"OrderSend()" and when processing the orders, check the"OrderMagicNumber()" too. The Magic number value of "0" is for manualtrades, so do not use that value.


Also, you should count down and not up when processing the orders (especially when closing orders as you are doing):


There are actually a few more things that should be corrected or improved but I don't want to overwhelm you all at once.


how about "return value of 'OrderSend' should be checked". i still dont get it

please show me all, do not worry it won't overwhelming me.


avatar
4
orangkere 2016.04.09 13:05 #
 
//+------------------------------------------------------------------+
//|                                                  ArrowSignal.mq4 |
//|                                       Copyright 2016, Orangkere. |
//|                                               facebook.com/arsya |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Orangkere."
#property link      "facebook.com/arsya"
#property version   "1.00"
#property strict

extern string  Nama_EA                 = "ArrowSignal";
extern int     TP                      = 60;
extern int     SL                      = 200;
extern double  Lot                     = 0.1;
extern int     Slippage                = 30;
extern int     dis                     = 24;
extern double  arrowPosition           = 0.25;
extern int     magicNumber             = 123456;
double         dPoint                  = 0;

int Buy,Sell;       

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
       if(Digits==3 || Digits==5) 
       {
         dPoint = Point*10;
       }
       else if(Digits==2 || Digits==4)
       {
         dPoint = Point;
       } 
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//----
   int      iTrade=0;
   int ticket;
   double RedArrow   = iCustom(Symbol(),0,"ArrowSignal",dis,arrowPosition,0,0);
   double BlueArrow  = iCustom(Symbol(),0,"ArrowSignal",dis,arrowPosition,1,0);
   
   if (OrdersTotal()<1)
      {
       if((RedArrow>0) && (BlueArrow==0))
         {
            Sell=1;
         }
       }
       else
       {
        if((BlueArrow>0) && (RedArrow==0))
         {
            Buy=1;
         }
       }
   
   if(Buy==1)
     {
      ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,Slippage,Bid-SL*dPoint,Ask+TP*dPoint,"Beli chuy",magicNumber,0,Blue);
     }
   
   if(Sell==1)
     {
      ticket=OrderSend(Symbol(),OP_SELL,Lot,Bid,Slippage,Ask+SL*dPoint,Bid-TP*dPoint,"Jual chuy",magicNumber,0,Red);
     }
     

   for(iTrade=OrdersTotal()-1;iTrade>=0;iTrade--)
     {
      ticket=OrderSelect(iTrade,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
      {
         if((RedArrow>0) && (BlueArrow==0))
         {
            ticket=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);
         }
      }
      else
      {
         if((BlueArrow>0) && (RedArrow==0))
         {
            ticket=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Violet);
         }
      }
     }
   } 

//+------------------------------------------------------------------+


Thanks for your advice, i am glad at least i solve those warning, but when i tested it, there is no OP. Is something wrong with my script?

avatar
4
orangkere 2016.04.09 13:19 #
 

What different between "res" and "ticket"

"ticket=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);"

and

"res=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);"
avatar
Moderator
3406
GumRai 2016.04.09 13:33 #
 
orangkere:

What different between "res" and "ticket"

ticket=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);

and

res=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);

In this case there is no difference, but res is short for result and so it makes the code easier to follow. Using ticket as a boolean result could be confusing

  if(res==false)
    Print("Error closing ticket #",OrderTicket(),", Error code ",GetLastError());

and you have the error printed if the OrderClose fails. You can include a lot more in the print to help you to pinpoint the problem



avatar
12985
WHRoeder 2016.04.09 15:03 #
 
orangkere: how about "return value of 'OrderSend' should be checked". i still dont get it
What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
GumRai:
res=OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Violet);
if(res==false)
   Print("Error closing ticket #", OrderTicket(),", Error code ", GetLastError());
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Violet) )
   PrintFormat("Error closing ticket #%i, Error code %i", OrderTicket(), GetLastError());
and you can use OrderClosePrice() instead of Bid/Ask.
avatar
Moderator
3406
GumRai 2016.04.09 22:28 #
 
WHRoeder:
orangkere: how about "return value of 'OrderSend' should be checked". i still dont get it
What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
GumRai:
res=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);
if(res==false)
   Print("Error closing ticket #", OrderTicket(),", Error code ", GetLastError());
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.

If I was writing English, then I would never write if 2+2==4 either, English does not use == normally.

Would you write

if(the answer) mark it with a tick  ?

no, you would write

if the answer is correct, mark it with a tick.

I am sure that if(result==true) compiles to exactly the same as if(result)

I am trying to write replies that can be easily understood by inexperienced coders

I would not use

res=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);
if(res==false)
   Print("Error closing ticket #", OrderTicket(),", Error code ", GetLastError());

I would use

if(!OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet))
   Print("Error closing ticket #", OrderTicket(),", Error code ", GetLastError());

but new coders may not understand


avatar
12985
WHRoeder 2016.04.10 03:27 #
 
GumRai: I would use
if(!OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet))
but new coders may not understand
Agreed. I simply added something for the OP to consider.

Back to topics list  

To add comments, please log in or register