Questions from Beginners MQL4 MT4 MetaTrader 4 - page 122

 
Mickey Moose: Finished what I wanted I can send it to you for review. It's great. But it's forbidden to post it here.

in person... I love leakers... I did it on purpose. When the demo increases the deposit 15 times in a day, then I'll drain it back. I want to have comparable results tomorrow.

 
STARIJ:
Requotes in the tester? That's the first I've heard of...

Here's the proof. Beginning:


and the end:

and the end:




"So put in the EA that if so, exit and on the next tick continue."This is in the code.

 
novichok2018:

Here's the proof. The beginning:


and the end:

and the end:




"So put in the EA that if so, exit and on the next tick continue." - This is in the code.

Well and write If(tester) if(January 25 or 26) return

 
STARIJ:

Well and write If(tester) if(January 25 or 26) return

I don't understand why. What, will it help to avoid a repeat of the failure? The main thing is that the positions do close, and if the reason for the fuzzy command execution is a tester failure, then everything is fine. To be sure that the cause of the other, probably have to wait for the repetition of the situation, when with an open Sell(BAY) will open BAY(SEL), and see how they will close.

 
novichok2018:

This is exactly what I need, or rather only forBuy and Sell. For my simple strategy, the most important thing is that open positions do not interfere with each other's closing conditions. Maybe we can do without arrays? I do not understand them: how to create them, how to address them - I'm in the dark. Maybe my situation will become clearer to you on the screenshot:

Everything seems to be simple and clear in the code, but it is the only case of confusion.

If we need to split the accounting for Sell and Buy orders, we will declare two arrays and two counters for each of them:

int g_nBuyOrdersCnt, g_nSellOrdersCnt;
OrderInfo  arrstBuyOrderInfo[MAX_ORDERS_CNT], arrstSellOrderInfo[MAX_ORDERS_CNT];

As a result, the data collection cycle will be as follows:

g_nBuyOrderCnt = 0;
g_nSellOrdersCnt = 0;
for (int i = OrdersTotal() - 1; i >= 0; --i)
{
   if (!OrderSelect(i, SELECT_BY_POS))
      continue;

   if (OrderSymbol() != Symbol())   // Если нужны ордера только по текущему символу, к графику которого прикреплен советник
      continue;

   if (OrderMagicNumber != i_nMagicNumber)  // Если имеется входной параметр советника i_nMagicNumber, в котором указан ID ордеров советника
      continue;

   if (OrderType() == OP_BUY)
      SaveOrderInfo(g_arrstBuyOrderInfo, g_nBuyOrdersCnt);
   if (OrderType() == OP_SELL)
      SaveOrderInfo(g_arrstSellOrderInfo, g_nSellOrdersCnt);
}

void SaveOrderInfo(OrderInfo &arrstOrderInfo[], int &nOrdersCnt)
{
   if (nOrderCnt >= MAX_ORDERS_CNT)
      return;

   arrstOrderInfo[nOrdersCnt].nTicket = OrderTicket();
   arrstOrderInfo[nOrdersCnt].nType = OrderType();
   arrstOrderInfo[nOrdersCnt].fOpenPrice = OrderOpenPrice();
   arrstOrderInfo[nOrdersCnt].fSL = OrderStopLoss();
   arrstOrderInfo[nOrdersCnt].fTP = OrderTakeProfit();

   ++nOrdersCnt;
}

Then we just need to do the following in the Expert Advisor to determine whether there is a Buy or Sell order:

if (g_nBuyOrdersCnt > 0)
{
   // Есть ордера Buy
}
 
novichok2018:

Can we do without arrays after all?

Arrays can only be dispensed with if no more than one order of each type is expected to exist at any one time. Then the array degenerates into a variable of the OrderInfo structure type (or an array with size 1).

But as I see in the figure above, this is not the case. You can have more than one order of each type at a time.
 
novichok2018:

Here's the proof. Start:

This shows that when an order is closed, it is not the market price. For example, Buy is closed at Ask, while Sell is closed at Bid. If you look at your code, this may well be the case, because there is no check for order type before the close operation.

 

Good evening again. Full gist of the question.

I am putting an EA (working) in the Market. MT4 platform. I can display a single file. A file of the Expert Advisor. It should pass the validity, but it cannot because it is an EA without indicators. They are in separate files. The Expert Advisor works with four indicators. They have to be somehow attached to the Expert Advisor. You have to specify the path, i.e., write them in the Expert Advisor. What? and Where? Please advise which form and how to do this.

From what I understand, we have to use the "Resources" . I do not know how to register it correctly in the Expert Advisor. Maybe you know some other solutions.

Thank you .

Here's what it says when it fails to pass validity

 2016.04.01 00:00:00 cannot open file 'MQL4\indicators\Heiken_Ashi_Smoothed1lime.ex4' [2] 2016.04.01 00:00:00 cannot open file 'MQL4\indicators\Heiken_Ashi_Smoothed1lime.ex4' [2]01 00:00:00 cannot open file 'MQL4\indicators\MA in Color_wAppliedPrice.ex4' [2] 2016.04.01 00:00:00 cannot open file 'MQL4\indicators\MA in Color_wAppliedPrice.ex4' [2] 2016.04.01 00:00:00 cannot open file 'MQL4\indicators\HA_Smooth.ex4' [2] 2016.04.01 00:00:00 cannot open file 'MQL4\indicators\HA_Smooth.ex4' [2] 2016.04.01 00:00:00 cannot open file 'MQL4\indicators\TrendLord.ex4' [2] 2016.04.01 00:00:00 cannot open file 'MQL4\indicators\TrendLord.ex4' [2] 2016.04.01 00:00:05 cannot open file 'MQL4\indicators\Heiken_Ashi_Smoothed1lime.ex4' [2] 2016.04.01 00:00:05 cannot open file 'MQL4\indicators\Heiken_Ashi_Smoothed1lime.ex4' [2] 2016.04.01 00:00:0504.01 00:00:05 cannot open file 'MQL4\indicators\MA in Color_wAppliedPrice.ex4' [2] 2016.04.01 00:00:05 cannot open file 'MQL4\indicators\MA in Color_wAppliedPrice.ex4' [2] 2016.04.0101 00:00:05 cannot open file 'MQL4\indicators\HA_Smooth.ex4' [2] 2016.04.01 00:00:05 cannot open file 'MQL4\indicators\HA_Smooth.ex4' [2] 2016.04.01 00:00:05 cannot open file 'MQL4\indicators\TrendLord.ex4' [2] 2016.04.0101 00:00:05 cannot open file 'MQL4\indicators\TrendLord.ex4' [2] 2016.04.01 00:00:10 cannot open file 'MQL4\indicators\Heiken_Ashi_Smoothed1lime.ex4' [2] 2016.04.01 00:00:10 cannot open file 'MQL4\indicators\Heiken_Ashi_Smoothed1lime.ex4' [2] 2016.04.01 00:00:10 cannot open file 'MQL4\indicators\MA in Color_wAppliedPrice.ex4' [2] 2016.04.01 00:00:10 cannot open file 'MQL4\indicators\MA in Color_wAppliedPrice.ex4' [2]

 
Ihor Herasko:


Thank you very much for your comprehensive and very clear answers.

 
Ihor Herasko:

If we need to split the accounting of orders into Buy and Sell, we declare two arrays and two counters for each of them:

As a result, the data collection cycle will be as follows:

Then we just need to do the following in the Expert Advisor to determine whether there is a Buy or Sell order:

Could you please explain this line of your code:OrderInfo arrstBuyOrderInfo[MAX_ORDERS_CNT], arrstSellOrderInfo[MAX_ORDERS_CNT]; Why doesOrderInfo have no brackets and no type specified? and all this is declared at global level?

And the determination of order availability is inserted into the function of position closing? Where? And maybe the function of closing positions with arrays should look somehow different? It is a bit complicated for me. Thank you.


I tried to use your example, but the compiler swears at me...

And it swears at the examples from the tutorial too.

Reason: