Download MetaTrader 5
To add comments, please log in or register
Join MQL5 Cloud Network. Millions of traders are waiting for this!
FXNew89
8
FXNew89 2016.10.09 14:39 

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 ?

Keith Watford
Moderator
7953
Keith Watford 2016.10.09 21:21  
 ObjectCreate(Current_Chart_ID,Name,OBJ_VLINE,0,CurrentTime,Price);

.

FXNew89
8
FXNew89 2016.10.09 22:23  
Cheers! I've fixed and works great!
whroeder1
13623
whroeder1 2016.10.10 23:44  
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.
/
To add comments, please log in or register