Quantative indicator HELP to write in mql4 code

 

I created the indicator below in metastock and i call it Rullet. It shows the percent of bars, in the last N bars, that close below and above a simple moving average x periods.

In the picture below you can see the percent of the last 12 bars that closed below and above 200 periods simple moving average in EURUSD 1hour time frame.

I would like some help so i can plot it on metatrader 4 as a custom mql4 indicator. I don't know mql4 but i have knowledge of metastock. I beleive that it is a power tool.

Thank you at advance and hope any one who can write it in mql4 sent me the code at goldeaglefu@yahoo.gr or answer. I must say that i have many tools so i would like to coοparate with someone to create a trading system very profitable.


 

Hope the following helps. Maybe it's even correct ;-)

//+------------------------------------------+
//|                              Rullett.mq4 |
//+------------------------------------------+
#property  copyright "Copyright © 2011, Brewmanz, but feel free to modify & use"
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Green
#property  indicator_color2  Red
#property  indicator_width1  1
#property  indicator_width2  1
#property  indicator_style1  STYLE_SOLID
#property  indicator_style2  STYLE_SOLID
#property  indicator_level1  0.0

//---- indicator parameters
extern int MAPeriods=200;
extern int LastNBars=12;
extern int MAMode_0SmaEmaSmmaLwma3=MODE_SMA;
extern int MAPrice_0COHLMedTypWgt6=PRICE_CLOSE;
extern int BarPrice_0COHLMedTypWgt6=PRICE_CLOSE;
//---- indicator buffers
double     BufferAboveHalf[];
double     BufferBelowHalf[];
double     BufferTrackAboveOrBelow[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorDigits(Digits);
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_NONE);
   SetIndexDrawBegin(0,LastNBars);
   SetIndexDrawBegin(1,LastNBars);
//---- indicator buffers mapping
   SetIndexBuffer(0,BufferAboveHalf);
   SetIndexBuffer(1,BufferBelowHalf);
   SetIndexBuffer(2,BufferTrackAboveOrBelow);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Rullett(" + LastNBars + "/" +  MAPeriods + ")");
   SetIndexLabel(0,"AboveHalf");
   SetIndexLabel(1,"BelowHalf");
   SetIndexLabel(2,"A/B");
   
//---- initialization done
   return(0);
  }
//+-------------------------------------------------+
//| Rullett - how of last N bars are above MA line? |
//+-------------------------------------------------+
int start()
  {
   int ixLimit, ix;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) 
      counted_bars--;
   ixLimit=Bars-counted_bars-1;
   // track above or below array
   for(ix=ixLimit; ix>=0; ix--)
   {
      double myMA = iMA(NULL, 0, MAPeriods, 0, MAMode_0SmaEmaSmmaLwma3, MAPrice_0COHLMedTypWgt6, ix);
      double myPrice = iMA(NULL, 0, 1, 0, MODE_SMA, BarPrice_0COHLMedTypWgt6, ix);  // cheat to get unknown type of Price
      double ab;
      if(myPrice > myMA)
         ab = 1;
      else if(myPrice < myMA)
         ab = -1;
      else
         ab = 0;
      
      BufferTrackAboveOrBelow[ix] = ab * LastNBars; // * LastNBars to scale to N bars.
   }
   // plot wanted value from MA of tracker buff
   for(ix=ixLimit; ix>=0; ix--)
   {
      double myABMA = iMAOnArray(BufferTrackAboveOrBelow, 0, LastNBars, 0, MODE_SMA, ix);
      BufferBelowHalf[ix] = 0;
      BufferAboveHalf[ix] = 0;
      if(myABMA > 0)
         BufferAboveHalf[ix] = myABMA;
      else
         BufferBelowHalf[ix] = myABMA;
   }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
 
Good code but it would be more usefull if i could see the persent of bars above and below the moving average at the same time. For example if 5 bars are above the 10 period moving average and 5 bars below 10 period moving average the result would be +50% and -50%. If 2 bars are above the 10 period moving average and 8 bars below 10 period moving average the result would be +20% and -80% at the same time in the histogram. I would like to see it as percent above and below 0 so i can see the limit of 50 and -50 as a level with a line. Thank anyway.
Reason: