cind_MA_RSI_MACD_v_7

Author: Aleksei Parvatkin, 22/05/2009
Indicators Used
MACD Histogram
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
cind_MA_RSI_MACD_v_7
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "Aleksei Parvatkin, 22/05/2009"
#property link      "alexpar@list.ru"



#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 CLR_NONE
#property indicator_color2 CLR_NONE
#property indicator_color3 DeepSkyBlue
#property indicator_color4 Red
#property indicator_color5 DeepSkyBlue
#property indicator_color6 Red
#property indicator_color7 Goldenrod

#property indicator_width3 0
#property indicator_width4 0
#property indicator_width5 1
#property indicator_width6 1

//---- input parameters
extern int       RSIPeriod=5;
extern int       MAPeriod=5;

extern bool TwoBar=true;      // Ïðîâåðÿòü ïåðåãèá ïî äâóì áàðàì (ñëåâà îò ýêñòðåìóìà, ñïðàâà âñåãäà ïî îäíîì áàðó)

//---- buffers
double macd_m[];
double macd_s[];
double ma_rsi1[];
double ma_rsi2[];
double buy[];
double sell[];
double buy1[];
double sell1[];
double close[];
double cnt[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   IndicatorBuffers(8);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ma_rsi1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ma_rsi2);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,225);
   SetIndexBuffer(2,buy);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,226);
   SetIndexBuffer(3,sell);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,233);
   SetIndexBuffer(4,buy1);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,234);
   SetIndexBuffer(5,sell1);

   SetIndexStyle(6,DRAW_ARROW);
   SetIndexArrow(6,251);
   SetIndexBuffer(6,close);
   SetIndexBuffer(7,cnt);

   SetIndexLabel(0,"Fast MA");
   SetIndexLabel(1,"Slow MA");
   SetIndexLabel(2,"");
   SetIndexLabel(3,"");
   SetIndexLabel(4,"");
   SetIndexLabel(5,"");
   SetIndexLabel(6,"");

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=4;

   ArrayResize(macd_m,ArraySize(buy));
   ArrayResize(macd_s,ArraySize(buy));

   for(int i=limit-1;i>=0;i--)
     {
      buy[i]=EMPTY_VALUE;
      sell[i]=EMPTY_VALUE;
      ma_rsi1[i]=iCustom(NULL, 0, "MA_RSI",RSIPeriod,0,MAPeriod,PRICE_CLOSE,i);
      ma_rsi2[i]=iCustom(NULL, 0, "MA_RSI",RSIPeriod,0,MAPeriod,PRICE_CLOSE,i+1);
      macd_m[i]=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i);
      macd_s[i]=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i);
      cnt[i]=cnt[i+1];
      buy1[i]=EMPTY_VALUE;
      sell1[i]=EMPTY_VALUE;
      close[i]=EMPTY_VALUE;
      if(ma_rsi1[i]>ma_rsi2[i])
        {

         if(ma_rsi1[i+1]<=ma_rsi2[i+1] && macd_m[i+1]>macd_s[i+1])
           {
            close[i]=Low[i]-Point*7;
           }

         if(ma_rsi1[i+3]>ma_rsi1[i+2] || !TwoBar)
           {
            if(ma_rsi1[i+2]>ma_rsi1[i+1])
              {
               if(ma_rsi1[i+1]<ma_rsi1[i])
                 {
                  buy[i]=Low[i]-Point*5;
                  if(cnt[i]<0)
                    {
                     cnt[i]=0;
                    }
                  cnt[i]++;
                  if(cnt[i]==1)
                    {
                     buy1[i]=Low[i]-Point*5;
                    }
                 }
              }
           }
        }

      if(ma_rsi1[i]<ma_rsi2[i])
        {

         if(ma_rsi1[i+1]>=ma_rsi2[i+1] && macd_m[i+1]<macd_s[i+1])
           {
            close[i]=High[i]+Point*7;
           }

         if(ma_rsi1[i+3]<ma_rsi1[i+2] || !TwoBar)
           {
            if(ma_rsi1[i+2]<ma_rsi1[i+1])
              {
               if(ma_rsi1[i+1]>ma_rsi1[i])
                 {
                  sell[i]=High[i]+Point*5;
                  if(cnt[i]>0)
                    {
                     cnt[i]=0;
                    }
                  cnt[i]--;
                  if(cnt[i]==-1)
                    {
                     sell1[i]=High[i]+Point*5;
                    }
                 }
              }
           }
        }

     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---