Questions from Beginners MQL5 MT5 MetaTrader 5 - page 492

 
Евгений:
Is there any way to check if the opening scripts work at the weekend?
No. Only Expert Advisors can be checked in the strategy tester at the weekend.
 
Karputov Vladimir:
Only the indicator handles all ticks in OnCalculate(). Without any skips.
Eh no. And it skips. But less than others. But it skips.
 
Victor Nikolaev:
Uh, no. And he misses. But less than others. But it skips.
The indicator can skip the tick only if the indicator uses resource-intensive calculations at each input in OnCalculate().
 
kashi_ann:

That's good, thank you.

Another question:

OrderSelect

Selects an order for further work with it. Returns true on successful completion of the function. Returns false if the function fails. You need to call theGetLastError() function to get information about the error.

TheOrderSelect(
ulong ticket// Ticket the order
);

Parameters

ticket

[The ticket of the order.

How is this ticket assigned? Where can I get it? Or how do I set it up?

In the help it says

OrderGetTicket

Returns the ticket of the corresponding order and automatically selects the order for further manipulation using functions. We have to look through all of the orders by index and get a ticket, if necessary. Although this function will also select the order itself. The ticket is set by the broker, and we can't change it.

ulong  OrderGetTicket( 
   int  index      // номер в списке ордеров 
   );
 

Hello all!

I have written a function, which should draw "non-trading time zone" on the chart every day.
But here is a problem - when I start it, the module OnInit, draws as it should be but when I trigger it in the module OnTimer for some unknown reason the variable date keeps values which were assigned in the module OnInit.

Question: Why?

int OnInit()

  {

    EventSetTimer(1);

    MqlDateTime date;

    TimeLocal(date); 

    offtimeCreate(date); // Рисуем на графике заполненный прямоугольник (не торговая зона) с 21:00 до 23:59 в день указанный в переменной date

    return(INIT_SUCCEEDED); 

  } 

 ...

void onTimer()

  {

    MqlDateTime date;

    TimeLocal(date);

    if (date.hour==9 && date.min==0 && date.sec==0)  offtimeCreate(date); // Каждое утро, в 9:00, рисуем новую "не торговую зону" для дня указанного в переменной date

  } 

...
 
INGFX:

Hello all!

I've written a function which should draw a "non-trading time zone" on a chart every day.
But there is a problem - when executed in module OnInit it draws the date as it should be but when executed in module OnTimer for some unknown reason the date variable keeps the values which were assigned in module OnInit.

Question: Why?

Forum on trading, automated trading systems and strategy testing

Bugs, bugs, questions

Karputov Vladimir, 2016.01.09 20:51

What makes you think that in the timer variable date is passed the value previously defined in OnInit()?

You need to look at your function that draws the zone.

Completed:

Correctly would be OnTimer, not onTimer.

 

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

INGFX, 2016.01.09 21:20

Because A) I see visually, the "time zone" is not drawn today from 21:00 to 23:59, but from yesterday 21:00 to today 23:59

B) If I open the properties of the graphical object (shaded rectangle - "time zone"), I see that the first variable has not changed, i.e. it has the same value as yesterday's 21:00

...
bool offtimeCreate(MqlDateTime &stm)
  {
    color clr=Black;
    datetime tm1,tm2;
    tm1 = StringToTime((string)stm.year+"."+(string)stm.mon+"."+(string)stm.day+" 21:00");
    tm2 = StringToTime((string)stm.year+"."+(string)stm.mon+"."+(string)stm.day+" 23:59");

    RectangleCreate(0,"offtime",0,tm1,0,tm2,200,clr); // chrart_id,object_name,sub_window,time1,price1,time2,price2,color

    return(true);
  }
...

 
Karputov Vladimir:
The correct answer is OnTimer, not onTimer
Yes, it's OnTimer, I made a mistake when I copied it here ... The code itself is correct.
 
INGFX:
Yes OnTimer, made a mistake when rewritten here ... the code itself is correct

You would have checked your code. Tired of stitching together your bits and pieces - so here, check code. In OnTimer substitute your local time and compare prints at initialization and in timer:

//+------------------------------------------------------------------+
//|                                                       TestEA.mq5 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1);
   MqlDateTime date;
   TimeLocal(date);
   offtimeCreate(date); // Рисуем на графике заполненный прямоугольник (не торговая зона) с 21:00 до 23:59 в день указанный в переменной date
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer()
  {
   MqlDateTime date;
   TimeLocal(date);
   if(date.hour==22 && date.min==33 && date.sec==00)
      offtimeCreate(date); // Каждое утро, в 9:00, рисуем новую "не торговую зону" для дня указанного в переменной date
  }
//+------------------------------------------------------------------+
/*void offtimeCreate(MqlDateTime &struct_date)
  {
   string text="";
   text=IntegerToString(struct_date.hour)+":"+
        IntegerToString(struct_date.min)+":"+
        IntegerToString(struct_date.sec);
   Comment(text);
//ChartRedraw();
  }*/
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool offtimeCreate(MqlDateTime &stm)
  {
   color clr=Black;
   datetime tm1,tm2;
   tm1 = StringToTime((string)stm.year+"."+(string)stm.mon+"."+(string)stm.day+" 21:00");
   tm2 = StringToTime((string)stm.year+"."+(string)stm.mon+"."+(string)stm.day+" 23:59");

   Print(tm1+"      "+tm2);
//RectangleCreate(0,"offtime",0,tm1,0,tm2,200,clr); // chrart_id,object_name,sub_window,time1,price1,time2,price2,color

   return(true);
  }
//+------------------------------------------------------------------+
 
Karputov Vladimir:

You would have checked your code.

Vladimir, thank you for your patience and help!
Really made a mistake in the code ...
I'll be more careful from now on.

Reason: