Download MetaTrader 5

implicit conversion from 'string' to 'number' error - what have I missed

To add comments, please log in or register
Robert Browne
Robert Browne  

Hi all


I am running the below code in an EA, the idea is to copy the pattern created inside the bot as a comment on my order. But I get the above error. What have I done wrong? 


//Specification Engine Rule 1
   if(currentboxhigh>prev1high && currentboxlow<prev1low) CurrentBoxType=1001;
   if(currentboxhigh<prev1high && currentboxlow>prev1low) CurrentBoxType=1010;
   if(currentboxhigh>prev1high && currentboxlow>=prev1low && currentboxlow<=prev1high) CurrentBoxType=1011;
   if(currentboxhigh<=prev1high && currentboxhigh>=prev1low && currentboxlow<prev1low) CurrentBoxType=1100;
   if(currentboxlow>prev1high) CurrentBoxType=1101;
   if(currentboxhigh<prev1low) CurrentBoxType=1111;

//Specification Engine Rule 2
   if(prev1high>prev2high && prev1low<prev2low) Prev1BoxType=1001;
   if(prev1high<prev2high && prev1low>prev2low) Prev1BoxType=1010;
   if(prev1high>prev2high && prev1low>=prev2low && prev1low<=prev2high) Prev1BoxType=1011;
   if(prev1high<=prev2high && prev1high>=prev2low && prev1low<prev2low) Prev1BoxType=1100;
   if(prev1low>prev2high) Prev1BoxType=1101;
   if(prev1high<prev2low) Prev1BoxType=1111;

//Specification Engine Rule 3
   if(prev2high>prev3high && prev2low<prev3low) Prev2BoxType=1001;
   if(prev2high<prev3high && prev2low>prev3low) Prev2BoxType=1010;
   if(prev2high>prev3high && prev2low>=prev3low && prev2low<=prev3high) Prev2BoxType=1011;
   if(prev2high<=prev3high && prev2high>=prev3low && prev2low<prev3low) Prev2BoxType=1100;
   if(prev2low>prev3high) Prev2BoxType=1101;
   if(prev2high<prev3low) Prev2BoxType=1111;

//Assign Box Pattern
   string cbt = IntegerToString(CurrentBoxType,4,' ');
   string p1t = IntegerToString(Prev1BoxType,4,' ');
   string p2t = IntegerToString(Prev2BoxType,4,' ');

   Print("Current box pattern "+CurrentBoxPattern);

   if(CurrentBoxPattern=="1100.1101.1011") NewTradeBox110Formed=true;

//  Look For Active Trade Box              |
void LookForActiveTradeBox(int pattern)
   double fakey = iClose(Symbol(),0,1);
   double price = Bid;

         GoLongIntoMarket(currentboxhigh,currentboxlow,110,"1100.1101.1011 Long");// Set string text for order comment
      if(fakey<currentboxlow) NewTradeBox110Formed=false;
//|   Set first order to go long into market                         |
void GoLongIntoMarket(double high,double low,int Magic_No,string comment)
   double lot            = 0.01;
   double volatility     = high-low;
   double n_value        = (volatility/Point)*TickValue;
   double risk           = AccBal*(Risk / 100);
   double tradevolume    = risk /n_value;

   if(tradevolume>lot) lot=tradevolume;

   double price          = Ask;
   double StopLoss       = Ask-volatility;
   double TakeProfit     = Ask+volatility;

   int OpenLong=OrderSend(Symbol(),OP_BUY,lot,price,Slippage,StopLoss,TakeProfit,NULL,Magic_No,comment,Blue);// returns implicit conversion from 'string' to number'
Fernando Carreiro
Fernando Carreiro  

RULE #1 - When in doubt always check the documentation!

Your "comment" is in the wrong place. It should be the 8th parameter (just after "takeprofit") and not the 10th as you have it, which is the parameter "expiration" (datetime); hence the error.

int OpenLong=OrderSend(Symbol(),OP_BUY,lot,price,Slippage,StopLoss,TakeProfit,NULL,Magic_No,comment,Blue);// returns implicit conversion from 'string' to number'

int OpenLong=OrderSend(Symbol(),OP_BUY,lot,price,Slippage,StopLoss,TakeProfit,comment,Magic_No,0,Blue);   // now it is in the correct position


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
Robert Browne
Robert Browne  
Thank you once again for helping out. 
To add comments, please log in or register