Download MetaTrader 5

Implicit conversion from number to string error

To add comments, please log in or register
Simon Clark
12
Simon Clark  
Hi,
I'm a newbie looking at writing a very basic expert advisor to help me with my Trading self-training. I have no real experience of MQL4 coding so please be gentle with me lol

I've got a line of code that gives me an "Implicit conversion from number to string error" when I try and complie in in MT4
I've searched on this great MQL4 forum and found similar threads but I cant seem to be able to apply the answers given to my piece of code. So I thought I'd join and post a thread asking the question :)

Would someone mind advising please why this error is popping up when it tries to compile the "int buyticket" line of code below?


//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
int buyticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,3.0,(Ask +0.10),NULL,26082014,0,Green);
}
//+------------------------------------------------------------------+

Cheers,
Clank


Keith Watford
Moderator
10615
Keith Watford  

You have not included a stoploss in the ordersend.

So it is taking NULL to be the take profit and 26082014 as the order comment. As it is expecting a string , but finds a number, you get the warning 

int buyticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,3.0,Insert Stoploss here,(Ask +0.10),NULL,26082014,0,Green); 

 I hope that makes sense

Carl Schreiber
7362
Carl Schreiber  

You can look it up yourself by comparing your variables (number and position) in OrderSend() to the requirements of the variables of OrderSend() - just look into the editor's reference:

int  OrderSend(
   string   symbol,              // symbol
   int      cmd,                 // operation
   double   volume,              // volume
   double   price,               // price
   int      slippage,            // slippage
   double   stoploss,            // stop loss
   double   takeprofit,          // take profit
   string   comment=NULL,        // comment
   int      magic=0,             // magic number
   datetime expiration=0,        // pending order expiration
   color    arrow_color=clrNONE  // color
   );
Simon Clark
12
Simon Clark  

Hi,

Thankyou for this - my code is now  int buyticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,3.0,9,(Ask +0.10),NULL,26082014,0,Green); so in effect this gives me a stop loss of 9 pips.

I dont want to badger you as the weekend is coming up, but i have one more error repeated a few times in my next piece of code - namely "return value of 'Order Select' should be checked.

As an example it gets generated here: OrderSelect (result,SELECT_BY_TICKET); 

Using your analysis above, i assume I now have to specify a result ? Sorry for being vague but I've only been learning MQL4 for a day or 2, whereas you guys have such deep knowledge it must have taken you years of study to master? I really appreciate you taking the time to help me :)

Cheers,

Clank 

honest_knave
Moderator
2319
honest_knave  
Clank_001:

I dont want to badger you as the weekend is coming up, but i have one more error repeated a few times in my next piece of code - namely "return value of 'Order Select' should be checked.

As an example it gets generated here: OrderSelect (result,SELECT_BY_TICKET); 

Using your analysis above, i assume I now have to specify a result ? Sorry for being vague but I've only been learning MQL4 for a day or 2, whereas you guys have such deep knowledge it must have taken you years of study to master? I really appreciate you taking the time to help me :)


 

Have a read here and all should become clear.

Basically, it is a warning not an error saying, "don't you want to make sure this worked?"

Keith Watford
Moderator
10615
Keith Watford  
Clank_001:

Hi,

Thankyou for this - my code is now  int buyticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,3.0,9,(Ask +0.10),NULL,26082014,0,Green); so in effect this gives me a stop loss of 9 pips.

 

 

Using 9 as the SL does not give you a SL of 9 pips. You are on the right track with the TP at Ask+0.10
To add comments, please log in or register