iMAOnArray()

 

I'm using iMAOnArray and I seem to be getting a straight line.

I'm using it on an indicator but within that same indicator itself, is this the correct way to us iMAOnArray? Could this be why I am getting a constant value along the whole indicator?

 
MetaNt:

I'm using iMAOnArray and I seem to be getting a straight line.

I'm using it on an indicator but within that same indicator itself, is this the correct way to us iMAOnArray? Could this be why I am getting a constant value along the whole indicator?

Do some searches on the Forum for imaonarray() and you will find plenty of discussion, tick the date box when you do so you see the newest posts first.
 
RaptorUK:
Do some searches on the Forum for imaonarray() and you will find plenty of discussion, tick the date box when you do so you see the newest posts first.


Right thanks, but I recently realised using iMAOnArray was not right for what I was trying to do, due to the nature of my indicator, i'm using iMA instead and I have run into a different issue.

Usually I don't post all my code but I think it may be necessary in this case.

This is my indicator, it's Market Pressure Buy (Downward bias)

It calculates the rate of increase and then determines the rate of the rate of increase by determining the previous rate of increase with the current rate of increase, I have a sell version which does the same but with decrease (in price).

The code itself is incredible simple atm as it is in it's inchoate stage.

//+------------------------------------------------------------------+
//|                       Pressurised Market Buy (Downward Bias).mq4 |
//|                                                       Luciano. E |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Luciano .E"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Green 
double MarketBias[];
double MarketPressure[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,MarketBias);
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,2,Blue);
   SetIndexLabel(0,"MarketBias");
   SetIndexDrawBegin(0,203);   
   SetIndexBuffer(1,MarketPressure);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,2,Green);
   SetIndexLabel(1,"MarketPressure");
   SetIndexDrawBegin(1,202);
   
  
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   int counted_bars=IndicatorCounted();
   if(counted_bars<0)return(-1);
   if(counted_bars>0)counted_bars--;
   int uncountedbars=Bars-counted_bars; 
   
//- ---


for(int i=0;i<uncountedbars;i++)
    
   {
      
      MarketBias[i]   =(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,i+1)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,i+1))/(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,i+2)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,i+2));

   }
   
   
   
for(int j=0;j<uncountedbars;j++)

   {
      
      MarketPressure[j] =(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,j)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,j))/(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,j+1)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,j+1));
   }
      


   return(0);
  }
//+------------------------------------------------------------------+ 
 

The issue I'm having is that only one of the indicators get's drawn, if I blank one out I get data for the other, and if I blank out neither I only get data for the market Bias.

 
//+------------------------------------------------------------------+
//|                       Pressurised Market Buy (Downward Bias).mq4 |
//|                                                       Luciano. E |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Luciano .E"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
//#property indicator_color2 Green 
double MBMPD[];
//double MarketPressure[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,MBMPD);
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,2,Blue);
   SetIndexLabel(0,"Market Bias/Market Pressure Difference");
   SetIndexDrawBegin(0,203);   
   /*SetIndexBuffer(1,MarketPressure);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,2,Green);
   SetIndexLabel(1,"MarketPressure");
   SetIndexDrawBegin(1,202);*/
   
  
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   int counted_bars=IndicatorCounted();
   if(counted_bars<0)return(-1);
   if(counted_bars>0)counted_bars--;
   int uncountedbars=Bars-counted_bars; 
   
//- ---


for(int i=0;i<uncountedbars;i++)
    
   {
      
      MBMPD[i]   =(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,i+1)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,i+1))/(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,i+2)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,i+2))-(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,i)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,i))/(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,i+1)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,i+1));

   }
   
   
   
/*for(int j=0;j<uncountedbars;j++)

   {
      
      MarketPressure[j] =(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,j)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,j))/(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,j+1)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,j+1));
   }*/
      


   return(0);
  }
//+------------------------------------------------------------------+ 

Seems to be a fix.

 

Woops I mean

//+------------------------------------------------------------------+
//|                       Pressurised Market Buy (Downward Bias).mq4 |
//|                                                       Luciano. E |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Luciano .E"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
//#property indicator_color2 Green 
double MBMPD[];
//double MarketPressure[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,MBMPD);
   SetIndexStyle(0,DRAW_LINE,EMPTY,2,Blue);
   SetIndexLabel(0,"Market Bias/Market Pressure Difference");
   SetIndexDrawBegin(0,203);   
   /*SetIndexBuffer(1,MarketPressure);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,2,Green);
   SetIndexLabel(1,"MarketPressure");
   SetIndexDrawBegin(1,202);*/
   
  
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   int counted_bars=IndicatorCounted();
   if(counted_bars<0)return(-1);
   if(counted_bars>0)counted_bars--;
   int uncountedbars=Bars-counted_bars; 
   
//- ---


for(int i=0;i<uncountedbars;i++)
    
   {
      
      MBMPD[i]   =(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,i)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,i))/(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,i+1)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,i+1))-(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,i+1)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,i+1))/(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,i+2)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,i+2));

   }
   
   
   
/*for(int j=0;j<uncountedbars;j++)

   {
      
      MarketPressure[j] =(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,j)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,j))/(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,j+1)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,j+1));
   }*/
      


   return(0);
  }
//+------------------------------------------------------------------+ 
 

This really fixed it.

//+------------------------------------------------------------------+
//|                       Pressurised Market Buy (Downward Bias).mq4 |
//|                                                       Luciano. E |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Luciano .E"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
//#property indicator_color2 Green 
double MBMPD[];
double MarketPressure[];
double MarketBias[];
extern int InPeriod = 20;
double pips;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
  double ticksize = MarketInfo(Symbol(), MODE_TICKSIZE);
  if (ticksize == 0.00001 || ticksize == 0.001)
  pips = ticksize*10;
  else pips =ticksize;
  
   SetIndexBuffer(0,MBMPD);
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,2,Blue);
   SetIndexLabel(0,"Market Bias/Market Pressure Difference");
   SetIndexDrawBegin(0,InPeriod+3);   
   /*SetIndexBuffer(1,MarketPressure);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,2,Green);
   SetIndexLabel(1,"MarketPressure");
   SetIndexDrawBegin(1,202);*/
   
   
  
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   
   int counted_bars=IndicatorCounted();
   if(counted_bars<0)return(-1);
   if(counted_bars>0)counted_bars--;
   int uncountedbars=Bars-counted_bars; 
   
//- ---


for(int i=0;i<uncountedbars;i++)
    
   {
      if((iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+1)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+1))/(iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+2)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+2))<1 && (iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+1)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+1))<1)
      MBMPD[i]   =(iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i))/1*pips/1*pips;

else  if((iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+1)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+1))/(iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+2)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+2))>=1 && (iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+1)-iMA(NULL,0,InPeriod, 0,MODE_SMMA,PRICE_OPEN,i+1))<1)
      MBMPD[i]   =(iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i))/1*pips/(iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+1)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+1))/(iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+2)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+2));

else if((iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+1)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+1))/(iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+2)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+2))<1 && (iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+1)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+1))>=1)
      MBMPD[i]   =(iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i))/(iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+1)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+1))/(iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_CLOSE,i+1)-iMA(NULL,0,InPeriod,0,MODE_SMMA,PRICE_OPEN,i+1))/1*pips;
   }
   
    
   
/*for(int j=0;j<uncountedbars;j++)

   {
      
      MarketPressure[j] =(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,j)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,j))/(iMA(NULL,0,200,0,MODE_SMMA,PRICE_HIGH,j+1)-iMA(NULL,0,200,0,MODE_SMMA,PRICE_OPEN,j+1));
   }*/
      


   return(0);
  }
//+------------------------------------------------------------------+ 
Reason: