Create an automatic Fibonacci time indicator

 

Hi everyone

I have been reading the topics on this forum for years and I love the great feedback here.

I open my first topic, to share and ask for your opinion.

I am trying to make an indicator that automatically gives the fibonacci time of the current candle (not future candles), I insist it is the time not the price levels.

So after much research, I decided to use ZigZag to determine two points High AND low, or Low and High, depending on which were the last 2 or 3. I reviewed a lot of zigzag indicators, and the one I liked the most is zz_DT_ZZ (attached file for download), ok, with a while procedure, I search for the last 3 zigzag points, and I keep the third and second found to determine my first 100%, from then on I count the number of candles there are and I have calculated the current "moment" referenced to that distance. v0 and v1 = 100 %, next candles increase that percent.

for example, if 10 candles ago was my first point "V0" and the second point found "v1", and they were 10 candles distance, one from each other, I have my first 100%, so subsequent candles will do for example 1.38, something like 14 candles, remember first 10 candles did 100%, so would be interesting to know that current candle, present time. is almost 1.38 (14 candles away from V0).

In my script, in the while procedure, the "P"s variables store hi/low prices,(feed from zigzag hi-lo points) once found it, store the "V"s variables which count the bars to those points found it.

To achieve this, you need to smooth out the candles and renko is perfect for this, in fact, is imperative, uniform candles. So the timeframe should be "current" or "0", using renko.

Everything goes well, it's perfect, do a while to get those points of the zigzag and only alter the "extdepth", so using extdepth now I have several ways to have zigzags of different sizes, this function works perfectly for me when I comment it on my indicator script, but troubles begin when I need it to perform other calculations, curiously if I invoke it to comment, it gives the results very well, but when I invoke it to perform a "filewrite" , for example, it gets stuck and I have to wildly end the metatrader shuting down by windows manager, since it stays frozen.

The function asks for two parameters:

  • 1.- which bar for begin?
  • 2.-extdepth

To comment, it works very well, you can in parameter 1 determine from which bar in the past backwards it performs its search and with the second parameter determine the size of the zigzag, all very well but only when I call the function when commenting ! when I call it for filewrite it just freezes.

note, I use this filewrite procedure for N number of functions and icustoms and it always works for me, it is specifically in this function where I get stuck. so I appreciate any comment from the community, and of course I share the idea and my code with great pleasure.


function while for scan past zigzag points and return ratio:

double Sensor_FiboTime(int ss, int ExtDepth) {

int inicial = ss;
double fibo_time =0;
int n;
double p0, p1, p2, p3;
int v0, v1, v2, v3;
double velas_zz_ant;
double velas_zz_actual;

while(n<3) {
 if(p0>0) {p3=p2;v3=v2;p2=p1;v2=v1;p1=p0;v1=v0;}
    p0= iCustom(NULL,0, "zz_DT_ZZ",ExtDepth,0,ss);v0=ss;
    if(p0>0) {n+=1; }
    ss++;}

v0 = v0 - inicial;
v1 = v1 - inicial;
v2 = v2 - inicial;
inicial = 0;

      velas_zz_ant =MathAbs(v0-v1); 
      velas_zz_actual = v1;
      fibo_time = (velas_zz_actual/velas_zz_ant)+1;

return (fibo_time);}

The ZigZag Indicator: Fresh Approach and New Solutions
The ZigZag Indicator: Fresh Approach and New Solutions
  • www.mql5.com
The article examines the possibility of creating an advanced ZigZag indicator. The idea of identifying nodes is based on the use of the Envelopes indicator. We assume that we can find a certain combination of input parameters for a series of Envelopes, whereby all ZigZag nodes lie within the confines of the Envelopes bands. Consequently, we can try to predict the coordinates of the new node.
Files:
zz_DT_ZZ.mq4  8 kb
 

script for filewrite:

string   FileName = Symbol()+"3.csv";
int limit,f;
int counted_bars = IndicatorCounted();

      if(counted_bars>0) counted_bars--;

      limit = Bars - counted_bars - 1;


      for(f = limit - 1; f>=0; f--) 
         { 
      
            int handle=FileOpen(FileName,FILE_CSV|FILE_READ|FILE_WRITE,",");
            
            FileWrite(handle,"Open Timestamp","Open","High","Low","Close","Volume","fibotime_1","fibotime_3","fibotime_12","fibotime_24");
            FileSeek(handle,0,SEEK_END);
            FileWrite(handle,Time[f],Open[f],High[f],Low[f],Close[f],Volume[f],
               Sensor_FiboTime(f,1),
               Sensor_FiboTime(f,3),
               Sensor_FiboTime(f,12),
               Sensor_FiboTime(f,24),                                             
            );
            FileClose(handle);    
         }
         return(0);