Auto Draw rectangle from HIGH 10:00 AM candle to LOW 11 AM candle everyday.

 

Hi there,

I am trying something simple: To draw on the 10:00 AM candle a rectangle spanning from the High of the first candle to the Low of the second (@ 11:00 AM).

I am using the below code, but not working, no rectangle is appearing - cod below:

//+------------------------------------------------------------------+
//|                                                        test4.mq4 |
//|                                                  Wissam Boustany |
//|                                      http://www.trader-forex.com |
//+------------------------------------------------------------------+
#property copyright "Wissam Boustany"
#property link      "http://www.trader-forex.com"

#property indicator_chart_window
static int oldBarTime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {oldBarTime=Time[0];
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int x;
   bool  New1HBar;
   
   New1HBar=false;
//----

//
if(oldBarTime!=Time[0])
{oldBarTime=Time[0];
New1HBar=true;}
else New1HBar=false;

   if (New1HBar==true)
     if(Hour()==12)
      {ObjectCreate("Rectangle",OBJ_RECTANGLE,0,Time[2],Low[2],Time[1],High[1]);
       ObjectSet("Rectangle",OBJPROP_SCALE,1.0);
       ObjectSet("Rectangle",OBJPROP_COLOR,Gold);}
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

If I take out the

if (New1HBar==true)     
if(Hour()==12)

It will draw a rectangle, but not using my constraints. I now that I should also give a ticket number to each rectangle in the future so the sytem will be able to draw several rectangle, but Im not into that yet, I just cant draw any rectangle using the current code. Can anyone help ?

Thx!

 
it sounds like when you draw lines or something graphic objects you have to use buffers and fill data to them. it is just for customed indicator not for Ea. honestly i am not quite sure for this, i tried to add simple vertical line at the point when a new trade opened,but i could only get the first line. you can check the book or documentation on this website.
 
inquisiteur wrote >>

Hi there,

I am trying something simple: To draw on the 10:00 AM candle a rectangle spanning from the High of the first candle to the Low of the second (@ 11:00 AM).

I am using the below code, but not working, no rectangle is appearing - cod below:

If I take out the

It will draw a rectangle, but not using my constraints. I now that I should also give a ticket number to each rectangle in the future so the sytem will be able to draw several rectangle, but Im not into that yet, I just cant draw any rectangle using the current code. Can anyone help ?

Thx!

This might be of use. I wanted to draw rectangles on the chart to indicate the best times for me to trade my system which is around the Euro and US opens.

Files:
Reason: