Download MetaTrader 5

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

To add comments, please log in or register
Thousands of developers have already published their products in the Market. Join them!
moonsboy
889
moonsboy 2016.01.22 08: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);
     }
  }
//+------------------------------------------------------------------+
Keith Watford
Moderator
9625
Keith Watford 2016.01.22 08:50  
OBJ_RECTANGLE is anchored by time and price, not pixels
moonsboy
889
moonsboy 2016.01.22 09:04  

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

moonsboy
889
moonsboy 2016.01.22 09:49  
Besides, how to create a line segment as object?
moonsboy
889
moonsboy 2016.01.22 09:58  
Besides, how to skip weekend with code if counting bars for the object of "rectangle"?
Keith Watford
Moderator
9625
Keith Watford 2016.01.22 10: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 

moonsboy
889
moonsboy 2016.01.24 07: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! 

Zirkon
122
Zirkon 2016.01.26 18:33  
Don't you need to use RECTANGLE_LABEL instead ?
To add comments, please log in or register