View Single Post
  #7 (permalink)  
Old 09-18-2006, 05:04 AM
accrete's Avatar
accrete accrete is offline
Member
 
Join Date: Jan 2006
Location: The WET! Coast of Oregon, USA
Posts: 69
accrete is on a distinguished road
Question CG...Can this work??

Greetings all.

Ahamed, i read your article (and am going through your course, great info!)

[i wanted to add this PostScript as LowPhat figured it out and added his post w/the correction. Thank you all.]

I followed the directions in your article posted above on placing an MA on an indicator. I known that this code i've posted below is very, very close. Is it possible to point out what needs to be tweaked for the MA to show up? There are no errors listed, but i'm not seeing the moving average of the RSI. I wanted to use it as a signal line. I was able to add a second set of Bollinger Bands, and also place a second RSI line drawn in dots for use as a visual on candle close...Then the signal line was going to be based on the RSI. . .I know it is something simple i'm missing.

The signal buffer i named : "SignalMABuf", and also have an extern named "SignalMAPeriod" in case one wishes to change the MA period.

The line of code i inserted thanks to your article is this:

SignalMABuf[i]=iMAOnArray(RSIBuf,0,SignalMAPeriod,0,MODE_EMA,i);


Thanks in advance for your time and insights : )

: ) Thom

Here is the whole code:

Code:
/*+---------------------------------------------------------------------------------+
  | Original file from Dynamic Zone RSI.mq4 polk@alba.dp.ua  © 2005, Pavel Kulko    |
  |  Modyfied with Dual BBands, RSI Reversal Indicator Dots & Signal Line           |
  |  By Accrete at accrete.com c2006   Dynamic Zone RSI DualBBtrigger               |
  +---------------------------------------------------------------------------------+
*/
#property copyright "Copyright © 2005, Pavel Kulko"
#property link      "polk@alba.dp.ua"
#property indicator_buffers 7
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_color6 Aqua
#property indicator_color7 Yellow

#property indicator_separate_window

extern int RSIPeriod = 8;
extern int SignalMAPeriod=8;
extern int BandPeriod = 21;

double RSIBuf[],UpZone[],DnZone[],UpZonei[],DnZonei[],RSIBufdot[],SignalMABuf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,RSIBuf);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,UpZone);
      
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,DnZone);
   
   SetIndexStyle(3,DRAW_LINE,2,1);
   SetIndexBuffer(3,UpZonei);
      
   SetIndexStyle(4,DRAW_LINE,2,1);
   SetIndexBuffer(4,DnZonei);
          
   SetIndexStyle(5,DRAW_ARROW, EMPTY);
   SetIndexArrow(5,115);
   SetIndexBuffer(5,RSIBufdot);
   
   SetIndexStyle(6,DRAW_LINE,2,1);
   SetIndexBuffer(6,SignalMABuf);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double MA, RSI[];
   ArrayResize(RSI,BandPeriod);
   int counted_bars=IndicatorCounted();
   int limit = Bars-counted_bars-1;
   for(int i=limit; i>=0; i--)
   {
      RSIBuf[i] = iRSI(NULL,0,RSIPeriod,MODE_CLOSE,i);
      MA = 0;
      for(int j=i; j<i+BandPeriod; j++) {
         RSI[j-i] = RSIBuf[j];
         MA += RSIBuf[j]/BandPeriod;
      }
         {
      RSIBufdot[i] = iRSI(NULL,0,RSIPeriod,MODE_CLOSE,i);
      }
      UpZone[i] = MA + (1.3185 * StDev(RSI,BandPeriod));
      DnZone[i] = MA - (1.3185 * StDev(RSI,BandPeriod));
      UpZonei[i] = MA + (0.68 * StDev(RSI,BandPeriod));
      DnZonei[i] = MA - (0.68 * StDev(RSI,BandPeriod));   
   }
            {
      SignalMABuf[i]=iMAOnArray(RSIBuf,0,SignalMAPeriod,0,MODE_EMA,i);

      }
   
//----
   return(0);
  }
  
double StDev(double& Data[], int Per)
{
  return(MathSqrt(Variance(Data,Per)));
}

double Variance(double& Data[], int Per)
{
  double sum, ssum;
  for (int i=0; i<Per; i++)
  {
    sum += Data[i];
    ssum += MathPow(Data[i],2);
  }
  return((ssum*Per - sum*sum)/(Per*(Per-1)));
}
//+------------------------------------------------------------------+
__________________
Find a way to make someone's day

Last edited by accrete; 09-18-2006 at 09:27 PM.
Reply With Quote