i-RSICandleOverBought-Sold

Author: Copyright � 2007, Christof Risch (iya)
Indicators Used
Relative strength index
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
i-RSICandleOverBought-Sold
//+------------------------------------------------------------------+
//|                                 Stoch Candle OverBought-Sold.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//|                                                 StochCandles.mq4 |
//| Colored Candles, based on Stochastic Signal.							|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Christof Risch (iya)"
#property link      "http://www.forexfactory.com/showthread.php?t=13321"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3

//#property indicator_color5 Orange
//#property indicator_color6 Orange
//#property indicator_color7 Orange
//#property indicator_color8 Orange
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 3
#property indicator_width8 3

//---- stoch settings
extern double   RSI_Period=14,
RSI_UpLevel    = 70,
RSI_DownLevel  = 30;


//---- input parameters
extern color   BarUp=Green,
BarDown         = Red,
BullCandle      = Green,
BearCandle      = Red;
//BarUp2			= Orange,
//BarDown2			= Orange,
//MedCandle      = Orange,
//MedCandle2     = Orange;
extern int      BarWidth=1,
CandleWidth=3,
BarWidth2      = 1,
CandleWidth2   = 3;

//---- buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
//double Buffer5[];
//double Buffer6[];
//double Buffer7[];
//double Buffer8[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM,0,BarWidth,BarUp);
   SetIndexStyle(1,DRAW_HISTOGRAM,0,BarWidth,BarDown);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,CandleWidth,BullCandle);
   SetIndexStyle(3,DRAW_HISTOGRAM,0,CandleWidth,BearCandle);
   SetIndexBuffer(0,Buffer1);
   SetIndexBuffer(1,Buffer2);
   SetIndexBuffer(2,Buffer3);
   SetIndexBuffer(3,Buffer4);
   return(0);
  }

//+------------------------------------------------------------------+
double RSI(int i=0) {return(iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i));}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void SetBullCandle(int i=0)
  {
   Buffer1[i] = High[i];
   Buffer2[i] = Low[i];
   Buffer3[i] = MathMax(Open[i],Close[i]);
   Buffer4[i] = MathMin(Open[i],Close[i]);
  }
//+------------------------------------------------------------------+
void SetBearCandle(int i=0)
  {
   Buffer1[i] = Low[i];
   Buffer2[i] = High[i];
   Buffer3[i] = MathMin(Open[i],Close[i]);
   Buffer4[i] = MathMax(Open[i],Close[i]);
  }
//+------------------------------------------------------------------+
//| 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--;

   for(int i=limit; i>=0; i--)
     {
      double   rsi=RSI(i);

      bool      bull=((rsi<RSI_DownLevel)),
      bear =((rsi>RSI_UpLevel)),
      Med=((rsi<RSI_UpLevel) && (rsi>RSI_DownLevel));

      if(!bull && !bear && !Med)
        {
         bull = ((rsi<RSI_DownLevel));
         bear = ((rsi>RSI_UpLevel));
         Med=((rsi<RSI_UpLevel) && (rsi>RSI_DownLevel));
        }

      if(bull) SetBullCandle(i);
      else if(bear) SetBearCandle(i);

     }

   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 ---