Questions from Beginners MQL5 MT5 MetaTrader 5 - page 65

 

Here's the expert himself - cleaned up the unnecessary stuff - there was a lot of bashing :)

Files:
 

How do I close an order?

I opened it like this:

mrequest.action = TRADE_ACTION_DEAL; // immediate execution

mrequest.price = NormalizeDouble(Ask,_Digits); // last Ask price

mrequest.sl = NormalizeDouble(Ask - 10000*_Point,_Digits); // Stop Loss

mrequest.tp = 0; // Take Profit

mrequest.symbol = _Symbol; // symbol

mrequest.volume = Lots; // number of lots to trade

mrequest.magic = 1; // Magic Number

mrequest.type = ORDER_TYPE_BUY; // buy order

mrequest.type_filling = ORDER_FILLING_FOK; // order type - all or nothing

mrequest.deviation=100; // slippage from the current price

OrderSend(mrequest,mresult);

The issue is that we have more than one open order, and we need to close a selective order...

 
Forex_Noob: How to close an order?

The question is that there is not one order open, but several, and we need to close selectively...

1. Insert the code correctly.

2. If several orders are opened in one direction, the result is one aggregate position.

3. To close an open position you should place oppositely directed orders, the aggregate volume of which is equal to the volume of the position to be closed.

4. If it is necessary to close only a part of a position, then it is necessary to expose oppositely directed orders with corresponding aggregate volume.

 
Yedelkin:

1. Insert the code correctly.

2. If several orders are opened in the same direction, the result is one aggregate position.

3. To close an open position you should place oppositely directed orders, the aggregate volume of which equals the volume of the position to be closed.

4. If only part of a position needs to be closed, then opposite orders should be placed with the corresponding aggregate volume.

ok. thanks. The only problem now is that positions are not always closed using a closing order...
 
Forex_Noob:
OK. Thanks. Only now another problem - the closing order does not always close the positions...
Look in the logbook - the results are recorded there.
 

Yedelkin,Reshetov,

Hello,

What is the easiest method to extract data from one indicator for several pairs?

string Currency1 = "GBPUSD";
string Currency2 = "EURUSD";
string Currency3 = "USDCHF";
string Currency4 = "USDJPY";
int ATRHandle;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
  for(int c=0;c<4;c++){
  SymbolSelect(Currency1,true);
  SymbolSelect(Currency2,true);
  SymbolSelect(Currency3,true);
  SymbolSelect(Currency4,true);
  }
  ATRHandle = iATR(Symbol(),PERIOD_M1,1);
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   IndicatorRelease(ATRHandle);
   Comment("");        
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//Например так,как показал
  }
//+------------------------------------------------------------------+
Thanks in advance.
 
mario065: What is the easiest method/method to get data from one indicator for several pairs?

Is this what you mean?

ATRHandle1 = iATR(Currency1,PERIOD_M1,1);
ATRHandle2 = iATR(Currency2,PERIOD_M1,1);
ATRHandle3 = iATR(Currency3,PERIOD_M1,1);
ATRHandle4 = iATR(Currency4,PERIOD_M1,1);
 
Yedelkin:

You mean this?

Hi,

Of course not.

If there's more than one turkey, you have to do it a hundred times for each one, as many pairs eat.

One handler to use all the pairs.

 
mario065: If there are several indicators, for each of them it's necessary to do as many times as the number of pairs eat. One handler to use all pairs.

So you want to have one handle, but the iATR indicator works with different characters?

From the description of the iATR indicator, you can see that it is designed to work with only one symbol. Therefore, to work with 4 characters, you need to run 4 copies of the iATR indicator. In its turn, the indicator handle is necessary to access the values of the specific indicator copy, and if you are running 4 indicator copies, you will have to store the appropriate handles somewhere.

If the question of using only one handle is principal, we will have to rewrite theiATR indicator sothat it works with several symbols at once, has the corresponding number of arrays of values, etc.Then it will be possible to use one handle

handle = myATR(Currency1,Currency2,Currency3,Currency4,PERIOD_M1,1);

and use it to address to this or that indicator buffer from myATR.

 

You can also write it down like this (schematically):

string Currency[4] = {"GBPUSD","EURUSD","USDCHF","USDJPY"}; //могу ошибиться в части правильности записи присвоения значений, но проверить легко по Справочнику
int ATRHandle[4];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   for(int c=0;c<4;c++) SymbolSelect(Currency[с],true);
   for(int c=0;c<4;c++) ATRHandle[с] = iATR(Currency[с],PERIOD_M1,1);
   return(0);
  }
Reason: