Questions from Beginners MQL5 MT5 MetaTrader 5 - page 424

 
Hello all! Could you please tell me how to select the last closed order in mql4 history? I am using OrderSelect(0,SELECT_BY_POS,MODE_HISTORY), which selects the first closed order.
 
Sergei Maksimenko:
Hello all! Could you please tell me how to select the last closed order in mql4 history? I am using OrderSelect(0,SELECT_BY_POS,MODE_HISTORY); it selects the first closed order, but how can I select the last one?
Instead of 0, you should use OrdersHistoryTotal()-1.
 
new-rena:

It is easier to track bar changes by bar time changes rather than by bar prices. At the end of the algorithm, we will remember the current bar time, and at the beginning we will compare it with the current time.

For example, for the M5 bar, the current time will be changed only at the beginning of the bar and every 5 minutes....

Testing of such programs is performed "by opening prices", which greatly speeds up the process of code debugging and optimization.

Thus, I will have to find out what TF it is now and do rounding if a bar doesn't appear in exactly 5 minutes... In my case, the code is very easy and not burdensome. Of course, the open price may not change, but you can check by the sum of two previous bars. In general, if you hadn't written about advantages of your solution, I would have understood it better if I had attached the code - I am not a programmer...
 
-Aleks-:
So I have to find out what TF it is now, do the rounding if the bar doesn't appear in exactly 5 minutes... In my case the code is very easy and not cumbersome. Of course the opening price may not change, but you can check by the sum of the past two bars. In general, if you hadn't written about advantages of your solution, I would have understood it better if I had attached the code - I am not a programmer...
Навигатор по форуму и ответы на часто задаваемые вопросы. Настоятельно Рекомендуется к Прочтению! - MQL4 форум
  • www.mql5.com
Навигатор по форуму и ответы на часто задаваемые вопросы. Настоятельно Рекомендуется к Прочтению! - MQL4 форум
 
Artyom Trishkin:

Thank you - easier than I pictured in my mind after reading the comment.

 

Good afternoon!

Who can tell me how to make a drop-down menu in expert settings?

Like the one in the picture. Thanks.


 
Sergei Konoplev:

Good afternoon!

Who can tell me how to make a drop-down menu in expert settings?

Like the one in the picture. Thanks.


Need to add my listing to the code.
 
-Aleks-:
So I have to find out what TF it is now, do the rounding if the bar doesn't appear in exactly 5 minutes... In my case the code is very easy and not cumbersome. Of course the opening price may not change, but you can check by the sum of the past two bars. In general, if you hadn't written about advantages of your solution, I would have understood it better if I had attached the code - I am not a programmer...
//код в фигурных скобках выполнится только один раз, на открытии каждого нового бара М5

datetime prevTime;

if(prevTime!=iTime(Symbol(),PERIOD_M5,0))
   {
     ...
   }
prevTime=iTime(Symbol(),PERIOD_M5,0);
 

Where is the mistake?

void CheckValidStop4(string symbol,double price, double &sl) //функция на проверку близких стопов от цены и его исправление
{
    if(sl==0)
    return;
    
    double severs_min_stop = MarketInfo(symbol,MODE_STOPLEVEL)* MarketInfo(symbol,MODE_POINT);
    if(MathAbs(price - sl)<= severs_min_stop)
    {
        if(price>sl)
             sl = price - severs_min_stop;
       else  sl = sl + severs_min_stop;
       
        
    }
    sl = NormalizeDouble(sl,(int)MarketInfo(symbol,MODE_DIGITS));
}
 
Leanid Aladzyeu:

Where is the mistake?

Error code?
Reason: