Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 562

 
Aleksandr Lishchenko:

I'm just learning!

Don't be too harsh! ;)

Do you learn how to download codes from the network, attach them to your account and earn money on affiliate? You don't have to learn it, it's pretty easy to do.

 
Vitaly Muzichenko:

Do you learn how to download codes from the net, link them to your account and earn money from your affiliate? You don't need to learn how to do it, it's easy enough.

I want to link my author's (commissioned) Expert Advisor to my account and place it on a dubious server, what's not to understand =)

I'm asking for your help, please tell me what I need to post.
 
Aleksandr Lishchenko:

I want to link my author's (commissioned) EA to an account and host it on a dodgy server, what's not to understand =)

Therefore, I'm asking for your help, please advise what you need to post.

You got the answer.

But you can also insert at the end ofOnInit

int OnInit()
  {
//---
  // Здесь уже есть код
//---
 // Проверка счёта
  if(AccountInfoInteger(ACCOUNT_LOGIN) != 123456 ) return(INIT_FAILED);
//---
 return(INIT_SUCCEEDED);
  }
 
Vitaly Muzichenko:

You have been told

But you can also insert at the end ofOnInit

Are you sure the person won't copy again without thinking?

if(AccountInfoInteger(ACCOUNT_LOGIN) != 123456 ) return(INIT_FAILED);
 
Ihor Herasko:

That's not quite right. The first thing to do is to calculate the nearest correct value (based on a given value), and then check the difference between the values. If it is zero (or no more than DBL_EPSILON), then everything is OK:

The VolumeCast function can be taken from here.

Thank you very much

 
Ihor Herasko:

That's not quite right. The first thing to do is to calculate the nearest correct value (based on a given value), and then check the difference between the values. If it is zero (or no more than DBL_EPSILON), then everything is OK:

The VolumeCast function can be taken from here.

Thanks. I would just refineVolumeCast a bit more, because if we set quite usual values, for example, lot volume equal to 0.01 and minimum lot equal to 0.01 while volume specified by the user is correct, like 0.03,VolumeCast will increase the volume to 0.04. I would do it this way

double VolumeCast(double volume, double volumeMin, double volumeMax, double volumeStep)
{
   if (volumeStep == 0.0)
      return volumeMin;
   if(volumeStep!=volumeMin)
      return (MathMin(MathFloor(volume / volumeStep) * volumeStep + volumeMin, volumeMax));
   else
      return (MathMin(MathFloor(volume / volumeStep) * volumeStep, volumeMax));
}
 
Aleksandr Teleguz:

Thank you. Only I would like to refineVolumeCast a bit more, because if we set quite usual values, for example lot volume equal to 0.01 and minimum lot equal to 0.01 and volume value set by user is correct, for example 0.03, thenVolumeCast will increase volume to 0.04. I would do so:

Yes, correct.

 
Can you tell me if it is possible to write a code that works on both MT5 and MT4?
 
Roman Sharanov:
Can you tell me if it is possible to write code that works on MT5 and MT4?

For example

#ifdef __MQL5__
        int totalPsitions = PositionsTotal();
#else
        int totalPsitions = OrdersTotal();
#endif
 
Konstantin Nikitin:

For example like this

and getting data from the indicators, the graph?