Warning: implicit conversion from 'string' to 'string'

 

Hello,

get a warning "implicit conversion from 'string' to 'string'"

string to number Ok

number to string OK


but "string to string" is complete new, i have no idea where is should start...

int GetHistoryCloseTime(){
  uint TotalNumberofDeals=HistoryDealsTotal();
  ulong ticket=0;
  string symbol=Symbol();
  int DealTime=0;
  string ClosingTime="";
   HistorySelect(0,TimeCurrent());
   for(uint i=0;i<TotalNumberofDeals;i++) {
   if((ticket=HistoryDealGetTicket(i))>0) {
   if(OrderGetString(ORDER_SYMBOL)==Symbol())
   ClosingTime=TimeToString(DealTime,TIME_DATE|TIME_MINUTES);
   }
  }
 warning-> return(ClosingTime);
 }

The idea ist to count how many orders on (Symbol) D1 are executed & closed (regadeless of profit)

Then i can compare it like

"snip"
if(GetHistoryCloseTime()>iTime(NULL,(ENUM_TIMEFRAMES)ENUM_ORDER_PROPERTY_INTEGER(PERIOD_D1),0))d1count++;
     }
   }
  return(d1count);
 }

Then i can stop open new orders, if d1count > maxd1trades for example


Maybe i'm complete wrong ( i'm sure :) )

The Original MQL4 code, which works perfect:

 int SymbolD1HistoryOrders(){
    int d1count=0;
    for(int w=OrdersHistoryTotal()-1;w>=0;w--){
     if(OrderSelect(w,SELECT_BY_POS,MODE_HISTORY))
     if(OrderSymbol()!=Symbol())continue;
     if(OrderType()==OP_BUY || OrderType()==OP_SELL)
     if(OrderCloseTime()>iTime(NULL,1440,0))d1count++;
     }
   return(d1count);
 }

Thanks for any suggestions, ideas, code snippets!

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Fernando Carreiro #:
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

Thank you!

 
ixbone: get a warning "implicit conversion from 'string' to 'string'"

To be honest, you are using so many wrong data-types and doing unnecessary type conversions that I really don't know where to begin.

For example, why are you using a "int" data-type if you plan to return a "datetime" data-type from your function?

int GetHistoryCloseTime() { ... }; // why an "int"?

Use a "datetime" instead, if you are plan to return a date and time ...

datetime GetHistoryCloseTime() { ... }; // use a "datetime" if you are going to return a date and time

Same goes for the variable that will hold the deal's time ...

datetime DealTime;

And why convert it to string to then convert it back into a "datetime"? It's totally unnecessary and the reason for the warning!

ClosingTime=TimeToString(DealTime,TIME_DATE|TIME_MINUTES);

Also, there is nothing in your code that gets the deal's time or a position's closing time.

 
ixbone:

get a warning "implicit conversion from 'string' to 'string'"

Try replacing Symbol() with a variable of the string type in:

if(OrderGetString(ORDER_SYMBOL)==Symbol())

That's the only double "stringy" thingy that I can see, and they're both functions.

 
Change

int GetHistoryCloseTime()
to
string  GetHistoryCloseTime()

 
Fernando Carreiro #:

To be honest, you are using so many wrong data-types and doing unnecessary type conversions that I really don't know where to begin.

For example, why are you using a "int" data-type if you plan to return a "datetime" data-type from your function?

Use a "datetime" instead, if you are plan to return a date and time ...

Same goes for the variable that will hold the deal's time ...

And why convert it to string to then convert it back into a "datetime"? It's totally unnecessary and the reason for the warning!

Also, there is nothing in your code that gets the deal's time or a position's closing time.

Thanks Fernando, not your fault, its my ignorance...

May i request where is can find "positions closing time"? you mentioned, in documentation

and yes I'm familiar with C/Cobol/Pascal/Fortran/Assembler not with C++ Scripting like MQL5

and yes Migrating from MQL4 to MQL5 is a good basic start doc (https://www.mql5.com/en/articles/81) , but lacks on advanced informations, AFTER 14 years of release....(no information about MQL4:OrderCloseTime->MQL5 in this doc)

So, frustration level is very high, therfor i postboned migration of perfect working MT4 EA since several years....

Once again, not your fault! I'll keep trying searching for reasonable documentation or code examples for 14 additional days, if i cant find some, i'll postboned migration for 2 years again...and again....because lack of reliable information/documentation ist not my or your fault but fault of MetaQuotes Ltd.

Kind regards

Migrating from MQL4 to MQL5
Migrating from MQL4 to MQL5
  • www.mql5.com
This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.
 
Soewono Effendi #:
Change

to

thank you

warning has changed from "string to string" to "datetime to string"

 
Ryan L Johnson #:

Try replacing Symbol() with a variable of the string type in:

That's the only double "stringy" thingy that I can see, and they're both functions.

thank you, done, no change at all
 
ixbone #:

thank you

warning has changed from "string to string" to "datetime to string"

where ?

 
ixbone #: Migrating from MQL4 to MQL5 is a good basic start doc (https://www.mql5.com/en/articles/81) , but lacks on advanced informations, AFTER 14 years of release....(no information about MQL4:OrderCloseTime->MQL5 in this doc)

If you are transitioning from MT4 to MT5, you will find that the trading mechanism is completely different.

So, I suggest you start by first learning how to understand the MT5 trading mechanisms and how to use the MQL5 trade functions ...

Articles

Orders, Positions and Deals in MetaTrader 5

MetaQuotes, 2011.02.01 16:13

Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.


I also highly suggest you study the MQL5 programming for traders - Book on MQL5.com too.

MQL5 programming for traders - Book on MQL5.com
MQL5 programming for traders - Book on MQL5.com
  • www.mql5.com
Modern trading relies heavily on computer technology. Automation now extends beyond the boundaries of exchanges and brokerage offices, becoming...
This website uses cookies. Learn more about our Cookies Policy.