Indicator to draw arrow at certain time

 
Hi all,
I've done some expert programming but indicators are making me trouble. Could someone please write an indicator that will draw an arrow above the certain bar, based on time. For instance, an arrow above every 10.00 bar on hourly chart.
It seems to me as if it should be a few lines of code but...

Thanks in advance
 
Hi all,
I've done some expert programming but indicators are making me trouble. Could someone please write an indicator that will draw an arrow above the certain bar, based on time. For instance, an arrow above every 10.00 bar on hourly chart.
It seems to me as if it should be a few lines of code but...

Thanks in advance



I'd be willing to help, but I need clarification. Can you elaborate on where you want the arrow placed price, time interval, hard time, etc.
-charliev
 
see for example our custom indicator Fractals "MQL4: Fractals"
 
Hi all,
I've done some expert programming but indicators are making me trouble. Could someone please write an indicator that will draw an arrow above the certain bar, based on time. For instance, an arrow above every 10.00 bar on hourly chart.
It seems to me as if it should be a few lines of code but...

Thanks in advance



I'd be willing to help, but I need clarification. Can you elaborate on where you want the arrow placed price, time interval, hard time, etc.
-charliev

thank you charliev, arrow should be placed for instance at the high of every 10.00 am bar. it will not be used as an trading indicator but for manual backtesting and strategy developing
so, it's purpose will be to tell me "hey look, 10.00 am is right here", which is much quicker then waiting for a tooltip or using a crosshair to discover the 10.00 am bar

slawa, thanks for the example, I will try to modify it...

swacc



 
Here ya go...
-charliev


//+------------------------------------------------------------------+
//|                                                  MarkTimeGMT.mq4 |
//|                        Copyright © 2006, Charles W. Van Dien III |
//|                                    mailto: vandien@bellsouth.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Charles W. Van Dien III"
#property link      "mailto: vandien@bellsouth.net"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 White
extern int  MarkHourGMT=10;            //change default GMT Hour here
double MarkHour[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW,0,1);   // change size of arrow here
   SetIndexShift(0,0);
   SetIndexDrawBegin(0,0);
   SetIndexEmptyValue(0,0.0);
   SetIndexArrow(0,242);         // change wingding symbol value here
   SetIndexLabel(0,NULL);
   SetIndexBuffer(0,MarkHour);
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()   {
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   IndicatorShortName("Mark Hour GMT("+MarkHourGMT+")");
   int limit=0;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(Period()>60)  {
      Alert("Chart must be H1 or below!");
   }
   if(counted_bars>0) counted_bars--;
   int x=0;
   limit=Bars-counted_bars;
   for(x=0; x<limit; x++) {
      if(TimeHour(Time[x])==MarkHourGMT && TimeMinute(Time[x])==0) {
         MarkHour[x]=High[x]+20*Point;    // change height of arrow above High here
      }
   }
return(0);
}

//+------------------------------------------------------------------+
// Subroutines
//+------------------------------------------------------------------+





 
thanks a lot charliev, it works just as it should
I was pretty close to doing it alone but didn't really understand some basics, which I do now (with a help from your solution to this trivial problem and some RTFM)

one more thing, why do we have to do:
if(counted_bars>0) counted_bars--;
that way we recalculate indicator value for the previous bar, as well as for the current bar, for every price change at the current bar, right?
why is this neccessary, isn't it enough to calc it for the current bar?

swacc
 

one more thing, why do we have to do:
if(counted_bars>0) counted_bars--;
that way we recalculate indicator value for the previous bar, as well as for the current bar, for every price change at the current bar, right?
why is this neccessary, isn't it enough to calc it for the current bar?

swacc


It's 0 based. If you had 100 counted Bars they would actually be indexed 0-99. So you decrement the count by 1 to get the actual limit.

Here is a link to Codersguru's MQL4 Lessons tutorial http://www.metatrader.info/node/36 this is an excellent resource.
-charliev
 


It's 0 based. If you had 100 counted Bars they would actually be indexed 0-99. So you decrement the count by 1 to get the actual limit.

Here is a link to Codersguru's MQL4 Lessons tutorial http://www.metatrader.info/node/36 this is an excellent resource.
-charliev



One more thing, on first iteration IndicatorBars() returns zero, so Bars-0=Bars. Then each additional iteration (tick) only the Bars that are new get calculated due to the "limit" amount in the For/Next loop. I pulled this from the MQL4 Laugauge manual here http://www.networksimplicity.com/metatrader/mql4-manual.pdf
-charliev
 

one more thing, why do we have to do:
if(counted_bars>0) counted_bars--;
that way we recalculate indicator value for the previous bar, as well as for the current bar, for every price change at the current bar, right?
why is this neccessary, isn't it enough to calc it for the current bar?

swacc


It's 0 based. If you had 100 counted Bars they would actually be indexed 0-99. So you decrement the count by 1 to get the actual limit.

Here is a link to Codersguru's MQL4 Lessons tutorial http://www.metatrader.info/node/36 this is an excellent resource.
-charliev




but I still find it unnecessary:
if we have total of 5 bars in the chart, IndicatorCounted would return 4 (total Bars - 1) and we would further decrement to get counted_bars=3 and limit=bars-counted_bars=5-3=2
then in the for loop we would have for(x=0;x<2;x++) which means that we calculate indicato value for x=0 (current bar) and x=1 (previous bar)
why the previous bar?

swacc
 
ok, I've found the answer in the IndicatorCounted() docs:

"Note: The latest bar is not considered to be calculated and, in the most cases, it is necessary to recalculate only this bar. However, there occur some boundary cases where custom indicator is called from the expert at the first tick of the new bar. It is possible that the last tick of the previous bar had not been processed (because the last-but-one tick was being processed when this last tick came), the custom indicator was not called and it was not calculated because of this..."

Basically there is no need to decrement counted_bars but in some special cases it might happen that the last tick do not get processed so, by decrementing, we make sure that even in this (probably) very rare cases the indicator value is correct to the last tick.

thanks again for the help
swacc
Reason: