Questions from Beginners MQL4 MT4 MetaTrader 4 - page 19

 
Vitalie Postolache:
Don't be like that ))))
the reason is not mql4
 
Vitalie Postolache:

That's not how it works much. The arguments of this function are 1) the string to be searched; 2) the character combination to be found; 3) the start of the search (by default, from the null character of the string according to point 1).

It returns the number of position in the string, at which the sought substring starts, or -1 if no substring is found.

So, it should be written like this:

if(StringFind(OrderComment(),"[tp]",0)>-1) {действие при нахождении признака закрытия по TP}

Thanks for the answer... So, theStringFind function with its parameters ( string_value, string match_substring, int start_pos=0 ) is written in common code in one line with

arguments corresponding to the data of the function parameters: string OrderComment(), string "[tp]", int 0 and if this expression (enclosed in curly brackets) is greater than -1 , thefollowing {bracketed} code is executed

if(StringFind(OrderComment(),"[tp]",0)>-1)

{

double OrderTakeProfit();

if(OrderSelect(12, SELECT_BY_POS)==true)

Print("Order #",OrderTicket()," profit: ", OrderTakeProfit());

else

Print("OrderSelect() returned error ",GetLastError());

bool PlaySound(

string payment // where "payment" isthe file name in the MT4 Sound folder

);

}

... Will this code work in MQL4? ...

 
bablusut:

Thanks for the reply ... It turns out, theStringFind function with its parameters ( string_value, string match_substring, int start_pos=0 ) is written in common code in one line with

arguments corresponding to the data of the function parameters: string OrderComment(), string "[tp]", int 0 and if this expression (enclosed in curly brackets) is greater than -1 , thefollowing {bracketed} code is executed

if(StringFind(OrderComment(),"[tp]",0)>-1)

{

double OrderTakeProfit();

if(OrderSelect(12, SELECT_BY_POS)==true)

Print("Order #",OrderTicket()," profit: ", OrderTakeProfit());

else

Print("OrderSelect() returned error ",GetLastError());

bool PlaySound(

string payment // where "payment" isthe file name in the MT4 Sound folder

);

}

... Will this code work in MQL4? ...

double OrderTakeProfit(); - the code should have an error when compiling.

As far as I understand it (I'm still studying it myself), OrderTakeProfit(); requests the order profit from the market. Thus, our Expert Advisor makes 2 requests for these few lines OrderTakeProfit(); looks like this line should be deleted (double OrderTakeProfit(); )

 
bablusut:

Thanks for the reply ... It turns out, theStringFind function with its parameters ( string_value, string match_substring, int start_pos=0 ) is written in common code in one line with

arguments corresponding to the data of the function parameters: string OrderComment(), string "[tp]", int 0 and if this expression (enclosed in curly brackets) is greater than -1 , thefollowing {bracketed} code is executed

if(StringFind(OrderComment(),"[tp]",0)>-1)

{

double OrderTakeProfit();

if(OrderSelect(12, SELECT_BY_POS)==true)

Print("Order #",OrderTicket()," profit: ", OrderTakeProfit());

else

Print("OrderSelect() returned error ",GetLastError());

bool PlaySound(

string payment // where "payment" isthe file name in the MT4 Sound folder

);

}

... Will this code work in MQL4? ...

This has already been mentioned:double OrderTakeProfit() - do not do that. This function is declared automatically and must not be re-announced. The compiler will generate an error, since standard functions do not need to be declared beforehand.

if(OrderSelect(12, SELECT_BY_POS)==true) - if we do so, then, at best, this will be another order, and not the one for which the comment has been processed above. The order must already be selected at the very beginning beforeif(StringFind(OrderComment(),"[tp]",0)>-1) and the loop counter must be used as an argument of the order number, not a constant, otherwise the 12th order will be checked every iteration.

 
Vitalie Postolache:

They have already said about it:double OrderTakeProfit() - don't do that. This function is declared automatically and must not be declared repeatedly. The compiler will generate an error, since standard functions don't need to be declared beforehand.

if(OrderSelect(12, SELECT_BY_POS)==true) - if we do that, then, at best, this will be another order, and not the one for which the comment has been processed above. The order must already have been selected at the very beginning, beforeif(StringFind(OrderComment(),"[tp]",0)>-1).

A1exPit:

double OrderTakeProfit(); - it is supposed to crash here when compiling.

As far as I understand it (I still understand it myself), OrderTakeProfit(); makes request for profit of the order from the market. Thus, our Expert Advisor makes 2 requests for these few lines OrderTakeProfit(); looks like this line should be deleted (double OrderTakeProfit(); )

Thanks for the comment - you turned out to be right.
 
"Vitalie Postolache:

They have already said about it:double OrderTakeProfit() - don't do that. This function is declared automatically and must not be declared repeatedly. The compiler will generate an error, since standard functions don't need to be declared beforehand.

if(OrderSelect(12, SELECT_BY_POS)==true) - if we do that, then, at best, this will be another order, and not the one for which the comment has been processed above. The order must already be selected in the beginning, beforeif(StringFind(OrderComment(),"[tp]",0)>-1) and we should set the loop counter as an argument of the order number, not a constant, otherwise we will see the 12th order every iteration.

Thanks for the reply ... The declaration of functiondouble OrderTakeProfit() is understandable, let's delete it.

"If we have only one loop counter in the previous code, in theOrdersHistoryTotalfunction, the loop for operator with the body(i=0;i<accTotal;i++) must beused as an argument of the order number, which means that we should replace the body of the operator with the bodyof the OrderSelect functionand we will get it

if(StringFind(OrderComment(),"[tp]",0)>-1)

{

if(OrderSelect(i=0;i<accTotal;i++)==true)

Print("Order #",OrderTicket()," profit: ", OrderTakeProfit());

else

Print("OrderSelect() returned error ",GetLastError());

bool PlaySound(

string payment // where"payment" isthe file name in the MT4 Sound folder

);

}

... Will this code work in MQL4? ...




 
bablusut:

Thanks for the reply ... The declaration of functiondouble OrderTakeProfit() is clear, let's delete it.

"Loop counter should be used as an argument of the order number" - in the previous code, we have only one loop counter, the loop for operatorin theOrdersHistoryTotalfunction with the body(i=0;i<accTotal;i++), it means that we should replace the body of the operator with the bodyof the OrderSelect functionand we will get it:

Again. In the work with the order, the first place must be OrderSelect. And then everything else.

If we are working in a loop around the order, the order of operations is as follows

1. Checking if(OrderSelect())

2. Checking if it is the right order, we usually check for the symbol and magic number, and then check the type if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic && OrderType()<2) - in this case only market orders placed for the current symbol and with the specified magic number are processed

Processing of other data like OrderComment(), OrderProfit(), etc.

It would look something like this

for(int i=OrdersHistoryTotal()-1; i>=0; i--) //перебираем историю торгов
{
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) //если ордер выбран то работаем дальше, иначе смысла нет
      {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic && OrderType()<2) //Если ордер тот, что нам нужен (эту проверку можно и опустить, если нужно обработать все ордера в истории)
         {
            if(StringFind(OrderComment(),"[tp]",0)>-1) //если найден признак закрытия профитом
            Print("Order #",OrderTicket()," profit: ", OrderTakeProfit());
            if(StringFind(OrderComment(),"[sl]",0)>-1) //если найден признак закрытия стоплосс
            Print("Order #",OrderTicket()," loss: "OrderTakeProfit());
         }
      }
}
 
How do I check if there is a signal value in one buffer or the other of the iCustom indicator?
 
Vitalie Postolache:
Once again. OrderSelect should be in the first place when working with an order. Then everything else.

They've decided by trial and error apparently, but it's expensive, I've been there myself...

My ears are ringing to be honest...

 
atik441:
how do you check if there is a signal value in the iCustom indicator buffer?
Follow the link, it is highlighted in your post.
Reason: