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

 
Artyom Trishkin :

I haven't looked into it - I can't tell you unfortunately.

I will explain. I hope it makes sense.

Here's the explanation:

I am trading EURUSD and AUDJPY in MT5. Both have margin booked as shown in the MT5 toolbar. I will share the image.

First trade on EURUSD:

I sold with lot = 1. Took margin = 235.31.

I am now trading on AUDJPY:

I sold at lot = 1. I took a margin call = 144.24.

And total margin shown in ToolBox = 379.55.

The toolbox, as you can see, shows the total margin used by EURUSD and AUDJPY symbols.

Now I come to my question.

I want to know what is the margin of the total margin used by EURUSD. I am not getting the calculations for this. I know that the answer should = 235.31

But with OrderCalcMargin () I get different answers. Sometimes the function returns 235.23, sometimes 235.01. But this is the wrong answer. I want to know how I can calculate the margin used for a particular symbol. In my example, tell me how I can calculate the margin used by EURSD or AUDJPY.

Note:

The answer OrderCalcMargin () sometimes gives the correct answer for EURUSD. But if I want to calculate the margin for AUDJPY, it is always different.

Now please let me know if I understand.

I have this question and have tried to explain it to everyone on the forum, but no one can understand. This is me trying again.

I'll try again if it still doesn't make sense.

@ Artyom Trishkin, let me know. I'm counting on you to give me a solution.

 
jaffer wilson:

I will explain. I hope it makes sense.

Here's the explanation:

I am trading EURUSD and AUDJPY in MT5. Both have margin booked as shown in the MT5 toolbar. I will share the image.

First trade on EURUSD:

I sold with lot = 1. Took margin = 235.31.

I am now trading on AUDJPY:

I sold at lot = 1. I took a margin call = 144.24.

And total margin shown in ToolBox = 379.55.

The toolbox, as you can see, shows the total margin used by EURUSD and AUDJPY symbols.

Now I come to my question.

I want to know what is the margin of the total margin used by EURUSD. I am not getting the calculations for this. I know that the answer should = 235.31

But with OrderCalcMargin () I get different answers. Sometimes the function returns 235.23, sometimes 235.01. But this is the wrong answer. I want to know how I can calculate the margin used for a particular symbol. In my example, tell me how I can calculate the margin used by EURSD or AUDJPY.

Note:

The answer OrderCalcMargin () sometimes gives the correct answer for EURUSD. But if I want to calculate the margin for AUDJPY, it is always different.

Now please let me know if I understand.

I have this question and have tried to explain it to everyone on the forum, but no one can understand. This is me trying again.

I'll try again if it still doesn't make sense.

@ Artyom Trishkin, let me know. I'm counting on you to give me a solution.

Very important values to calculate in your case:

  1. What currency the account is in
  2. What was the exchange rate at the time you opened the position

As an example, the AUDJPY and USDJPY are involved in the margin calculation. What was the AUDJPY exchange rate at the time you opened the position, no one will ever guess. You can only try to calculate via the current margin. This was mentioned in the thread I linked you to. But to be honest it doesn't say much about it, but there is something in the codes.

At each subsequent moment these rates change and hence you get different margin values. Calculate the ratio of the current margin to the opening price of the position and apply this coefficient in calculating the margin for the open position. You need to experiment. I do not remember the exact calculation algorithm.

But I don't think anyone will give you a ready-made solution.

 
Alexey Viktorov :

Very important values for the calculation in your case:

  1. What currency the account is denominated in
  2. What was the exchange rate at the time you opened the position

As an example, the AUDJPY margin calculation involves AUDUSD and USDJPY. What was the AUDJPY exchange rate at the time you opened the position, no one will ever guess. You can only try to calculate via the current margin. This was mentioned in the thread I linked you to. But to be honest it doesn't say much about it, but there is something in the codes.

At each subsequent moment these rates change and hence you get different margin values. Calculate the ratio of the current margin to the opening price of the position and apply this coefficient in calculating the margin for the open position. You need to experiment. I do not remember the exact calculation algorithm.

But I don't think anyone will give you a ready-made solution.

Yes, I understand it. But I see that the MT5 ToolBox calculates exactly without changing the margin. Then what logic does the MT5 ToolBox use? Could you shed some light on this please?

 

Question how to assign a value to different variables via arguments in a function. If there is one argument, it can be returned and assigned a value, but if there are 2, what should be done?

int x,x1,x2,x3=1,x4,x5;
void OnStart()
{
x=2;
F(x,x1,x2);
Print ("x1= ",x1," x2= ",x2);
x=5 ;
F(x,x4,x5);
Print ("x4= ",x4," x5= ",x5);
return;
}

int F(int ArgX, int ArgX1, int ArgX2)
{
ArgX1=ArgX + x3;
ArgX2=ArgX - x3;
return ArgX1;
}

//результат
2020.09.09 15:10:10.561 TestS EURUSD,H1: x4= 0 x5= 0
2020.09.09 15:10:10.561 TestS EURUSD,H1: x1= 0 x2= 0
Документация по MQL5: Основы языка / Операции и выражения / Операции присваивания
Документация по MQL5: Основы языка / Операции и выражения / Операции присваивания
  • www.mql5.com
Побитовые операции производятся только с целыми числами. При выполнении операции логический сдвиг представления y вправо/влево на x бит используются младшие 5 двоичных разрядов значения x, старшие разряды отбрасываются, то есть сдвиг производится на 0-31 бит.
 

Valery, maybe this will do:

void  F(int &ArgX, int &ArgX1, int &ArgX2)
 
Aleksei Stepanenko:

Valery, maybe this will do:

Right, links, appersand if I'm not mistaken.

2020.09.09 15:18:33.572 TestS EURUSD,H1: x4= 6x5= 4

2020.09.09 15:18:33.572 TestS EURUSD,H1: x1= 3x2= 1

Thank you)))


 
That's right! Transmission at the link.
 
Valeriy Yastremskiy:

Question how to assign a value to different variables via arguments in a function. If there is one argument, it can be returned and assigned a value, but if there are 2, what about this?

This is what?

void start()

Once upon a time, long, long ago. mammoths ate. And then they put it on. Is that what I think it is?

 
Artyom Trishkin:

What's that?

Once upon a time... mammoths used to eat. And then they put it on. Is that what I think it is?

Don't judge, I wrote the script by hand. And a strict check skips old functions. Of course, I don't write my script that way. Besides, there are constructors. )))))

Corrected)
 
Colleagues, good day to all. There are five robots with different magic symbols opening market positions at opening price of a new bar and they all have the same conditions for entry. Exits are different.
Sometimes I close all five positions manually.
And then, how with minimal effort to organize an algorithm for opening a new market position but not on the next bar - trade on M1, but on consecutive different, ie on 1 m1 opened the first who had time, on the second m1 opened from them the second who had time, etc. to 5.
I.e. I think the question boils down to the following, as an option, how to allocate a minute of market opening time for its subsequent comparison with Minutes () standard f-fi? And of course, if there is already a market position at this minute, then return ().