Estimating margin requirements in MQL5 - page 5

 
Petros Shatakhtsyan:

I advise you to read carefully what this function is for:


margin

[out] Variable which will be used to record the required margin if this function is executed successfully. The calculation is done as if there were no pending orders and open positions in the current account.

The value of margin depends on many factors and may change as the market environment changes.

Here's another question: how do you propose to calculate margin for pending orders, assuming that the pending order may or may not work?

 
Vladimir Karputov:

And how do you propose to account for margin on pending orders, assuming that the pending order may or may not work?

Exactly. And not just any pending order. When there are open positions on the account, then we must ask ourselves: with what lot an order must be opened in order to keep the margin smaller than the Free Margin.

For this you must know not the leverage of the trading account, but precisely the current leverage of the symbol. And without real leverage it is impossible to determine the margin.

 

OK, theorists ...

Here's a snippet of code from a working program that's 100 years old.

)))

            if(Action=="BUY" && orBUY==0)
               {
                  if(OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1,ASK,Mgn)==true)
                     {
                        Lot=Acc_Bal*Risk/(Mgn*lvrg);
                        if(Lot<minLot)Lot=0;
                        if(Lot>maxLot)Lot=maxLot;
                        Lot=NormalizeDouble(Lot,ls);
                        if(Lot>=minLot)
                           {
                              if(OpenPositions(_Symbol, "BUY", Lot, Magik_Number, "xxx")==-1)
                                 {
                                    Fun_Error(GetLastError());
                                    return;
                                 }
                           }
                     }              
               }
            if(Action=="SELL" && orSELL==0)
               {
                  if(OrderCalcMargin(ORDER_TYPE_SELL,_Symbol,1,BID,Mgn)==true)
                     {
                        Lot=Acc_Bal*Risk/(Mgn*lvrg);
                        if(Lot<minLot)Lot=0;
                        if(Lot>maxLot)Lot=maxLot;
                        Lot=NormalizeDouble(Lot,ls);
                        if(Lot>=minLot)
                           {              
                              if(OpenPositions(_Symbol, "SELL", Lot, Magik_Number, "xxx")==-1)
                                 {
                                    Fun_Error(GetLastError());
                                    return;
                                 }                              
                           }
                     }           
               }

Well, you've got to, you've got to, you've got to!

I forgot already...

SAR, make a switch, handwrite a shoulder for each character and let the program know it.

Don't bother where the problem is solved in a nutshell, write the code and go over it.

// If you can't count your money, somebody else will do it for you. ( © new-rena )

Good luck to you!

Goodbye

 
Renat Akhtyamov:

OK, theorists ...

Here's a snippet of code from a working program that's 100 years old.


You've got to, you've got to, you've got to!

I forgot already...

SAR, make a switch, handwrite a shoulder for each character and let the program know it.

Don't bother where the problem is solved like a cakewalk, write the code and go over it.

// If you can't count your money, somebody else will count it for you. ( © new-rena )

Good luck to you!

Goodbye

An addition to the above:

And don't forget to rewrite this list periodically. Not every hour, but only when the broker changes these values. ))))))

 
Alexey Viktorov:

Addendum to the above:

And do not forget to periodically rewrite this list. Not every hour, but only when your broker changes these values. ))))))

In such trading conditions, it is better to calculate all lots to the minimum leverage so as not to run into a sudden shortage of funds at the most inopportune time.

In this case 1k2

)))

I have a minimum of 1k100

My leverage is at least 1k100 and I've never had a threat of it going down.

)))

 
Renat Akhtyamov:

OK, theorists...


It's not just theory, it's practice.

You write an illiterate program and show everyone your "masterpieces" and talk nonsense.

If you have open positions, your program will not work correctly.

 
Petros Shatakhtsyan:

It's not just theory, it's practice.

You write an illiterate programme and show everyone your "masterpieces" and talk nonsense.

If you have open positions, your program will not work correctly.

Listen, read it carefully.

if(Action=="BUY" && orBUY==0)

I'll be writing you three letters in a word soon...

 
Renat Akhtyamov:

Listen, read it carefully.

if(Action=="BUY" && orBUY==0)

I will soon be writing you three letters in the word...

Is this a threat from a street kid?

I advise you to calm down and be quiet, or I will write the worst reviews in discussions of your products showing all the defects of your programs and no one will buy them).

 
Petros Shatakhtsyan:

Is this a threat from a street kid?

I advise you to calm down and be quiet, or I will write the worst reviews in discussions of your products, showing all the defects of your programs and no one will buy them).

that's up to you, i'm not threatening.

I just showed you what you can not see for yourself.

that's it

)

 
Renat Akhtyamov:

In such trading conditions it is better to calculate all lots to the minimum leverage so as not to run into a sudden shortage of funds at the most inopportune times.

In this case 1k2

)))

I have a minimum of 1k100

I've got a minimum of 1q100, so far they haven't threatened to cut my losses.

)))

Renat, on the gate "Buchenwald" was written jedem das Seine

Don't impose your opinion on others. Someone may need to load their deposit to the max and that decision depends on the parameter being discussed here.

Reason: