How to execute script to draw horizontal lines on all charts

 

My script looks for a couple of trendlines with specific names and draws another line on top of it, which can then be seen by an alert function.

I am able to execute that script on the current chart, but I want this to do that on every chart. How do I do that?

#property copyright "Copyright 2018"
#property link      "http://www"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script to draw alert lines on Yest High/Low                                   |
//+------------------------------------------------------------------+
void OnStart()
{

   
color col = Black;
int style = 0;
int width = 1;
   


        // Iterate over objects on this chart
        for (int i=ObjectsTotal()-1;i>=0;i--) {
                string  sObjName        = ObjectName(i);
                double  dObjPrice;
//              int             iObjAlert;
//              int             iProximity;
//              string  sMessage;
                
                // Look for Yest High line from pivots
                if (sObjName == "[PIVOT] Y's High Line")
                {
                dObjPrice = ObjectGet(sObjName,OBJPROP_PRICE1);

         string linename = "Horizontal Line Yesterday High" + TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) + IntegerToString(rand());
         double  level=dObjPrice;

       ObjectCreate(linename,OBJ_HLINE,0,0,level);
       ObjectSet(linename,OBJPROP_COLOR,col);
       ObjectSet(linename,OBJPROP_STYLE,style);
       ObjectSet(linename,OBJPROP_WIDTH,width);
       ObjectSet(linename,OBJPROP_SELECTED,true);
       ObjectSet(linename,OBJPROP_BACK,true);  
       ObjectSetText(linename,"Alert_5",10,"Times New Roman",Green);

      }
                
                if (sObjName == "[PIVOT] Y's Low Line")
                {
                dObjPrice = ObjectGet(sObjName,OBJPROP_PRICE1);
         string linename = "Horizontal Line Yesterday Low" + TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) + IntegerToString(rand());
         double  level=dObjPrice;

       ObjectCreate(linename,OBJ_HLINE,0,0,level);
       ObjectSet(linename,OBJPROP_COLOR,col);
       ObjectSet(linename,OBJPROP_STYLE,style);
       ObjectSet(linename,OBJPROP_WIDTH,width);
       ObjectSet(linename,OBJPROP_SELECTED,true);
       ObjectSet(linename,OBJPROP_BACK,true);  
       ObjectSetText(linename,"Alert_5",10,"Times New Roman",Green);
                
                }                       

        }

//   }   
}
//+------------------------------------------------------------------+
 
darkcanvas: but I want this to do that on every chart. How do I do that?

Make it an indicator, and put it on every chart.

 
Loop over every chart (outer loop) then loop over every object on that chart (inner loop). 
 
whroeder1:

Make it an indicator, and put it on every chart.

Thanks,

I needed the lines to be drawn permanently, and shown on every time frame, so indicator was out.

I'm just doing it one chart at a time.

 

nicholi shen:
Loop over every chart (outer loop) then loop over every object on that chart (inner loop).


Yeah,

I tried that, but could not make it work.

It did it on 1 chart but refused to cycle through all the charts.

Ended up just using it on 1 chart at a time. It's just a matter of speeding up drawing alert lines. 

 

You need get Chart ID of each chart, then use ObjectCreate

bool  ObjectCreate(
   long          chart_id,      // chart ID
   string        object_name,   // object name
   ENUM_OBJECT   object_type,   // object type
   int           sub_window,    // window index
   datetime      time1,         // time of the first anchor point
   double        price1,        // price of the first anchor point
   ...
   datetime      timeN=0,       // time of the N-th anchor point
   double        priceN=0       // price of the N-th anchor point
   );
Reason: