Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1503

 
Sergey Voytsekhovsky #:
Do Expert Advisors leave traces of their activity in Global Variables
I am not sure.

Start here - In the terminal, in the ribbon, in the Tools folder, there is a GlobalVariables item. Let's find it.

 
Sergey Voytsekhovsky #:

This is where you should start - In the terminal, in the ribbon, in the Tools folder, there is a GlobalVariables item. Let's find it.

It's empty.

 
Sergey Voytsekhovsky #:

This is where you should start - In the terminal, in the ribbon, in the Tools folder, there is a GlobalVariables item. Let's find it.

As I understand you, I am also an ignoramus myself. Sometimes I can't catch a phrase or logic, the simplest ones. And I am constantly asking and reading too. That's why I'm calling you back. You helped me here recently, just above - very much, thank you.

 
psihodelit #:
It's empty.

So we're not interrupting anything.

Open the code of the EA whose readings you are interested in. You wrote that the other advisor should perform some actions depending on the readings of the first one. That's where you should start.

In any convenient place for you, prepare an empty line and type GlobalVariableCheck(), then highlight and press F1. The page with information will open, it's not difficult there.

And the essence of the embodied idea - Create a Global variable in the translating Expert Advisor, and let the receiving one read from it, at certain readings the condition will be triggered, and further on according to the scenario.

 
Sergey Voytsekhovsky #:
prepare an empty line and type GlobalVariableCheck(),

Don't forget to delete it afterwards, it was just a quick way to the necessary help. Burn it after reading it.

 

Hello, if there is a formula (code) for the weighted average price of opening a position on a hedge account. Thank you.

I don't understand, what is the formula to close cases of opposite trades?

Pср = (Open Price 1 × Lot 1 + Open Price 2 × Lot 2 + ... + Open Price X × Lot X) / (Lot 1 + Lot 2 + ... + Lot X)

This one doesn't seem to work?

 
leonerd opening a position on a hedge account. Thank you.

I don't understand, what is the formula to close cases of opposite trades?

This one doesn't seem to work?

I don't remember where I copied it, but it works well.

   double NLb = 0, NLs = 0;

   long OT;
   int b = 0, s = 0;
   double PB = 0, PS = 0, OL = 0, LS = 0, LB = 0, OOP = 0;
   for(int i = 0; i < PositionsTotal(); i++)
     {
      if(_Symbol == PositionGetSymbol(i))
        {
         OL  = PositionGetDouble(POSITION_VOLUME);
         OOP = PositionGetDouble(POSITION_PRICE_OPEN);
         OT  = PositionGetInteger(POSITION_TYPE);
         if(OT == POSITION_TYPE_BUY)
           {
            PB += OOP * OL;
            LB += OL;
            b++;
           }
         if(OT == POSITION_TYPE_SELL)
           {
            PS += OOP * OL;
            LS += OL;
            s++;
           }
        }
     }
   if(LB != 0)
      NLb = PB / LB;
   if(LS != 0)
      NLs = PS / LS;

It's the same as what you have written, only separated by position directions.

Ithink that's what you need .

 
Aleksandr Slavskii #:

I can't remember where I copied it, but it works well.

It's the same as what you wrote, only separated by position directions.

Ithink that's what you need .

I don't understand if it is the same if you just take shorts with negative volume and sum the absolute values in the denominator?

You might want to add a division by 0 check at the end.

 
leonerd #:

I don't understand if it's the same if you just take the shorts with negative volume and sum the absolute values in the denominator?

The function calculates the average price separately for buy and separately for sell.

I don't quite understand what your task is. I don't understand this phrase: " to close cases of opposite trades".

leonerd #:

It would be good to add a check of division by 0 at the end.

There is a check.

 

Can you tell me how to round ask and bid prices in CSymbolInfo class to price step?


#include <Trade\SymbolInfo.mqh>

input string symbol   = "MTLR";
input int    spred    = 10;
CSymbolInfo C_info;

int OnInit()
  {   
  C_info.Name(symbol); 
  C_info.Digits();
  C_info.Point();
   return(0);
  }
  
void OnTick()
  {  
   C_info.RefreshRates();

   int    spread      = C_info.Spread();
   double ask         = C_info.Ask();
   double bid         = C_info.Bid();
   ulong vol          = C_info.Volume();

   if(spread>spred)
      { 
       string info    = symbol+" = "+ IntegerToString(spread) + " Ask: "  +
                        DoubleToString(ask)                   + " Bid: "  +
                        DoubleToString(bid)                   + " Объем=" +
                        IntegerToString(vol);
       Print(info);
      }  
  }
/* MTLR = 4 Ask: 278.80000000 Bid: 278.76000000 Объем=289 */
Reason: