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

 
Alexey Viktorov:

ctrl+tab and ctrl+shift+tab won't save the father of russian democracy?

it switches randomly, but I want it in order

it's more convenient, faster and allows you to hide the chart panel

 
Artyom Trishkin:

Thank you.

 
Трейдер Внатуре:

it switches randomly, but I want it in order

it's more convenient, faster and allows you to hide the chart panel

It should switch in the order in which the charts were opened. But if you then shuffle them randomly by dragging with the mouse, then and ...

 

Gentlemen, please help with the algorithm. It's summer, my head is not working at all. The task is to calculate the total volume to be opened with the condition of increasing the trading volume.

You are given:

b - base lot (volume of first order).

m - multiplier or coefficient of volume increase. For example, the volume of the second order = b*m. Volume of the third order = b*m*m.

t is the total amount of orders to be opened.


Thus, for example, the volume of each subsequent order is calculated by the formula

v=b*(m^(i-1)), where i is the ordinal number of this order, i.e. if this is the second order in the series, v=b*m, if the third is b*m^2.

So now the task is to derive a formula for the total volume of all orders to be opened (t).

 
leonerd:

v=b*(m^(i-1)), where i is the order number of this order, i.e. if it is the second order in the series then v=b*m, if it is the third - b*m^2.

So, the task now is to derive a formula for the total volume of all orders to be opened (t).

If the formula is correct, you are all set, in the loop v +=b*(m^(i-1)) , preliminarily zero out v=0.0 or if you want to get the amount in t, then t=0.0 ; in the loop t +=v;

 
Igor Makanu:

if the formula is correct, you are all set, in the loop v +=b*(m^(i-1)) , pre zero v=0.0 or if in t you want to get the sum, t=0.0 ; in the loop t +=v;

Yeah, I didn't think about the loop... But that's how I got it experimentally, I think:

vol_total=b*m^t-b


b(m^t-1)

 
leonerd:

Yeah, I hadn't thought about the cycle... But that's how I got it from experience:

b(m^t-1)

then just check your both formulas in the loop - they should be the same ;)

 
Igor Makanu:

then just check your both formulas in the loop - they should be the same ;)

OK, it's really more reliable with a cycle.

Could you please tell me if there is some ready-made class for determining total margin including hedging.

For example, i have calculated order volumes using martingale. They are differently directed. I have their prices too. I now need to estimate the total margin to be reserved for these orders. By orders in this case I mean open market orders activated.

 
leonerd:

OK, it really is more reliable with a cycle.

Please tell me if there is any ready-made class for determining the total margin including hedging.

For example I have calculated order volumes using martingale. They are differently directed. I have their prices too. I now need to estimate the total margin to be reserved for these orders. In this case, by orders I mean open market orders activated.

I do not do much writing for MT5, I did not understand the margin, it should be in the articles about preparing Expert Advisors for Market.

i looked at my handhelds for MT4, this is roughly how the margin is calculated:

bool checkmargin(double lot,int ordertype)
  {
   double m=NormalizeDouble(AccountFreeMargin()-AccountFreeMarginCheck(_Symbol,ordertype,lot),2);
   bool result = AccountBalance()-m>0 ? true : false;
   return(result);
  }
 
Igor Makanu:

I do not write much in MT5, I do not understand margins, somewhere in the articles on the preparation of experts for the Market should be exact

I have looked at my hand for MT4, this is how the margin is calculated:

Thanks, I need it for MT4 and MT5. But you don't take into account differently directed orders and Margin hedge coefficient here.

There are several orders order1,..., orderN all of which are market (will be) Buy or Sell, directions are known: dir1,...,dirN. The volumes are also vol1,...,volN. Also open_price1,...,open_priceN. The task is to calculate the total margin size. But the orders have not been opened yet. This is the complexity, as I understand that it will be problematic for all cross rates, because even though the opening price of the order at the cross rate is known, we need the exchange rate of the pair for its conversion into the deposit currency, and we cannot know it beforehand.

Reason: