ObjectCreate() problems

 

Hi I'm new to Mql4 and I have problems with ObjectCreate() function.

I want to create script that gonna show me some events on the chart via drawing vertical lines. I came up with that

#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict



 long Current_Chart_ID = ChartID();


void OnStart()
  {

     for (int i=0;i<=Bars-3;i++)
      {
         double Price=High[i];
         datetime CurrentTime = iTime(NULL,0,i);
         string Name = IntegerToString(i);
         
            if (High[i]<High[i+1]&&High[i+1]<High[i+2]&&Low[i]>Low[i+1]&&Low[i+1]>Low[i+2])
            {
            ObjectCreate(Current_Chart_ID,Name,OBJ_VLINE,CurrentTime,Price);
            Print(Name);
            
            }
      
      }
      
     
  }

 But this doesn't draw any line.

So how can I have line on every bar that has been met the criteria in the if operator ?

 
 ObjectCreate(Current_Chart_ID,Name,OBJ_VLINE,0,CurrentTime,Price);

.

 
Cheers! I've fixed and works great!
 
string Name = IntegerToString(i);
:
ObjectCreate(Current_Chart_ID,Name,OBJ_VLINE,CurrentTime,Price);
  1. Do not use a bar index in a obtect name. The moment a new bar forms you're going to try to create another object with the same name. Use the bar's time, which is unique.
  2. After the first tick, you're going to try to create the same object again. How to do your lookbacks correctly.