Download MetaTrader 5

hrv-6-100

To add comments, please log in or register
Having questions? Ask them on the Forum - traders will help you!
constantin_n
18
constantin_n 2016.11.04 11:56 
hrv-6-100 indicator stopped working yesterday on time frame m1, works only on m5 and others. Someone can help?
Mladen Rakic
54691
Mladen Rakic 2016.11.04 12:23  
constantin_n:
hrv-6-100 indicator stopped working yesterday on time frame m1, works only on m5 and others. Someone can help?

what is "hrv-6-100"?

forum and google search returned 0 results

whroeder1
14530
whroeder1 2016.11.05 16:07  
constantin_n: Someone can help?
Only if you can post the source code.
constantin_n
18
constantin_n 2016.11.05 16:30  
Mladen Rakic:

what is "hrv-6-100"?

forum and google search returned 0 results

historical ratio of volatility
constantin_n
18
constantin_n 2016.11.05 16:32  
whroeder1:
Only if you can post the source code.

it's for mt4. here it is

 

 //+------------------------------------------------------------------+

//|                                                HRV-6 -100 .mq4 |

//|                      Copyright © 2005, MetaQuotes Software Corp. |

//|                                        http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property link ""

#property indicator_buffers 2

#property indicator_separate_window

#property indicator_color1 Yellow

#property indicator_color2 Red

#property indicator_level2 100

#property indicator_level3 0

#property indicator_level4 -100

extern int ShortPeriod = 6;

extern int LongPeriod = 100;

extern int calcperiode = 500;

//---- buffers

double Buffer3[]; 

 extern int    CountBars =  3000;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

IndicatorBuffers(1);

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);

SetIndexBuffer(0,Buffer3);

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custor indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//---- TODO: add your code here

 

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{//---- TODO: add your code here

 

 

 

for(int i=calcperiode;i>=0;i--)

{

Buffer3[i]=iStdDev(NULL,0,LongPeriod,MODE_EMA,0,PRICE_CLOSE,0  )/iStdDev(NULL,0,ShortPeriod,MODE_EMA,0,PRICE_CLOSE,  i);

} //iStdDev(NULL,0,ShortPeriod,MODE_EMA,0,PRICE_CLOSE,  i)/iStdDev(NULL,0,LongPeriod,MODE_EMA,0,PRICE_CLOSE,0  );

}

 

//----

//}

//+------------------------------------------------------------------+

MetaTrader 5 Trading Platform / MetaQuotes Software Corp.
  • www.metaquotes.net
MetaTrader 5 trading platform designed to arrange brokerage services in Forex, CFD, Futures, as well as equity markets
Mladen Rakic
54691
Mladen Rakic 2016.11.05 17:51  
constantin_n:

it's for mt4. here it is

 

 //+------------------------------------------------------------------+

//|                                                HRV-6 -100 .mq4 |

//|                      Copyright © 2005, MetaQuotes Software Corp. |

//|                                        http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property link ""

#property indicator_buffers 2

#property indicator_separate_window

#property indicator_color1 Yellow

#property indicator_color2 Red

#property indicator_level2 100

#property indicator_level3 0

#property indicator_level4 -100

extern int ShortPeriod = 6;

extern int LongPeriod = 100;

extern int calcperiode = 500;

//---- buffers

double Buffer3[]; 

 extern int    CountBars =  3000;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

IndicatorBuffers(1);

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);

SetIndexBuffer(0,Buffer3);

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custor indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//---- TODO: add your code here

 

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{//---- TODO: add your code here

 

 

 

for(int i=calcperiode;i>=0;i--)

{

Buffer3[i]=iStdDev(NULL,0,LongPeriod,MODE_EMA,0,PRICE_CLOSE,0  )/iStdDev(NULL,0,ShortPeriod,MODE_EMA,0,PRICE_CLOSE,  i);

} //iStdDev(NULL,0,ShortPeriod,MODE_EMA,0,PRICE_CLOSE,  i)/iStdDev(NULL,0,LongPeriod,MODE_EMA,0,PRICE_CLOSE,0  );

}

 

//----

//}

//+------------------------------------------------------------------+

Try using this :

#property indicator_buffers 1
#property indicator_separate_window
#property indicator_color1 clrYellow

extern int ShortPeriod = 6;
extern int LongPeriod  = 100;
extern int CountBars   = 500;

double Buffer[];
int init()   { SetIndexBuffer(0,Buffer); return(0); }
int deinit() {                           return(0); }
int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit = (CountBars>0) ? MathMin(Bars-1,CountBars-1) : MathMin(Bars-counted_bars,Bars-1);

   double dev0 = iStdDev(NULL,0,LongPeriod,MODE_EMA,0,PRICE_CLOSE,0);
   for(int i=limit;i>=0;i--)
   {
      double dev = iStdDev(NULL,0,ShortPeriod,MODE_EMA,0,PRICE_CLOSE,i);
      Buffer[i]  = (dev!=0) ? dev0/dev : 0;
   }      
   return(0);
}
But you know that it will repaint (regardless of what you set for CountBars - "calcperiode" in the code you posted)?
constantin_n
18
constantin_n 2016.11.10 12:18  
Mladen Rakic:

Try using this :

#property indicator_buffers 1
#property indicator_separate_window
#property indicator_color1 clrYellow

extern int ShortPeriod = 6;
extern int LongPeriod  = 100;
extern int CountBars   = 500;

double Buffer[];
int init()   { SetIndexBuffer(0,Buffer); return(0); }
int deinit() {                           return(0); }
int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit = (CountBars>0) ? MathMin(Bars-1,CountBars-1) : MathMin(Bars-counted_bars,Bars-1);

   double dev0 = iStdDev(NULL,0,LongPeriod,MODE_EMA,0,PRICE_CLOSE,0);
   for(int i=limit;i>=0;i--)
   {
      double dev = iStdDev(NULL,0,ShortPeriod,MODE_EMA,0,PRICE_CLOSE,i);
      Buffer[i]  = (dev!=0) ? dev0/dev : 0;
   }      
   return(0);
}
But you know that it will repaint (regardless of what you set for CountBars - "calcperiode" in the code you posted)?

seems working, ty. What do you mean it will repaint?

Mladen Rakic
54691
Mladen Rakic 2016.11.10 16:21  
constantin_n:

seems working, ty. What do you mean it will repaint?

It is using standard deviation of the current bar for all the past values (the "iStdDev(NULL,0,LongPeriod,MODE_EMA,0,PRICE_CLOSE,0)" part from your code). That has two problems - issues :

  • Past values are calculated using de facto future standard deviation that it could not "know" in the moment when that bar was closed
  • As soon as a new bar is formed, all the past bars (because of the above) are rendered obsolete and must be recalculated : i.e. : all the past values are going to be repainted

In order to avoid that, you have to replace the "0" part of that standard deviation call with "i", and move it within the loop,  and only then you shall have a non-repainting indicator (in that case the code would be like this - CountBars removed since there is no need to use it at all :

#property indicator_buffers 1
#property indicator_separate_window
#property indicator_color1 clrYellow

extern int ShortPeriod = 6;
extern int LongPeriod  = 100;

double Buffer[];
int init()   { SetIndexBuffer(0,Buffer); return(0); }
int deinit() {                           return(0); }
int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit = MathMin(Bars-counted_bars,Bars-1);

   for(int i=limit;i>=0;i--)
   {
      double dev = iStdDev(NULL,0,ShortPeriod,MODE_EMA,0,PRICE_CLOSE,i);
      Buffer[i]  = (dev!=0) ? iStdDev(NULL,0,LongPeriod,MODE_EMA,0,PRICE_CLOSE,i)/dev : 0;
   }      
   return(0);
}
constantin_n
18
constantin_n 2016.11.11 11:11  
Mladen Rakic:

It is using standard deviation of the current bar for all the past values (the "iStdDev(NULL,0,LongPeriod,MODE_EMA,0,PRICE_CLOSE,0)" part from your code). That has two problems - issues :

  • Past values are calculated using de facto future standard deviation that it could not "know" in the moment when that bar was closed
  • As soon as a new bar is formed, all the past bars (because of the above) are rendered obsolete and must be recalculated : i.e. : all the past values are going to be repainted

In order to avoid that, you have to replace the "0" part of that standard deviation call with "i", and move it within the loop,  and only then you shall have a non-repainting indicator (in that case the code would be like this - CountBars removed since there is no need to use it at all :

#property indicator_buffers 1
#property indicator_separate_window
#property indicator_color1 clrYellow

extern int ShortPeriod = 6;
extern int LongPeriod  = 100;

double Buffer[];
int init()   { SetIndexBuffer(0,Buffer); return(0); }
int deinit() {                           return(0); }
int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit = MathMin(Bars-counted_bars,Bars-1);

   for(int i=limit;i>=0;i--)
   {
      double dev = iStdDev(NULL,0,ShortPeriod,MODE_EMA,0,PRICE_CLOSE,i);
      Buffer[i]  = (dev!=0) ? iStdDev(NULL,0,LongPeriod,MODE_EMA,0,PRICE_CLOSE,i)/dev : 0;
   }      
   return(0);
}
thank you very much.
To add comments, please log in or register