[Solved] Help in modifying a price ratio indicator

 
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 5
#property  indicator_color1  Aqua
#property  indicator_color2  Lime
#property  indicator_color3  Red
#property  indicator_color4  Maroon
#property  indicator_color5  Maroon
#property  indicator_width1  2


//---- indicator parameters
extern string Security        = "EURUSD";
extern int    SignalMethod   = MODE_EMA;
extern int    SignalSMA      = 13;
extern int    SignalSMA2     = 34;
extern int    BandsPeriod    = 20;
extern int    BandsDeviation = 2;

//
double SDCDBuffer[];
double SignalBuffer[];
double SignalBuffer2[];
double SignalBuffer3[];
double SignalBuffer4[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{

   SetIndexBuffer(0,SDCDBuffer);   SetIndexLabel(0,"SDCD");
   SetIndexBuffer(1,SignalBuffer); SetIndexLabel(1,"Signal");
   SetIndexBuffer(2,SignalBuffer2);SetIndexLabel(2,"Signal2");
   SetIndexBuffer(3,SignalBuffer3);SetIndexLabel(2,"Signal3");
   SetIndexBuffer(4,SignalBuffer4);SetIndexLabel(2,"Signal4");
//
   IndicatorShortName("ONE:"+Security+" ("+SignalSMA+","+SignalSMA2+")");
   return(0);
  }
 
//+------------------------------------------------------------------+
//| Custom Initialization Function                        |
//+------------------------------------------------------------------+

int start()
{
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = MathMin(Bars-counted_bars,Bars-1);
   //
   //
   //
   //
   //
      
   for(i=limit; i>=0; i--) SDCDBuffer[i] = 1 / MathMax(iMA(Security,0,1,0,MODE_EMA,PRICE_CLOSE,i),Point);              
   for(i=limit; i>=0; i--)
   {
       SignalBuffer[i]  = iMAOnArray(SDCDBuffer,Bars,SignalSMA, 0,SignalMethod,i);

       SignalBuffer2[i] = iMAOnArray(SDCDBuffer,Bars,SignalSMA2,0,SignalMethod,i);

// Note to the Programmer: I am looking for a plot of "SignalBuffer[i] minus SignalBuffer2[i] minus" in two colored histogram.   
       SignalBuffer3[i] = iBandsOnArray(SDCDBuffer,0,BandsPeriod, BandsDeviation,0,MODE_LOWER,i);

       SignalBuffer4[i] = iBandsOnArray(SDCDBuffer,0,BandsPeriod, BandsDeviation,0,MODE_UPPER,i);

// Note to the Programmer: Current display option for the inverse, MA, and BB can be eliminated, if these interfere with proper display of histogram.
   }
     
   return(0);
  }
//+------------------------------------------------------------------+

I have an indicator which allows me to plot inverse of any price. In addition to plotting the inverse, it also computes two moving average of the inverse and draws Bollinger's Bands. I use MA crosses to identify change in trend. Currently I manually check for the cross. I need your help to modify it so it will make identification of the cross easier (manually) and mark such an event automatically on the price chart.

Please help me to modify the code below so it will:

1. Display the difference of two moving averages as histogram in two different colors (much like two color MACD).

2. Draw an up/down arrow on the price chart whenever the histogram crosses up/down the zero line.

Thanks in advance . Here is the original code.

 
Harapa: Please help me to modify the code below so it will:
  1. Use SRC
  2. Since there are no slaves here, there are only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.
 
RaptorUK:
Please edit your post . . . or have your code removed


Please use this to post code . . . it makes it easier to read.


Thanks for the advice. I edited my original post.
 
Harapa:
Thanks for the advice. I edited my original post.

Thank you :-)
 

So I re-did the code. Now it does exactly what I wanted to do. In doing this I re-learned that it is more fun to solve a puzzle than look for its answer;you enjoy few moments of glory plus you keep your respect.

So for newbies, this indicator calculates inverse of any instrument (user defined), and plots difference of two moving averages as two colored (user selected) histogram. There are few other ways to use this indicator as well, I will update you with those options as soon as I have them ready.

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Aqua
#property  indicator_color2  Lime
#property  indicator_color3  Red
#property  indicator_width1  2
#property  indicator_width2  2
#property  indicator_width3  2

//---- indicator parameters

extern string Instrument     = "EURUSD";
extern int    SignalMethod = MODE_EMA;
extern int    Fast_MA      = 34;
extern int    Slow_MA      = 89;

//----indicator buffers
double HistoBuffer[];
double HistoBufferHup[];
double HistoBufferHdn[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators setting
    SetIndexBuffer(0, HistoBuffer);
    SetIndexBuffer(1, HistoBufferHup);
    SetIndexBuffer(2, HistoBufferHdn);
//----
    SetIndexStyle(0, DRAW_LINE);
    SetIndexStyle(1, DRAW_HISTOGRAM);
    SetIndexStyle(2, DRAW_HISTOGRAM); 

//
   IndicatorShortName("MACD ONE:"+Instrument+" ("+Fast_MA+","+Slow_MA+")");
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                       |
//+------------------------------------------------------------------+

int start()
{{
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = MathMin(Bars-counted_bars,Bars-1);
   //
   //
   //
      
   for(i=limit; i>=0; i--) HistoBuffer[i] = 1 / MathMax(iMA(Instrument,0,1,0,MODE_EMA,PRICE_CLOSE,i),Point);              
   for(i=limit; i>=0; i--)
   {
       HistoBuffer[i]  = iMAOnArray(HistoBuffer,Bars,Fast_MA, 0,SignalMethod,i) - iMAOnArray(HistoBuffer,Bars,Slow_MA,0,SignalMethod,i);
              
       if(HistoBuffer[i] >= 0)
           HistoBufferHup[i] = HistoBuffer[i];
       else
           HistoBufferHup[i] = 0;   
       //----
       if(HistoBuffer[i] < 0 )
           HistoBufferHdn[i] = HistoBuffer[i];
       else
           HistoBufferHdn[i] = 0;
    }   
     
//---- done
   return(0);
}
}
//---------------------
Reason: