Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1091

 
LRA:

1. Try in MetaEditor: File --> Open shared data folder. You will see the path to the folder. This issue has been discussed many times, here is a link for example

2. Try it without include at first. When you will debug it, you will start to include it.

3. Insert your sources here either by using SRC button above, or by using Attach file button below.

Thank you very much.
 

Please advise how to draw a horizontal line at the opening price of the bar at 07:00.

I have written this code, but the line is not drawn for some reason. Where is the error?

extern string StartTime = "07:00";          //Начальное время для анализа, 00:00 EST
extern string AlTime = "18:55";          //Время для трейдинга
extern string EndTime   = "20:00";          //Время экспирации
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {       
   ObjectCreate(ChartID(),"CORDON",OBJ_HLINE,0,0,Ask);        //созд гор линию по цене Ask
   
   ObjectSetInteger(ChartID(),"CORDON",OBJPROP_COLOR,clrDarkBlue);  //цвет темно-сиий
      
   ObjectSetInteger(ChartID(),"CORDON",OBJPROP_WIDTH,1);  //толщина линии 1
      
   ObjectSetInteger(ChartID(),"CORDON",OBJPROP_STYLE,STYLE_SOLID);  //линия сплош
   
   int IndexOfBar = iBarShift(ChartID(),PERIOD_H1, StringToTime(StartTime), true); //Считаем индекс бара по заданному времени StartTime
   double StartPrice = Open[IndexOfBar];                    //Получаем цену по индексу
   
   ObjectMove(ChartID(),"CORDON", 0, 0, StartPrice);          // меняем распол линии   
   return(0);
   }
 
RichLux:

Please advise how to draw a horizontal line at the opening price of the bar at 07:00.

I have written this code, but the line is not drawn for some reason. Where is the error?

If you remove ObjectMove, the line is visible? Try Alert(StartPrice);
 
LRA:
If you remove ObjectMove, the line is visible? Try Alert(StartPrice);

If you remove ObjectMove, you cannot see the line, but ifyou write a numeric value instead of "IndexOfBar", for example, "double StartPrice = Open[5];" it draws the line at the opening price of the fifth bar.

Thanks for the idea with Alert - it shows "0" value.

By the way, the line also exists in the list of objects with the value 0.

 
RichLux:

Please advise how to draw a horizontal line at the opening price of the bar at 07:00.

I have written this code, but the line is not drawn for some reason. Where is the error?

You cannot draw and calculate in the inite, it is a gross error. The inite must finish its work as fast as possible.

The error here isint IndexOfBar = iBarShift(ChartID()_Symbol,PERIOD_H1, StringToTime(StartTime), true); //read the index of the bar by the given time StartTime

The time can be set directly in datetime format, no need to waste machine time on conversion, works like this:

#property strict
#property  show_inputs

extern datetime StartTime = D'07:00';          //Начальное время для анализа, 00:00 EST
extern datetime AlTime = D'18:55';          //Время для трейдинга
extern datetime EndTime   = D'20:00';          //Время экспирации
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
{       
   ObjectCreate(0,"CORDON",OBJ_HLINE,0,0,Ask);        //созд гор линию по цене Ask
   
   ObjectSetInteger(0,"CORDON",OBJPROP_COLOR,clrDarkBlue);  //цвет темно-сиий
      
   ObjectSetInteger(0,"CORDON",OBJPROP_WIDTH,1);  //толщина линии 1
      
   ObjectSetInteger(0,"CORDON",OBJPROP_STYLE,STYLE_SOLID);  //линия сплош
   
   int IndexOfBar = iBarShift(_Symbol,0, StartTime, false); //Считаем индекс бара по заданному времени StartTime
   double StartPrice = Open[IndexOfBar];                    //Получаем цену по индексу
   Print(IndexOfBar,", ",StartPrice);
   ObjectMove(0,"CORDON", 0, 0, StartPrice);          // меняем распол линии   
}
   
 
evillive:

You can't draw and calculate in the init, it's a gross mistake. The init should complete its work as quickly as possible.

The error here -int IndexOfBar = iBarShift(ChartID()_Symbol,PERIOD_H1, StringToTime(StartTime), true); //read the index of the bar by the specified time StartTime

The time can be set directly in datetime format, no need to waste machine time on conversion, works like this:

Thanks for the valuable tips for me.

And special thanks for raising my morale by finding the error. I'm starting to believe again that I can make friends with MQL4

 
RichLux: version of the code doesn't work. The line on the graph still doesn't appear...
// Вставил такой код в скрипт - линию рисует синюю на черном графике слабо видно
#property strict                                                       // -------- Возможно, Дело в этой строке
        
extern string StartTime = "07:00";          //Начальное время для анализа, 00:00 EST
extern string AlTime = "18:55";          //Время для трейдинга
extern string EndTime   = "20:00";          //Время экспирации
void OnStart()
{
   ObjectCreate("CORDON",OBJ_HLINE,0,0,Ask);    //созд гор линию по цене Ask   --- Для текущего графика ID пропускаем
   ObjectSetInteger(0,"CORDON",OBJPROP_COLOR,DarkBlue);  //цвет темно-сиий  --- 0 = текущий график   DarkBlue - то же самое
   ObjectSetInteger(0,"CORDON",OBJPROP_WIDTH,1);  //толщина линии 1
   ObjectSetInteger(0,"CORDON",OBJPROP_STYLE,STYLE_SOLID);  //линия сплош

   // Первый параметр нужен типа string, а функция ChartID возвращает long
   int IndexOfBar = iBarShift(NULL,PERIOD_H1, StringToTime(StartTime), true); //  --- NULL = текущий график  ЗДЕСЬ И БЫЛА ОШИБКА???
   double StartPrice = Open[IndexOfBar];                    //Получаем цену по индексу
   ObjectMove(ChartID(),"CORDON", 0, 0, StartPrice);          // меняем распол линии   
}
 
evillive:

You can't draw and calculate in the init, it's a gross mistake. The init should be completed as quickly as possible.


And if you take the calculations from the inite into a separate function and then insert this function into the inite, it won't be a gross error?

LRA:

It already works.

 
RichLux:

And if you take the calculations from the inite into a separate function, and then insert this function into the inite, it will not be a gross error?

If the code is executed too long, the inite will terminate forcibly and the code simply will not have time to be executed. The executed code, including calls of secondary functions, must be in the predefined functions of MQL - OnTick() for Expert Advisors, OnStart() for scripts, OnCalculate() for indicators.

The inite must contain the minimum of code, only those things that must be executed once, right before the start of the program. For example, initialization of global variables, arrays, indicator buffers.

 
Reinstalling the OS. How to restore after OS reinstallation MT4 to the state it was in before reinstallation.
Indicators, EAs, scripts; templates, profiles; accounts
Reason: