Coding Help Please ! Pip range away from median MA's

 
#property strict
#property indicator_chart_window

#property indicator_buffers 5


//---Indicator Colours
#property indicator_color1 clrGreen//up arrow
#property indicator_color2 clrRed//down arrow
#property indicator_color3 clrCrimson//SMA10
#property indicator_color4 clrNavy//SMA25
#property indicator_color5 clrWhite//SMA100


//---Indicator Width
#property indicator_width1 2
#property indicator_width2 2

#include <WinUser32.mqh>
extern bool show=true;//Show Indicators?
extern double PipRange=25;//Above/Below MidMArange
double pips;

double UpArrow[];
double DownArrow[];
double SMA10[];
double SMA25[];
double SMA100[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   pips=Point; //.00001 or .0001. .001 .01.
   if(Digits==3 || Digits==5)
      pips*=10;

//--- indicator buffers mapping
   SetIndexBuffer(0,UpArrow);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexLabel(0,"Buy Signal.");
//---
   SetIndexBuffer(1,DownArrow);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexLabel(1,"Sell Signal.");
//---
   SetIndexBuffer(2,SMA10);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexLabel(2,"SMA10.");
//---
   SetIndexBuffer(3,SMA25);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexLabel(3,"SMA25.");
//---
   SetIndexBuffer(4,SMA100);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexLabel(4,"SMA100.");

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---for loop
   int counted_bars=IndicatorCounted();
   int limit= Bars-counted_bars;
   for(int i=1;i<limit;i++)
     {
      double fasterMA=iMA(NULL,0,10,0,MODE_SMA,PRICE_MEDIAN,i);
      double fasterMAback1=iMA(NULL,0,10,0,MODE_SMA,PRICE_MEDIAN,i+1);
      double fasterMAback2=iMA(NULL,0,10,0,MODE_SMA,PRICE_MEDIAN,i+2);
      double fasterMAback3=iMA(NULL,0,10,0,MODE_SMA,PRICE_MEDIAN,i+3);
      double fasterMAback4=iMA(NULL,0,10,0,MODE_SMA,PRICE_MEDIAN,i+4);
      double fasterMAback5=iMA(NULL,0,10,0,MODE_SMA,PRICE_MEDIAN,i+5);
      double fasterAverage=(fasterMAback1+fasterMAback2+fasterMAback3+fasterMAback4+fasterMAback5)/5;
      //---
      double mediumMA=iMA(NULL,0,25,0,MODE_SMA,PRICE_MEDIAN,i);
      double mediumMAback1=iMA(NULL,0,25,0,MODE_SMA,PRICE_MEDIAN,i+1);
      double mediumMAback2=iMA(NULL,0,25,0,MODE_SMA,PRICE_MEDIAN,i+2);
      double mediumMAback3=iMA(NULL,0,25,0,MODE_SMA,PRICE_MEDIAN,i+3);
      double mediumMAback4=iMA(NULL,0,25,0,MODE_SMA,PRICE_MEDIAN,i+4);
      double mediumMAback5=iMA(NULL,0,25,0,MODE_SMA,PRICE_MEDIAN,i+5);
      double mediumAverage=(mediumMAback1+mediumMAback2+mediumMAback3+mediumMAback4+mediumMAback5)/5;
      //---
      double slowerMA=iMA(NULL,0,100,0,MODE_SMA,PRICE_MEDIAN,i);
      double slowerMAback1=iMA(NULL,0,100,0,MODE_SMA,PRICE_MEDIAN,i+1);
      double slowerMAback2=iMA(NULL,0,100,0,MODE_SMA,PRICE_MEDIAN,i+2);
      double slowerMAback3=iMA(NULL,0,100,0,MODE_SMA,PRICE_MEDIAN,i+3);
      double slowerMAback4=iMA(NULL,0,100,0,MODE_SMA,PRICE_MEDIAN,i+4);
      double slowerMAback5=iMA(NULL,0,100,0,MODE_SMA,PRICE_MEDIAN,i+5);
      double slowerAverage=(slowerMAback1+slowerMAback2+slowerMAback3+slowerMAback4+slowerMAback5)/5;
      //---Filters
      double MidMArange=(fasterMA+mediumMA)/2;
      //--
      double Price=(High[i]+Low[i])/2;
      double PriceBack=(High[i+1]+Low[i+1])/2;
      double PriceHigh=(High[i]);
      double PriceHighBack=(High[i+1]);
      double PriceLow=(Low[i]);
      double PriceLowBack=(Low[i+1]);
      //---
      if(show==true)
        {
         SMA10[i]=fasterMA;
         SMA25[i]=mediumMA;
         SMA100[i]=slowerMA;
        }
      //---
      if(fasterMA>mediumMA && mediumMA>slowerMA && fasterMA>slowerMA)
      if(Price-PipRange*pips <=MidMArange)
         //if(fasterMA>fasterAverage && mediumMA>mediumAverage && slowerMA>slowerAverage)
         //if(fasterMA<fasterAverage && mediumMA>mediumAverage && slowerMA>slowerAverage)
         //if(fasterMA<fasterAverage && mediumMA<mediumAverage && slowerMA>slowerAverage)
        {
         UpArrow[i]=Open[i];
        }
      //---
      if(fasterMA<mediumMA && mediumMA<slowerMA && fasterMA<slowerMA)
      if(Price+PipRange*pips >=MidMArange)
         //if(fasterMA<fasterAverage && mediumMA<mediumAverage && slowerMA<slowerAverage)
         //if(fasterMA>fasterAverage && mediumMA<mediumAverage && slowerMA<slowerAverage)
         //if(fasterMA>fasterAverage && mediumMA>mediumAverage && slowerMA<slowerAverage)
        {
         DownArrow[i]=Open[i];
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Hi fellow coders, 

I am stuck on this, I want identify when the Price is below or above the fast and mid MA range by x pips and then draw an up or down arrow in the direction of the trend in accordance with above if statement.

I believe I have coded it OK but can't find the glitch!! 

Any help with a fix would be appreciated.

Thanks Mickey. 

 

it compiles ok !!

 
mickeyferrari: , I want identify when the Price is below or above the fast and mid MA range by x pips and then draw an up
I believe I have coded it OK but can't find the glitch!!
  1. What glitch? There are no mind readers here.
  2. double slowerMAback5=iMA(NULL,0,100,0,MODE_SMA,PRICE_MEDIAN,i+5);
    Your maximum look back is 100 - 1 + 5. Do your lookbacks correctly.
  3.   if(Price-PipRange*pips <=MidMArange)
    You said you want to identify when price is above the MA by x pips. Then code it that way. You should be able to read the code out loud and it should make reasonable good English. If it doesn't make it so.
      if(Price > MidMArange + PipRange*pips)
    Your code makes an arrow when it is less than x pips

  4. if(fasterMA>mediumMA && mediumMA>slowerMA && fasterMA>slowerMA)
    Redundant tests.
 
Thanks WHRoeder for the fresh eye's
Reason: