I found some errors. I forgot to call " #property indicator_buffers 3 " and "#property indicator_color1 Red". Now, there is a line, but it´s showing 0 all time. The problem is probably on the looping, but I don't have idea how to fix it.
Please, if you know how to correct it, let me know!
Thanks
Look at this and further
MMA=iMA(NULL,0,periodo,0,MODE_EMA,PRICE_CLOSE,0);
You never change your data.
limit=Bars;//-counted_bars; for(i = limit; i >= 0; i--) IMPETMMA=MMA_Buffer[i]-MMA_Buffer[i+1];
Open[Bars]... does not exist and MMA_Buffer[Bars+1]
//+------------------------------------------------------------------+ //| Flat Market Indicator.mq4 | //| Copyright ? 2010, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright ? 2010, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Red //---- input parameters extern int periodo=35; extern int LinhaDisparo; //---- double FMIBuffer[]; double MMA_Buffer[]; double SMMA_Buffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(3) ; SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2); SetIndexBuffer(0,FMIBuffer); SetIndexDrawBegin(0, 2*periodo); SetIndexBuffer(1,MMA_Buffer); SetIndexBuffer(2,SMMA_Buffer); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i; double MMA, SMMA,IMPETMMA,IMPETSMMA,DIVMA,AVERIMPET,TDF,NTDF; int counted_bars = IndicatorCounted(); static datetime prevtime = 0; //---- check for possible errors if(counted_bars < 0) return(-1); //---- last counted bar will be recounted if(counted_bars > 0) counted_bars--; limit=Bars;//-counted_bars; for(i = limit; i >= 0; i--) { MMA=iMA(NULL,0,periodo,0,MODE_EMA,PRICE_CLOSE,i); MMA_Buffer[i]=MMA; SMMA=iMA(NULL,0,periodo,0,MODE_SMA,PRICE_CLOSE,i); SMMA_Buffer[i]=SMMA; } for(i = limit; i >= 0; i--) { IMPETMMA=MMA_Buffer[i]-MMA_Buffer[i+1]; IMPETSMMA=SMMA_Buffer[i] - SMMA_Buffer[i+1]; DIVMA=MathAbs(MMA_Buffer[i] - SMMA_Buffer[i]); AVERIMPET= (IMPETMMA+IMPETSMMA)/2; TDF= MathPow(DIVMA,1)*MathPow(AVERIMPET,3);//culprit NTDF=TDF/iHighest(NULL,0,MathAbs(TDF),periodo*3,0); FMIBuffer[i]=MathAbs(NTDF); } //---- return(0); } //+------------------------------------------------------------------+The line in red seems to be the route of the problem. AVERIMPET to the power of 3 results in 0.0000 or -0.0000
The line in red seems to be the route of the problem. AVERIMPET to the power of 3 results in 0.0000 or -0.0000
Thanks.... I realize that too.. That is the original formula, but to solve this problem I multiplied for 100000. But, the indicator is instable, when I open it is different from when I wait for new prices. Do you know why this happens?
I tried to translate from Metastock, but until this moment it's not as good as the original.
cant say i had that problem when testing it.
for(i = limit; i >= 0; i--) { IMPETMMA=MMA_Buffer[i]-MMA_Buffer[i+1]; IMPETSMMA=SMMA_Buffer[i] - SMMA_Buffer[i+1]; DIVMA=MathAbs(MMA_Buffer[i] - SMMA_Buffer[i]); AVERIMPET= ((IMPETMMA+IMPETSMMA)/2)*100000; TDF= MathPow(DIVMA,1)*MathPow(AVERIMPET,3); NTDF=TDF/iHighest(NULL,0,MathAbs(TDF),periodo*3,0); FMIBuffer[i]=MathAbs(NTDF); }
The next problem is with this line
NTDF=TDF/iHighest(NULL,0,MathAbs(TDF),periodo*3,0);
This results in zero divide error. The third parameter in iHighest() needs to be an integer 0 - 5. You need another way to switch between types.
cant say i had that problem when testing it.
The next problem is with this line
This results in zero divide error. The third parameter in iHighest() needs to be an integer 0 - 5. You need another way to switch between types.
//+------------------------------------------------------------------+ //| Flat Market Indicator.mq4 | //| Copyright © 2010, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Green //---- input parameters extern int PeriodoFMI=50; //---- double FMI_Buffer[]; double MMA_Buffer[]; double SMMA_Buffer[]; double IMPETMMA_Buffer[]; double IMPETSMMA_Buffer[]; double DIVMA_Buffer[]; double AVERIMPET_Buffer[]; double TDF_Buffer[]; double NTDF_Buffer[]; //---- //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 7 additional bufferr are used for counting. IndicatorBuffers(8); SetIndexBuffer(1,MMA_Buffer); SetIndexBuffer(2,SMMA_Buffer); SetIndexBuffer(3,IMPETMMA_Buffer); SetIndexBuffer(4,IMPETSMMA_Buffer); SetIndexBuffer(5,DIVMA_Buffer); SetIndexBuffer(6,AVERIMPET_Buffer); SetIndexBuffer(7,TDF_Buffer); //---- indicator lines SetIndexBuffer(0,FMI_Buffer); SetIndexStyle(0,DRAW_HISTOGRAM); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit; int counted_bars=IndicatorCounted(); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; //---- for(int i=0; i<limit; i++) MMA_Buffer[i]=iMA(NULL,0,PeriodoFMI,0,MODE_EMA,PRICE_CLOSE,i); for(i=0; i<limit; i++) SMMA_Buffer[i]=iMAOnArray(MMA_Buffer,Bars,PeriodoFMI,0,MODE_EMA,i); for(i=0; i<limit; i++) IMPETMMA_Buffer[i]=MMA_Buffer[i]-MMA_Buffer[i+1]; for(i=0; i<limit; i++) IMPETSMMA_Buffer[i]=SMMA_Buffer[i] - SMMA_Buffer[i+1]; for(i=0; i<limit; i++) DIVMA_Buffer[i]=MathAbs(MMA_Buffer[i] - SMMA_Buffer[i]); for(i=0; i<limit; i++) AVERIMPET_Buffer[i]= (IMPETMMA_Buffer[i]+IMPETSMMA_Buffer[i])/2; for(i=0; i<limit; i++) TDF_Buffer[i]= ((DIVMA_Buffer[i])*(AVERIMPET_Buffer[i])*3)*100000; for(i=0; i<limit; i++) FMI_Buffer[i]=MathAbs(TDF_Buffer[i]/iHighest(NULL,0,MathAbs(TDF_Buffer[i]),PeriodoFMI*3,0)); //---- return(0); } //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ //| Flat Market Indicator.mq4 | //| Copyright © 2010, wabbit.com.au. | //| http://www.wabbit.com.au | //| | //| {FLAT MARKET INDICATOR (FMI) by Piotr Wojdy?o} | //| {indicator of "flat market"} | //| http://trader.online.pl/MSZ/e-w-Flat_Market_Indicator.html | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, wabbit.com.au" #property link "http://www.wabbit.com.au" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Red extern int periods = 17; double FMI[]; double MMA[]; double SMMA[]; double TDF[]; int init() { IndicatorBuffers(4) ; IndicatorDigits(Digits); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,FMI); SetIndexDrawBegin(0, 3*periods); SetIndexBuffer(1,MMA); SetIndexBuffer(2,SMMA); SetIndexBuffer(3,TDF); return(0); } int deinit() { return(0); } int start() { int i; double IMPETMMA,IMPETSMMA,DIVMA,AVERIMPET,HHV; int counted_bars = IndicatorCounted(); if(counted_bars>0) counted_bars--; int limit=Bars-counted_bars; for(i = limit; i >= 0; i--) { MMA[i] = iMA(NULL,0,periods,0,MODE_EMA,PRICE_CLOSE,i); } for(i = limit-1; i >= 0; i--) { SMMA[i] = iMAOnArray(MMA,0,periods,0,MODE_EMA,i); IMPETMMA = MMA[i] - MMA[i+1]; IMPETSMMA = SMMA[i] - SMMA[i+1]; DIVMA = MathAbs(MMA[i] - SMMA[i]); AVERIMPET= (IMPETMMA + IMPETSMMA)/2.0; TDF[i] = MathAbs(DIVMA * MathPow(AVERIMPET,3)); HHV = TDF[ArrayMaximum(TDF,periods*3,i)]; if(HHV!=0.0) FMI[i] = TDF[i]/HHV; else FMI[i] = 0.0; } return(0); }
Thank you so much wabbit. You are the one that is well known for Metastock language skills, don't you?! I really appreciate your help. Thanks again.
Could you explain me better the difference between this line:
for(int i=0; i<limit; i++)
for(i = limit-1; i >= 0; i--)
To me it remains confusing this type of logic. This difference probably made my formula wrong.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I was trying to do the Flat Market indicator Formula, but there is an error in the formula and I don't know where, the result is that it's not showing any value. The code is bellow. Can you help me out with this?