Pip distance from MA coding problem.

 
#property strict
#property indicator_chart_window

#property indicator_buffers 5

//---Indicator Colours
#property indicator_color1 clrGreen//UpArrow
#property indicator_color2 clrRed//DownArrow
#property indicator_color3 clrRed//EMA50
#property indicator_color4 clrBlue//EMA120


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


#include <WinUser32.mqh>
double pips;

extern bool show=true;//Show Indicators?
extern int PipRange=0;

double UpArrow[];
double DownArrow[];
double EMA50[];
double EMA120[];
//+------------------------------------------------------------------+
//| 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,EMA50);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexLabel(2,"EMA50.");
//--- 
   SetIndexBuffer(3,EMA120);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexLabel(3,"EMA120.");

   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 MA50=iMA(NULL,0,50,0,MODE_EMA,PRICE_MEDIAN,i);
      double MA120=iMA(NULL,0,120,0,MODE_EMA,PRICE_MEDIAN,i);
      double RSI=iRSI(NULL,0,14,PRICE_MEDIAN,i);
      double RSIBack=iRSI(NULL,0,14,PRICE_MEDIAN,i+1);
      double RSIBack1=iRSI(NULL,0,14,PRICE_MEDIAN,i+2);
      double PriceHigh=(High[i]);
      //---
      if(show==true)
        {
         EMA50[i]=MA50;
         EMA120[i]=MA120;
        }
      //if(MA50>MA120)
         if((PriceHigh-PipRange*pips)<MA120)
            //if(RSIBack<30)
              {
               UpArrow[i]=Open[i];
              }
      if(MA50<MA120)
         if(RSIBack>70)
           {
            DownArrow[i]=Open[i];
           }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
if((PriceHigh-PipRange*pips)<MA120)
 

I am trying to simply get an up arrow to draw if the price high of the bar is below MA120 by n pips. However I do not get the results I wish for !!

Can somebody please suggest a coding fix?

Regards Mickey. 

 
mickeyferrariif the price high of the bar is below MA120 by n pips. However I do not get the results I wish for !!
if((PriceHigh-PipRange*pips)<MA120)
You have high is below MA + n pips
if(PriceHigh < MA120 + PipRange*pips) // rewritten.
Code it exactly how you stated
 if(PriceHigh < MA120 -PipRange*pips) // high is below n pips
 
Thanks WH I see the logic !! Happy Easter:)
Reason: