Can i create objects (example OBJ_HLINE) inside OBJ_CHART?

 

i am trying to display 4 time frames in one screen, hence i  created 4 OBJ_CHARTs in one ChartWindow. I would like to draw a OBJ_HLINE, just like what we can do on the ChartWindow but seems like its not working. the OBJ_HLINE appears in ChartWindow. Can anyone help?


   int totalcharts = 4,chartobjectID,chartwidth = (x2-x1)/2,chartheight = (y2-y1)/2;

   string chartname;   

   for(int i=0; i<= totalcharts-1; i++)

   {

      chartname = "FRXChart" + IntegerToString(i);

      ObjectCreate(0,chartname,OBJ_CHART,0,0,0,0,0);

      chartobjectID = ObjectGetInteger(0,chartname,OBJPROP_CHART_ID);

      Print(chartobjectID, " ", chartname);      

      if(i==0)

      {

         ObjectSetInteger(0,chartname,OBJPROP_XDISTANCE,x1);

         ObjectSetInteger(0,chartname,OBJPROP_YDISTANCE,y1);

         ObjectSetInteger(0,chartname,OBJPROP_PERIOD,PERIOD_D1);

      }

      else if(i==1)

      {

         ObjectSetInteger(0,chartname,OBJPROP_XDISTANCE,x1);

         ObjectSetInteger(0,chartname,OBJPROP_YDISTANCE,chartheight);

         ObjectSetInteger(0,chartname,OBJPROP_PERIOD,PERIOD_H4);

      }

      else if(i==2)

      {

         ObjectSetInteger(0,chartname,OBJPROP_XDISTANCE,x1+chartwidth);

         ObjectSetInteger(0,chartname,OBJPROP_YDISTANCE,0);  

         ObjectSetInteger(0,chartname,OBJPROP_PERIOD,PERIOD_H1);    

      }

      

      else if(i==3)

      {

         ObjectSetInteger(0,chartname,OBJPROP_XDISTANCE,x1+chartwidth);

         ObjectSetInteger(0,chartname,OBJPROP_YDISTANCE,chartheight);

         ObjectSetInteger(0,chartname,OBJPROP_PERIOD,PERIOD_M15);

        

      }

      ObjectSetString(0,chartname,OBJPROP_SYMBOL,Symbol());           

      ObjectSetInteger(0,chartname,OBJPROP_XSIZE,chartwidth);

      ObjectSetInteger(0,chartname,OBJPROP_YSIZE,chartheight);

      ObjectSetInteger(0,chartname,OBJPROP_DATE_SCALE,true);

      ObjectSetInteger(0,chartname,OBJPROP_PRICE_SCALE,true);

      ObjectSetInteger(0,chartname,OBJPROP_SELECTABLE,1);

      ObjectSetInteger(0,chartname,OBJPROP_CHART_SCALE,3);

      ObjectCreate(chartobjectID,"Test",OBJ_HLINE,0,0,1283.79); //Atttemping to draw OBJ_HLINE in OBJ_CHART through OBJPROP_CHART_ID 

      ObjectSetInteger(chartobjectID,"Test",OBJPROP_PERIOD,PERIOD_D1);

 
ChartRedraw(chartobjectID);


Any objects in OBJ_CHART


Another convenient way to use this type of object

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Особенности языка mql5, тонкости и приёмы работы

fxsaber, 2017.10.31 08:11

// Saving Bitmap-object in bmp/gif/png-file (without transparency)
bool BitmapObjectToFile( const long chartID, const string ObjName, const string FileName, const bool FullImage = false )
{  
  const ENUM_OBJECT Type = (ENUM_OBJECT)ObjectGetInteger(chartID, ObjName, OBJPROP_TYPE);  
  bool Res = (Type == OBJ_BITMAP_LABEL) || (Type == OBJ_BITMAP);
             
  if (Res)
  {
    const string Name = __FUNCTION__ + (string)MathRand();

    ObjectCreate(chartID, Name, OBJ_CHART, 0, 0, 0);
    ObjectSetInteger(chartID, Name, OBJPROP_XDISTANCE, -1e3);
    
    const long chart = ObjectGetInteger(chartID, Name, OBJPROP_CHART_ID);
        
    Res = ChartSetInteger(chart, CHART_SHOW, false) && ObjectCreate(chart, Name, OBJ_BITMAP_LABEL, 0, 0, 0) &&
          ObjectSetString(chart, Name, OBJPROP_BMPFILE, ObjectGetString(chartID, ObjName, OBJPROP_BMPFILE)) &&
          (FullImage || (ObjectSetInteger(chart, Name, OBJPROP_XSIZE, ObjectGetInteger(chartID, ObjName, OBJPROP_XSIZE)) &&
                         ObjectSetInteger(chart, Name, OBJPROP_YSIZE, ObjectGetInteger(chartID, ObjName, OBJPROP_YSIZE)) &&
                         ObjectSetInteger(chart, Name, OBJPROP_XOFFSET, ObjectGetInteger(chartID, ObjName, OBJPROP_XOFFSET)) &&
                         ObjectSetInteger(chart, Name, OBJPROP_YOFFSET, ObjectGetInteger(chartID, ObjName, OBJPROP_YOFFSET)))) &&
                         ChartScreenShot(chart, FileName, (int)ObjectGetInteger(chart, Name, OBJPROP_XSIZE),
                                                          (int)ObjectGetInteger(chart, Name, OBJPROP_YSIZE));
    ObjectDelete(chartID, Name);
  }                    

  return(Res);
}


Use

// Saves in png-files all Bitmap objects of the current chart
void OnStart()
{  
  for (int i = ObjectsTotal(0) - 1; i >= 0; i--)
  {
    const string Name = ObjectName(0, i);
    
    BitmapObjectToFile(0, Name, (string)ChartID() + "\\" + Name + ".png");    
  }      
}


PS Also, the BMP-> GIF/PNG file converter is implemented.

 
fxsaber:


Any objects in OBJ_CHART


Another convenient way to use this type of object


I added ChartRedraw. but its still not appearing. 

int totalcharts = 4,chartobjectID,chartwidth = (x2-x1)/2,chartheight = (y2-y1)/2;

   string chartname;   

   for(int i=0; i<= totalcharts-1; i++)

   {

      chartname = "FRXChart" + IntegerToString(i);

      ObjectCreate(0,chartname,OBJ_CHART,0,0,0,0,0);

      chartobjectID = ObjectGetInteger(0,chartname,OBJPROP_CHART_ID);

      Print(chartobjectID, " ", chartname);      

      if(i==0)

      {

         ObjectSetInteger(0,chartname,OBJPROP_XDISTANCE,x1);

         ObjectSetInteger(0,chartname,OBJPROP_YDISTANCE,y1);

         ObjectSetInteger(0,chartname,OBJPROP_PERIOD,PERIOD_D1);

      }

      else if(i==1)

      {

         ObjectSetInteger(0,chartname,OBJPROP_XDISTANCE,x1);

         ObjectSetInteger(0,chartname,OBJPROP_YDISTANCE,chartheight);

         ObjectSetInteger(0,chartname,OBJPROP_PERIOD,PERIOD_H4);

      }

      else if(i==2)

      {

         ObjectSetInteger(0,chartname,OBJPROP_XDISTANCE,x1+chartwidth);

         ObjectSetInteger(0,chartname,OBJPROP_YDISTANCE,0);  

         ObjectSetInteger(0,chartname,OBJPROP_PERIOD,PERIOD_H1);    

      }

      

      else if(i==3)

      {

         ObjectSetInteger(0,chartname,OBJPROP_XDISTANCE,x1+chartwidth);

         ObjectSetInteger(0,chartname,OBJPROP_YDISTANCE,chartheight);

         ObjectSetInteger(0,chartname,OBJPROP_PERIOD,PERIOD_M15);

        

      }

     ObjectSetString(0,chartname,OBJPROP_SYMBOL,Symbol());           

      ObjectSetInteger(0,chartname,OBJPROP_XSIZE,chartwidth);

      ObjectSetInteger(0,chartname,OBJPROP_YSIZE,chartheight);

      ObjectSetInteger(0,chartname,OBJPROP_DATE_SCALE,true);

      ObjectSetInteger(0,chartname,OBJPROP_PRICE_SCALE,true);

      ObjectSetInteger(0,chartname,OBJPROP_SELECTABLE,1);

      ObjectSetInteger(0,chartname,OBJPROP_CHART_SCALE,3);

      ObjectCreate(chartobjectID,"Test",OBJ_HLINE,0,0,1283); //Atttemping to draw OBJ_HLINE in OBJ_CHART through OBJPROP_CHART_ID 

      ObjectSetInteger(chartobjectID,"Test",OBJPROP_PERIOD,PERIOD_D1);

      ChartRedraw(chartobjectID);    

 

is there anything else that i am missing? thanks 

 
Sergey Golubev:

ok noted. thanks

 

Chye Thiam Tan:

I added ChartRedraw. but its still not appearing.

long chartobjectID = ObjectGetInteger(0,chartname,OBJPROP_CHART_ID);
 
fxsaber:

its working!!... so awesome.. thanks for your guidance and time. appreciate.. :)