it's no the same number because dlow is the previous imomentum value and dhigh is the present(today) value of imomentum. previous\present is my purpose but it 's impossible to calculate.
//--------------------------------+
//| My_First_Indicator.mq4 |
//| Codersguru |
//| https://www.mql5.com/en/forum |
//+------------------------------------------------------------------+
#property copyright "Codersguru"
#property link "https://www.forex-tsd.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
string short_name = "Your first indicator is running!";
IndicatorShortName(short_name);
//----
return(1);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- check for possible errors
if (counted_bars<0) return(-1);
//---- last counted bar will be recounted
if (counted_bars>0) counted_bars--;
int pos=Bars-counted_bars;
double dHigh , dLow , dResult,dresult2;
Comment("Hi! I'm here on the main chart windows!");
//---- main calculation loop
while(pos>=0)
{
dHigh = iMomentum(NULL,0,5,PRICE_CLOSE,pos);
dLow = iMomentum(NULL,0,5,PRICE_CLOSE,pos+1);
dResult = (dLow/(dHigh));\\\ previous/today value
ExtMapBuffer1[pos]= dResult ;
pos--;
}
//----
return(0);
}
You should ensure the momentum lookback period has been accounted for, as well as the check-for-zero...........
//| My_First_Indicator.mq4 |
//| Codersguru |
//| https://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Codersguru"
#property link "https://www.forex-tsd.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
extern int Momentum_Period = 5;
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
string short_name = "Your first indicator is running!";
IndicatorShortName(short_name);
//----
return(1);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- check for possible errors
if (counted_bars<0) return(-1);
//---- last counted bar will be recounted
if (counted_bars < Momentum_Period)
int pos=Bars-Momentum_Period-1;
else pos=Bars-counted_bars-1;
double dHigh , dLow , dResult,dresult2;
Comment("Hi! I'm here on the main chart windows!");
//---- main calculation loop
while(pos>=0)
{
dHigh = iMomentum(NULL,0,Momentum_Period,PRICE_CLOSE,pos);
dLow = iMomentum(NULL,0,5,PRICE_CLOSE,pos+1);
dResult = dLow/dHigh; // previous/today value
ExtMapBuffer1[pos]= dResult ;
pos--;
}
//----
return(0);
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
it's impossible to calculate this:
why??????