Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1228

 
Vladimir Karputov:

This is already correct then:

and if it fails to close, look in the log file. There could be a million reasons: redirect, trade ban, no prices, proximity of stop levels...

Thank you. Then it's like this) :


void CloseSellPositions()
  {
   for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of current positions
	{
          if(m_position.SelectByIndex(i))     // selects the position by index for further access to its properties
            {
             if(m_position.PositionType()==POSITION_TYPE_SELL)
                m_trade.PositionClose(m_position.Ticket()); // close a position by the specified symbol
            }
	}


  }

Just added parentheses. So that the newbies don't get confused.

 

Hello. I often use a string like this in a program to write logs to separate files:

StringConcatenate(M,"Начинаем проверять время работы модулей. i=",i); Log.write(M,__FILE__,__LINE__);

Can you tell me how to shorten this line? In fact, only the output string itself and the name of the variable I output to is changed here.

I tried to use define

#define  LOG(LogPerem,StrMes) StringConcatenate(M,StrMes,""); LogPerem.write(M,__FILE__,__LINE__);

but if I call it like this, it won't work anymore:

LOG(Log,"i=",i);
 
pivomoe:

Hello. I often use a string like this in a program to write logs to separate files:

Can you tell me how to shorten this line? In fact, only the output string itself and the name of the variable I output to is changed here.

I tried to use define

but calling it like this won't work anymore:

Do you have an understanding of the preprocessor?

Your

LOG("i=",i);
unfolds in
StringConcatenate(M,i,""); "i=".write(M,__FILE__,__LINE__);;

and that's what's fed to the compiler.

It's not even funny. Prescription one: read doku, preferably not local, local already implies some understanding of the terminology.

Try this, it might help: https://metanit.com/cpp/c/3.1.php

С | Препроцессор
  • metanit.com
Препроцессор является обязательным компонентом компилятора языка Си. Препроцессор обрабатывает исходный текст программы до ее непосредственной компиляции. Результатом работы препроцессора является полный текст программы, который передается на компиляцию в исполняемый файл. Для управления препроцессором применяются директивы, каждая из которых...
 
Vladimir Simakov:

It's not even funny. There is only one recipe: smoke the docks, preferably not local ones, because local ones already imply some understanding of the terminology.

Try this, in case it helps: https://metanit.com/cpp/c/3.1.php

What do you mean suddenly? Did it help you? Can you shorten my line with define?


I changed a line of code in my question

LOG("i=",i);

to .

LOG(Log,"i=",i);
 
pivomoe:

Hello. I often use a string like this in a program to write logs to separate files:

Can you tell me how to shorten this line? In fact, only the output string itself and the name of the variable I output to is changed here.

I tried to use define

but if I call it like this it won't work anymore:

I solved my problem by using sheets of functions like this:

template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7,typename T8,typename T9,typename T10>
void Write(T1 var1,T2 var2,T3 var3,T4 var4,T5 var5,T6 var6,T7 var7,T8 var8,T9 var9,T10 var10,string ffile,int line)
  {
   string Str;
   StringConcatenate(Str,var1,var2,var3,var4,var5,var6,var7,var8,var9,var10);
   write(Str,ffile,line);
  }; 

Now I call the following in my program

   Log.Write("Test1",__FILE__,__LINE__);  
 
pivomoe:

What do you mean all of a sudden? Did it help you? Can you shorten my line using define ?


I changed a line of code in my question

to

I can. LOG("Text"); I gave an example of how this is implemented - search for it somewhere on the forum.
 

Good afternoon, here is the problem: I have an EA that calls a custom indicator to display data, everything works fine in the strategy tester, but in real trading mode when I start the EA, the indicator is not displayed. In the log write custom indicator loaded successfully, it seems to rustle, sends text messages, but on the chart in the list of indicators it also is not. At the same time, if I drag it to the chart it picks up the data and everything is displayed normally. The indicator is located in the Indicators folder, in iCustom(NULL,0, "Indicator name",Count) function. I also tried adding #resource "\\Indicators\\\indicator name.ex5", iCustom(NULL,0,"::Indicators\\\indicator name.ex5",Count) but no difference. What's the reason?

 

is there a setting to remove the current values of the indicator buffers?


 
Comments not related to this topic have been moved to "Questions from MQL4 MT4 MetaTrader 4 beginners".
 

Dear Professionals, could you please advise if it is possible to get the values of RSI for a week timeframe in the code of advisor, but to calculate the values for the week, which does not start on Monday, but for example from Wednesday (that is the week from Wednesday to next Wednesday). As far as I know it cannot be done with iRSI?

So far I can only see a way to write the code for the calculation by myself. Is there a simpler solution or a ready-made solution?

Reason: