[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 149

 

Please advise a newbie, AccountBalance() - it shows the amount of funds in the balance, but I need to calculate my calculated balance (calc_balance),

This balance is simple, but I can't write it yet, there is a total amount of open and pending orders (Orderstotal), for example 3 orders, max risk per one open position is 2%,

in order to open another trade I need to calculate max. risk (2%) of calculated balance, i.e. the logic of the formula roughly would be: calc_balance=AccountBalance()-2%-2%-2%,

That is, a consistent subtraction - but how to write it in code has not yet succeeded, I hope for your help.

Thanks in advance!

 
Can you tell me how Funds (AccountEquity() ) and Collateral (AccountMargin() ) are separate for Buy and Sell positions?
 
T-G:
Can you tell me how Funds (AccountEquity() ) and Collateral (AccountMargin() ) are separate for Buy and Sell positions?
AccountEquity() is only possible for your account and AccountMargin() with your conditions see Kim's very "Useful Functions"!
 
Gentlemen, can someone advise an indicator or an Expert Advisor, exposing support and resistance levels on D1, without lags preferably)))
 
Top2n:
Gentlemen, can someone advise an indicator or Expert Advisor, exposing support and resistance levels on D1, without lags preferably)))
Searching for: DailyPivotPoints
 

Good afternoon all, I'm having a problem and I can't figure out what it is.


There are two functions given. If I call 1, then nothing works. The second case, everything works. Please advise what is the error?

Thanks in advance!

int OrderBuy(double pLots, string pComment, int pMagic, int pDatetime, color pColor)
{
   int ticket = 0;
   int err = 0;
   int c = 0;
   int NumberOfTries = 100;
   for (c = 0; c < NumberOfTries; c++) 
     {
         RefreshRates();
         ticket = OrderSend(Symbol(), OP_BUY, pLots, Ask, 0, Ask-0.0005, Ask+0.0005, pComment, pMagic, pDatetime, pColor);
         err = GetLastError();
         if (err == 0/* NO_ERROR */) break;
         if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break;
         Sleep(5000);
      }
      return(ticket);

}


int OrderSell(double pLots, string pComment, int pMagic, int pDatetime, color pColor)
{
   int ticket = 0;
   int err = 0;
   int c = 0;
   int NumberOfTries = 100;
   
   for (c = 0; c < NumberOfTries; c++) 
   {
         RefreshRates();
         ticket = OrderSend(Symbol(), OP_SELL, pLots, Bid, 0, Bid+0.0005, Bid-0.0005, pComment, pMagic, pDatetime, pColor);
         err = GetLastError();
         if (err == 0/* NO_ERROR */) break;
         if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break;
         Sleep(5000);
    }
    return(ticket);

}





//вызовы функций

ticket = OrderBuy(lot, "---"+count+" ---", MagicNumber, 0, HotPink);
         Print(ticket+":тикет");//здесь выдает -1
         if (ticket < 0) 
               {
                  Print("Error: ", GetLastError());//здесь выдает "0";
                  return (0);
               } 




ticket = OrderSell(lot, "---"+count+" ---", MagicNumber, 0, HotPink);
         Print(ticket+":тикет");
         if (ticket < 0) 
               {
                  Print("Error: ", GetLastError());
                  return (0);
               } 
 
If you want to keep within the terminal's calculations, the easiest way is to subtract from what you have what remains if you open an appropriate order:
double ld_MarginPosition = AccountFreeMargin() - AccountFreeMarginCheck();
 
arabon:

Good afternoon all, I'm having a problem and I can't figure out what it is.


There are two functions given. If I call 1, then nothing works. The second case, everything works. Please advise what is the error?

Thank you in advance!


Function GetLastError() which in OrderSell and OrderBuy in loop, resets value of error (see help on GetLastError ATTENTION), therefore

Print("Error: ", GetLastError());

Try to print it out directly in the loop, then you will see where the order doesn't open due to an error.

 

I made a simple indicator that "flips" the instrument. Sometimes, for perception it is easier to see a pair in reverse, and the eye gets "washed out" by looking at the same picture. I have never read from file (I've never even tried to work with file), I can display full-fledged chart, does anybody have any ideas.


Files:
converter.mq4  2 kb
 

Still haven't found it either by searching or amongst Kim's functions.

How to correctly calculate the margin for open orders separately?

I used to do it this way:

в цикле
if (OrderType() == OP_BUY ) {  
   MarginBuy += (OrderOpenPrice()*OrderLots()/AccountLeverage())*MarketInfo(Symbol(), MODE_LOTSIZE);
}
         
if (OrderType() == OP_SELL ) {  
   MarginSell += (OrderOpenPrice()*OrderLots()/AccountLeverage())*MarketInfo(Symbol(), MODE_LOTSIZE);
}

I got a different value than what the terminal shows

If you want to fit in the terminal's calculations, the easiest way is to subtract from what you have what remains if you open the corresponding order:
double ld_MarginPosition = AccountFreeMargin() - AccountFreeMarginCheck();


You can't just subtract it. I need a separate calculation for each direction.

Reason: