Download MetaTrader 5
To add comments, please log in or register
You sell neither signals nor apps? No problem, everyone can make profit!
tonjangz
6
tonjangz 2015.11.23 19:57 

#property indicator_buffers 2
#property indicator_color1 SeaGreen
#property indicator_color2 Red

double CrossUp[];
double CrossDown[];
extern int FasterEMA = 4;
extern int SlowerEMA = 8;
extern int RSI_Period = 13;         //8-25
extern int RSI_Price = 0;           //0-6
extern int Volatility_Band = 34;    //20-40
extern int RSI_Price_Line = 2;      
extern int RSI_Price_Type = 0;      //0-3
extern int Trade_Signal_Line = 7;   
extern int Trade_Signal_Type = 0;   //0-3
extern bool SoundON=true;
double alertTag;
 double control=2147483647;
 double RSIBuf[],UpZone[],MdZone[],DnZone[],MaBuf[],MbBuf[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY,3);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY,3);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
  double MA,RSI[];
   double Range, AvgRange;
   ArrayResize(RSI,Volatility_Band);
   int counted_bars=IndicatorCounted();
   int limit = Bars-counted_bars-1;
   int counter;
   
   for(int i=limit; i>=0; i--)
   {
        counter=i;
        Range=0;
        AvgRange=0;
        RSIBuf[i] = (iRSI(NULL,0,RSI_Period,RSI_Price,i)); 
        MA = 0;
        for(int x=i; x<i+Volatility_Band; x++) 
        {
            RSI[x-i] = RSIBuf[x];
            MA += RSIBuf[x]/Volatility_Band;
        }
        UpZone[i] = (MA + (1.6185 * StDev(RSI,Volatility_Band)));
        DnZone[i] = (MA - (1.6185 * StDev(RSI,Volatility_Band)));  
        MdZone[i] = ((UpZone[i] + DnZone[i])/2);
    }
    
    for (i=limit-1;i>=0;i--)  
    {
        MaBuf[i] = (iMAOnArray(RSIBuf,0,RSI_Price_Line,0,RSI_Price_Type,i));
        MbBuf[i] = (iMAOnArray(RSIBuf,0,Trade_Signal_Line,0,Trade_Signal_Type,i));   
    } 
      
      if ((MaBuf[i] > MbBuf[i]) && (MaBuf[i+1] < MbBuf[i+1] )) {
         CrossUp[i] = Low[i] - Range*0.5;
      }
      else if((MaBuf[i] < MbBuf[i]) && (MaBuf[i+1] > MbBuf[i+1] )) {
          CrossDown[i] = High[i] + Range*0.5;
      }
        
  }

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)));
}

I can pass compile but it don't show arrow.i want to make arrow from tdi cross. thank you ^_^
Keith Watford
Moderator
8015
Keith Watford 2015.11.23 20:08  
 double RSIBuf[],UpZone[],MdZone[],DnZone[],MaBuf[],MbBuf[];
You do not size these arrays, so you will get an array out of range error
Jaroslav Suska
14
Jaroslav Suska 2015.11.23 20:40  

It is still pretty "messi" but it works.

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 SeaGreen
#property indicator_color2 Red

double CrossUp[];
double CrossDown[];
extern int FasterEMA = 4;
extern int SlowerEMA = 8;
extern int RSI_Period = 13;         //8-25
extern int RSI_Price = 0;           //0-6
extern int Volatility_Band = 34;    //20-40
extern int RSI_Price_Line = 2;      
extern int RSI_Price_Type = 0;      //0-3
extern int Trade_Signal_Line = 7;   
extern int Trade_Signal_Type = 0;   //0-3
extern bool SoundON=true;
double alertTag;
 double control=2147483647;
 double RSIBuf[],UpZone[],MdZone[],DnZone[],MaBuf[],MbBuf[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  IndicatorBuffers(5);
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY,1);
   //SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 3, Red);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY,1);
   //SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 3, Lime);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
   
   SetIndexBuffer(2, RSIBuf);
   SetIndexBuffer(3, MaBuf);
   SetIndexBuffer(4, MbBuf);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
  double MA,RSI[];
   double Range, AvgRange;
   ArrayResize(RSI,Volatility_Band);
   int counted_bars=IndicatorCounted();
   int limit = Bars-counted_bars-1;
   int counter;
   
   for(int i=limit; i>=0; i--)
   {
        counter=i;
        Range=0;
        AvgRange=0;
        RSIBuf[i] = iRSI(NULL,0,RSI_Period,RSI_Price,i); 
        //MA = 0;
        //for(int x=i; x<i+Volatility_Band; x++) 
        //{
        //    RSI[x-i] = RSIBuf[x];
        //    MA += RSIBuf[x]/Volatility_Band;
        //}
        //UpZone[i] = (MA + (1.6185 * StDev(RSI,Volatility_Band)));
        //DnZone[i] = (MA - (1.6185 * StDev(RSI,Volatility_Band)));  
        //MdZone[i] = ((UpZone[i] + DnZone[i])/2);
        
    }
    
    for (i=limit-1;i>=0;i--)  
    {
        MaBuf[i] = (iMAOnArray(RSIBuf,0,RSI_Price_Line,0,RSI_Price_Type,i));
        MbBuf[i] = (iMAOnArray(RSIBuf,0,Trade_Signal_Line,0,Trade_Signal_Type,i));   
    //} 
      if ((MaBuf[i] > MbBuf[i]) && (MaBuf[i+1] < MbBuf[i+1] )) {
         CrossUp[i] = Low[i] - Range*0.5;
      }
      else if((MaBuf[i] < MbBuf[i]) && (MaBuf[i+1] > MbBuf[i+1] )) {
          CrossDown[i] = High[i] + Range*0.5;
      }
    }
        
  }

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)));
}
/
To add comments, please log in or register