Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 199

 
STARIJ:
Read your comment: it turns out that if one of the last three orders closes with a profit, the trade will stop!

Thanks for the tip

OPEN THE NEW ORDER I gave just for the sake of example. I am not trading yet.

I just don't understand how to code this condition .

If 3 - 4 - 5 ..... last orders have closed at STOP

I HAVE NO IDEA WHAT TO DO.

 
Victor Nikolaev:


The differences are minimal. One of the variables is boolean.

The output will say true or false

Ugh, I can't figure out how to add variables - i.e. let's say I have 4 boolean variables and need to go through them?

//+------------------------------------------------------------------+
//|                                                       Decode.mq4 |
//|                                            Copyright 2017, Vinin |
//|                                             http://vinin.ucoz.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Vinin"
#property link      "http://vinin.ucoz.ru"
#property version   "1.00"
#property strict
#property script_show_inputs
//--- input parameters
input int N=15;  //0..162
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   for(int n=0;n<N;n++)
     {
      int tmp=n;
      bool a= (bool) MathMod(tmp,2);
      bool b= (bool) MathMod(tmp,3);
      bool c= (bool) MathMod(tmp,4);
      bool d= (bool) MathMod(tmp,5);

      Print("N=",n,"; A=",a,"; B=",b,"; C=",c,"; D=",d);
     }

  }

I understand the essence of the case - should be a remainder less or more than zero after division - but I can not figure out how to achieve this :(

 
ANDREY:

Thanks for the tip

OPEN THE NEW ORDER I gave just for the sake of example. I am not trading yet.

I just don't understand how to code this condition .

If 3 - 4 - 5 ..... last orders have closed at STOP

I JUST NEED TO TAKE SOME ACTION.

Before we take any action, we should first look at 3 to 4 to 5 positions that were closed in a row. If everything is on stop, then take some action. Elementary, Watson...
 
ANDREY: It is necessary that not only last but also penultimate and penultimate orders have been closed on stop

and only then open another order

The script attached - I checked it, it works, the result is attached

//+-------------------------------------------------------+
//| Подсчет убыточных ордеров                 PROBA_MA.mq4|
//+-------------------------------------------------------+
#property strict
130
void OnStart()
{
  int Счет=0, Номер=OrdersHistoryTotal()-1;

  for( ; Номер>=0; Номер--)
  {
    if(!OrderSelect(Номер, SELECT_BY_POS, MODE_HISTORY)) continue;
    Alert(Номер, "  Тикет = ", OrderTicket(),"  T =",OrderOpenTime(), "  Профит = ", OrderProfit());
    if(OrderProfit()>=0) break;
    Счет++;
    if(Счет==3)
    {
      Alert("Вот тут и открываем новый ордер");
      return;
    }
  }
  Alert("Подряд идущих убыточных ордеров слишком мало");
}

That's all history


And this is right click on history and chose period till May 3

 
STARIJ:

Attached is the script - tested it, it works, the result is attached

That's the whole story.


And this is right-clicking on the history and selecting the period up to May 3

It's a stop. And it's not reliable. You have to do it independently of the sorting.
 

I'm sorry to bother you, I will answer my question again.

I think it's time to look at the chart, I'm not a big expert on mql4.

I may have asked a question in the wrong branch.

 
STARIJ:

Attached is the script - tested it, it works, the result is attached

That's the whole story.


And this is right-clicking on the history and selecting the period up to May 3

Thank you very much for all your help.
 
Artyom Trishkin So it's a stop. And it's not reliable. It should be done regardless of sorting.

Artem! In the lower right corner of the terminal is the indicator for exchanges with the server - kilobytes received and sent. The indicator showed 2318. Right clicked on the history and selected Today (and today is Sunday). The history was emptied. The script displays that there are no orders in the history. I right clicked on the history and selected All History. The indicator came to life with 518 kilobytes added to it. So when you set the filter to a LARGE period the orders are downloaded from the server. If you set a smaller period, they are deleted. Therefore, you'd better set Last Week, Last 3 Days or Today to speed up your work (less orders to be processed). This can be easily checked with the help of script which has Alert(OrdersHistoryTotal());

About sorting. If you click on the column headers in the history, you can sort the history visually by descending or ascending of any column. However orders are always selected using the OrderSelect(Number, SELECT_BY_POS, MODE_HISTORY) function, starting from the beginning of the SELECTED interval of the history. And in the history, the orders are ordered by the time they were sent to the server, which is the most natural. If the number = 0, then this is the oldest order of the SELECTED interval of history. If OrdersHistoryTotal()-1, it's the most recent order of the chosen interval of history. I've checked this many times. And it's unlikely it will ever be changed.

 
STARIJ:

Artem! In the bottom right corner of the terminal is an indicator of exchange with the server - the received and sent kilobytes. On the indicator was 2318. Right clicked on history and selected Today (and today is Sunday). The history is empty. The script displays that there are no orders in the history. I right clicked on the history and selected All History. The indicator came to life with 518 kilobytes added to it. So when you set the filter to a LARGE period the orders are downloaded from the server. If you set a smaller period, they are deleted. Therefore, you'd better set Last Week, Last 3 Days or Today to speed up your work (less orders to be processed). This can be easily checked with the help of script with Alert(OrdersHistoryTotal());

About sorting. If you click on the column headers in the history, you can sort the history visually by descending or ascending of any column. However orders are always selected using the OrderSelect(Number, SELECT_BY_POS, MODE_HISTORY) function, starting from the beginning of the SELECTED interval of the history. And in the history, the orders are ordered by the time they were sent to the server, which is the most natural. If the number = 0, then this is the oldest order of the SELECTED interval of history. If OrdersHistoryTotal()-1, it's the most recent order of the chosen interval of history. I've checked this many times. And it is unlikely that this will ever be changed.

You are so new here that you don't know everything as it was. It's been a rule of threescore years that a time-based search is the only reliable way of identifying the last/first or consecutive positions. You're working with money. Okay, if only with your own, but with someone else's, too. Even indirectly with your program.

And what you're telling me is no secret or revelation - everyone has known about it for years ;)

And what I was saying - you still don't get it...

 
Artyom Trishkin:

You are so new here that you don't know everything as it was. It's been a rule of thumb for three hundred years that a time-based search is the only reliable way of identifying the last/first or consecutive positions. You're working with money. Okay, if only with your own, but with someone else's, too. Even indirectly with your program.

And what you're telling me is not a secret or a revelation - everyone has known about it for years ;)

And what I was talking about - you still don't get it...

Artem, either it's unobtrusive trolling or you don't know what you are writing about!!!

In your last post you talked about sorting. Explained to you that there is no dependence on sorting.

I have seen and participated in one of the discussions about the selection of orders by time. The conclusion was that orders are now sorted in the order database by the time they are sent to the server. But THEORETALLY there is a fear that the developers may change this. That was the end of that discussion. As a database specialist I assure you that this fear is unfounded, a change is out of the question. You can refer the issue to the developers. If I write something, I know what I write. It's the 50th anniversary of programming. If you notice in my posts some mess from your point of view - write to me in person. I will explain, and your doubts will dispel. But here bicker unlikely to be appropriate. I wrote the man a script - he said thank you. Isn't it good?

About the other day. I just changed my username, you can guess what it was by style. Or check your IP, you probably have access... Please leave it unanswered.

Reason: