//+------------------------------------------------------------------+
//| RSI_Bollinger_EMA_System_v2.mq4 |
//| Copyright 2023, ForexBee |
//| https://www.forexbee.ir |
//+------------------------------------------------------------------+
#property strict
#property indicator_chart_window
#property indicator_buffers 5 // بافر5 :تصحیح شده
#property indicator_color1 clrGreen // Buy Signal
#property indicator_color2 clrRed // Sell Signal
#property indicator_color3 clrBlue // EMA
#property indicator_color4 clrLime // Upper BB
#property indicator_color5 clrTomato // Lower BB
// Inputs
input int RSI_Period = 7;
input int BB_Period = 20;
input double BB_Deviation = 2.0;
input int EMA_Period = 9;
// Buffers
double BuySignal[];
double SellSignal[];
double EMA[];
double UpperBB[];
double LowerBB[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, BuySignal);
SetIndexStyle(0, DRAW_ARROW, EMPTY, 2, clrGreen);
SetIndexArrow(0, 233); // Up Arrow
SetIndexLabel(0, "BUY");
SetIndexBuffer(1, SellSignal);
SetIndexStyle(1, DRAW_ARROW, EMPTY, 2, clrRed);
SetIndexArrow(1, 234); // Down Arrow
SetIndexLabel(1, "SELL");
SetIndexBuffer(2, EMA);
SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 1, clrBlue);
SetIndexLabel(2, "EMA " + string(EMA_Period));
SetIndexBuffer(3, UpperBB);
SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 1, clrLime);
SetIndexLabel(3, "Upper BB");
SetIndexBuffer(4, LowerBB);
SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, 1, clrTomato);
SetIndexLabel(4, "Lower BB");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
for(int i = MathMax(prev_calculated, 1); i < rates_total; i++)
{
EMA[i] = iMA(NULL, 0, EMA_Period, 0, MODE_EMA, PRICE_CLOSE, i);
UpperBB[i] = iBands(NULL, 0, BB_Period, BB_Deviation, 0, PRICE_CLOSE,
MODE_UPPER, i);
LowerBB[i] = iBands(NULL, 0, BB_Period, BB_Deviation, 0, PRICE_CLOSE,
MODE_LOWER, i);
double rsi = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
// Buy Signal
if(rsi < 30 && low[i] <= LowerBB[i] && close[i] > EMA[i])
BuySignal[i] = low[i] - 10 * _Point;
// Sell Signal
if(rsi > 70 && high[i] >= UpperBB[i] && close[i] < EMA[i])
SellSignal[i] = high[i] + 10 * _Point;
}
return(rates_total);
}
//+------------------------------------------------------------------+