Who can help tell why the code can't show "rectangle"?

Back to topics list To post a new topic, please log in or register
avatar
228
jollydragon 2016.01.22 09:04
 


With the code below, I want to show a rectangle frame around the latest 3 bars.  

Who can help tell why the code can't show the "rectangle frame"?  I couldn't find the root cause.

Also attached the print log below for reference.  Maybe you can copy the code below as an indicator for try too.

 

 

//+------------------------------------------------------------------+
//|                                                   CandleMean.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

int      xs,ys,xe,ye,xSize,ySize;
string objPrice="Mean_Price";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if(id==CHARTEVENT_CLICK)
     {
      if(ObjectFind(objPrice)<0) ObjectCreate(ChartID(),objPrice,OBJ_RECTANGLE,0,0,0);
      ObjectSet(objPrice,OBJPROP_BORDER_TYPE,BORDER_FLAT);
      ObjectSet(objPrice,OBJPROP_WIDTH,3);
      ObjectSet(objPrice,OBJPROP_COLOR,clrDeepPink);

      ChartTimePriceToXY(ChartID(),0,Time[3],Low[0],xs,ye);
      ChartTimePriceToXY(ChartID(),0,Time[0],High[3],xe,ys);
      xSize=xe-xs;
      ySize=ye-ys; PrintFormat("xs %i,ys %i,xSiz %i,ySize %i",xs,ys,xSize,ySize);
      ObjectSet(objPrice,OBJPROP_XSIZE,xSize);
      ObjectSet(objPrice,OBJPROP_YSIZE,ySize);
      ObjectSet(objPrice,OBJPROP_XDISTANCE,xs);
      ObjectSet(objPrice,OBJPROP_YDISTANCE,ys);
     }
  }
//+------------------------------------------------------------------+

 

avatar
Moderator
3404
GumRai 2016.01.22 09:50 #
 
OBJ_RECTANGLE is anchored by time and price, not pixels
avatar
228
jollydragon 2016.01.22 10:04 #
 

Thanks. But how to change the rectangle size? How to change it to a frame instead of solid filling? 

avatar
228
jollydragon 2016.01.22 10:49 #
 
Besides, how to create a line segment as object?
avatar
228
jollydragon 2016.01.22 10:58 #
 
Besides, how to skip weekend with code if counting bars for the object of "rectangle"?
avatar
Moderator
3404
GumRai 2016.01.22 11:39 #
 

First decide what you want to draw

if OBJ_RECTANGLE 

change size by moving the anchor points

If set as background is true, it will show as a frame. If false, it will have a solid fill

I sometimes use 4 trend lines instead of a rectangle 

 

avatar
228
jollydragon 2016.01.24 08:49 #
 
GumRai:

First decide what you want to draw

if OBJ_RECTANGLE 

change size by moving the anchor points

If set as background is true, it will show as a frame. If false, it will have a solid fill

I sometimes use 4 trend lines instead of a rectangle 

 

 

Thank you very much! Realized! 

avatar
125
zirkoner 2016.01.26 19:33 #
 
Don't you need to use RECTANGLE_LABEL instead ?
Back to topics list  

To add comments, please log in or register