Time indicator

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
209
thrdel 2014.04.09 06:15 #
 
doktorfx:

Yes, by histogram, I mean bars. And what I mean by " kind of difficult reading the individual time stamps.", is basically that it would be easier to analyze Bar Heights than reading vertically printed text.


True, but then you'd get long bars for periods of inactivity in the market and really small bars for when the market moves fast.

Here, try this and see how it works :

//+------------------------------------------------------------------+
//|                                         Renko_Time_Histogram.mq4 |
//|                                   Copyright © 2014, thrdel  tm |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, thrdel  tm"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrLightBlue
#property indicator_width1 3

#include <stdlib.mqh> 
//---
double ExtBuffer1[];
//---
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer1,INDICATOR_DATA);
   SetIndexStyle(0,DRAW_HISTOGRAM);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration 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[])
  {
//---
   datetime barTimeValue=0;
//--- set arrays as series
   if(!ArraySetAsSeries(ExtBuffer1,true) || !ArraySetAsSeries(time,true))
      Print("Failed to set arrays as series !"+ErrorDescription(GetLastError()));
//---
   int i=0,limit=0;
//--- initial zero
   if(prev_calculated<=0)
     {
      for(i=0;i<rates_total-1;i++)
        {
         barTimeValue=time[i]-time[i+1];
         if(barTimeValue>172800)barTimeValue=time[i]-time[i+1]-172800;//-- weekend routine , 172800 for 2 days weekend
         ExtBuffer1[i+1]=NormalizeDouble((barTimeValue)/PeriodSeconds(PERIOD_CURRENT),2);
        }
     }
//--- only new bars
   else
     {
      limit=rates_total-prev_calculated;
      for(i=limit;i>=0;i--)
        {
         barTimeValue=time[i]-time[i+1];
         if(time[i]-time[i+1]>172800)barTimeValue=time[i]-time[i+1]-172800;
         ExtBuffer1[i+1]=NormalizeDouble((barTimeValue)/PeriodSeconds(PERIOD_CURRENT),2);
         datetime currentBarTimeValue=TimeCurrent()-time[0];
         if(currentBarTimeValue>172800)currentBarTimeValue=TimeCurrent()-time[0]-172800;
         ExtBuffer1[i]=NormalizeDouble(currentBarTimeValue/PeriodSeconds(PERIOD_CURRENT),2);
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

As you can see, time in seconds is divided by the chart period so histogram is not in seconds but multiples of chart period, which means that on an M10 chart for example, 1 unit on histogram = 10 minutes time, 2 units = 20 minutes and so on.

avatar
1109
Ovo 2014.04.09 06:57 #
 
thrdel:

True, but then you'd get long bars for periods of inactivity in the market or weekends and really small bars for when the market moves fast.


Yes, I think it is very similar to Volumes indicator. Long bars during consolidation. (though I believe volume shows it better than time, and is already built in)

avatar
209
thrdel 2014.04.09 07:40 #
 
Ovo:


Yes, I think it is very similar to Volumes indicator. Long bars during consolidation. (though I believe volume shows it better than time, and is already built in)


Yes, you're right. But with time, I worked around weekend as you can see in the code, maybe not perfect but eliminates a large part of the long bars.

The only inconvenient may be if the market stays still for days.

avatar
1109
Ovo 2014.04.09 07:58 #
 
thrdel:


Yes, you're right. But with time, I worked around weekend as you can see in the code, maybe not perfect but eliminates a large part of the long bars.

The only inconvenient may be if the market stays still for days.

You can hardly detect the time gaps on Renko without the underlying chart. On the underlying TF chart may detect gaps if there is no bar within 30 minutes interval after the measured bar period expired.

avatar
209
thrdel 2014.04.09 08:52 #
 
Ovo:
You can hardly detect the time gaps on Renko without the underlying chart. On the underlying TF chart may detect gaps if there is no bar within 30 minutes interval after the measured bar period expired.


True but I was more concerned about smaller time frames and bars started before weekend. On a 2 min frame, 2 days of weekend = 1440 of 2 min periods. If a bar on average takes up to let's say 200 minutes to complete or 100 periods and next one includes the weekend, the difference is quite big and makes all other bars look so small.
avatar
14
doktorfx 2014.04.09 09:34 #
 
thrdel:

True but I was more concerned about smaller time frames and bars started before weekend. On a 2 min frame, 2 days of weekend = 1440 of 2 min periods. If a bar on average takes up to let's say 200 minutes to complete or 100 periods and next one includes the weekend, the difference is quite big and makes all other bars look so small.

Thanks
thrdel:


True, but then you'd get long bars for periods of inactivity in the market and really small bars for when the market moves fast.

Here, try this and see how it works :

As you can see, time in seconds is divided by the chart period so histogram is not in seconds but multiples of chart period, which means that on an M10 chart for example, 1 unit on histogram = 10 minutes time, 2 units = 20 minutes and so on.

Thanks. You done did it again.
avatar
5
pabloroacho 2015.02.28 14:07 #
 

Hello,


I wish I had found this post before spending a weekend writing a version myself from scratch. Originally I wanted to change the colour of candles to indicate the time, even just by simply highlighting bricks that, say, took less than 5 minutes to form on a renko chart. This seemed to be a bit tricky and I couldn't find an easy way to do it or easily change existing code I could find. So I wrote a simple indicator to plot the time differences in seconds.

It is here -> https://www.mql5.com/en/code/12491

It doesn't quite give the same results as your code. It doesn't try to 'deal' with long bars over market closed periods. Price can move very fast or very slow.

If anyone is interested in this or in renko trading systems then I would be happy to hear about it.

Thanks and best of luck with your trading!

see also / google ~ RenkoAM_v2.0.mq4 indicator


Back to topics list   | 1 2  

To add comments, please log in or register