Questions from Beginners MQL4 MT4 MetaTrader 4 - page 120

 
Ihor Herasko:

Yeah, I can see that. And I see the answer to the question in the post belowhttps://www.mql5.com/ru/forum/160587/page115#comment_6521492. In other words, the problem is that the functionality is not divided into logical subtasks. You have lumped together: parsing orders, deciding on a trade action and executing a trade.

Such a task can be solved exactly in three stages:

  1. Gathering information about orders to be monitored by the program. This is just the loop of order evaluation, which you already have. The result of this cycle must be the array of orders.
  2. Calculation of trading signals. The calculation result is a command to open and/or close orders. It depends on the trading strategy. Previously, when there was no enumeration, I used codes: 0 - no signal, 1 - open Buy, -1 - open Sell, 2 - close Buy, -2 - close Sell.
  3. Execution of one trade operation. If there is a trade signal and one of the orders (point 1) is suitable for it, one trade operation is performed. After that, the entire algorithm is restarted starting from point 1. In some cases, we even exit OnTick in order to continue with the next tick.

Well, thank you. At least it's clear what to do. I'll try to figure out "how" to do it myself. Although I'm not familiar with arrays yet. Thanks again anyway.

 

Tell me how to get out of this !!!


for(int i=OrdersTotal()-1; i>=0; i--)

{

OrderSelect(i,SELECT_BY_POS);

if(OrderMagicNumber()==Magic && OrderType()==OP_SELL)

break;

The warning is: the return value of 'OrderSelect' must be checked

Howelse shouldthis'OrderSelect'valuebe checked?

if I do this: j=OrderSelect(); Is this correct?


 
Rewerpool:

Tell me how to get out of this !!!


for(int i=OrdersTotal()-1; i>=0; i--)

{

OrderSelect(i,SELECT_BY_POS);

if(OrderMagicNumber()==Magic && OrderType()==OP_SELL)

break;

The warning is: the return value of 'OrderSelect' must be checked

Howelse shouldthis'OrderSelect'valuebe checked?

if I do this: j=OrderSelect(); Is this correct?


 if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
 
Alekseu Fedotov:

It didn't work!(

((((

 
I have written to the file, everything is fine, but now how do I save data such as "eurusd" "1.2242" temporary data, etc.?
 
Mickey Moose:Wrote it to a file, everything is fine, but now how do I spar the data e.g. "eurusd" "1.2242" temporary data etc?

string s=FileReadString(F1); // Read the next line of the text file
StringSplit(s, "," , a); // Split comma-separated elements into array
datetime T1=StrToTime(a[4]); // Further, transformation proceeds ...
int ord=StrToInteger(a[8]);
double Price=StrToDouble(a[12]);

 
novichok2018:

Well, thank you. At least it's clearer what to do. I'll try to figure out the "how" myself. I'm not familiar with arrays yet, though. Anyway, thanks again.

Write at least one block and show me. They'll tell you further in this case.

 
Rewerpool:

Didn't work!(


Read it carefully, again.

 if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

All code will look like this

   for(int i=OrdersTotal()-1; i>=0; i--) 
     {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
       if(OrderMagicNumber()==Magic && OrderType()==OP_SELL)
          {
         break;
          }
        }
      }
 
Rewerpool:

It didn't work!(


So you haven't done anything. You wrote it above:

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

And you have it written without checking. Although it would look more readable that way:

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

@Ihor Herasko @Alekseu Fedotov

THANK YOU!!! IT WORKED THAT WAY!