Price Data Components
Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
Rsi EMA Engulf V3.1
#property copyright "http://bc.vc/ohKDegn"
#property link "http://bc.vc/ohKDegn"
#property description "VISIT SITE 4 MORE FREE INDICATORS & EXPERT ADVISORS "
#property version "1.2"
#property strict
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_ARROW
#property indicator_width1 5
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"
#property indicator_type2 DRAW_ARROW
#property indicator_width2 5
#property indicator_color2 0x0000FF
#property indicator_label2 "Sell"
#define PLOT_MAXIMUM_BARS_BACK 5000
#define OMIT_OLDEST_BARS 50
//--- indicator buffers
double Buffer1[];
double Buffer2[];
input double RsiLow = 40;
input int RsiPeriod = 10;
input double RsiHigh = 60;
input int EmaMovingAverage = 60;
input int Shiftpast = 6;
input int Shiftnow = 5;
datetime time_alert; //used when sending alert
input bool Send_Email = true;
input bool Audible_Alerts = true;
input bool Push_Notifications = true;
double myPoint; //initialized in OnInit
int RSI_handle;
double RSI[];
double Close[];
double Open[];
double High[];
int MA_handle;
double MA[];
double Low[];
void myAlert(string type, string message)
{
int handle;
if(type == "print")
Print(message);
else if(type == "error")
{
Print(type+" | Rsi EMA Engulf V3 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
}
else if(type == "order")
{
}
else if(type == "modify")
{
}
else if(type == "indicator")
{
Print(type+" | Rsi EMA Engulf V3 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
if(Audible_Alerts) Alert(type+" | Rsi EMA Engulf V3 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
if(Send_Email) SendMail("Rsi EMA Engulf V3", type+" | Rsi EMA Engulf V3 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
handle = FileOpen("Rsi EMA Engulf V3.txt", FILE_TXT|FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE, ';');
if(handle != INVALID_HANDLE)
{
FileSeek(handle, 0, SEEK_END);
FileWrite(handle, type+" | Rsi EMA Engulf V3 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
FileClose(handle);
}
if(Push_Notifications) SendNotification(type+" | Rsi EMA Engulf V3 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
}
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, Buffer1);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
PlotIndexSetInteger(0, PLOT_ARROW, 241);
SetIndexBuffer(1, Buffer2);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
PlotIndexSetInteger(1, PLOT_ARROW, 242);
//initialize myPoint
myPoint = Point();
if(Digits() == 5 || Digits() == 3)
{
myPoint *= 10;
}
RSI_handle = iRSI(NULL, PERIOD_CURRENT, RsiPeriod, PRICE_CLOSE);
if(RSI_handle < 0)
{
Print("The creation of iRSI has failed: RSI_handle=", INVALID_HANDLE);
Print("Runtime error = ", GetLastError());
return(INIT_FAILED);
}
MA_handle = iMA(NULL, PERIOD_CURRENT, EmaMovingAverage, 0, MODE_EMA, PRICE_CLOSE);
if(MA_handle < 0)
{
Print("The creation of iMA has failed: MA_handle=", INVALID_HANDLE);
Print("Runtime error = ", GetLastError());
return(INIT_FAILED);
}
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[])
{
int limit = rates_total - prev_calculated;
//--- counting from 0 to rates_total
ArraySetAsSeries(Buffer1, true);
ArraySetAsSeries(Buffer2, true);
//--- initial zero
if(prev_calculated < 1)
{
ArrayInitialize(Buffer1, EMPTY_VALUE);
ArrayInitialize(Buffer2, EMPTY_VALUE);
}
else
limit++;
datetime Time[];
if(BarsCalculated(RSI_handle) <= 0)
return(0);
if(CopyBuffer(RSI_handle, 0, 0, rates_total, RSI) <= 0) return(rates_total);
ArraySetAsSeries(RSI, true);
if(CopyClose(Symbol(), PERIOD_CURRENT, 0, rates_total, Close) <= 0) return(rates_total);
ArraySetAsSeries(Close, true);
if(CopyOpen(Symbol(), PERIOD_CURRENT, 0, rates_total, Open) <= 0) return(rates_total);
ArraySetAsSeries(Open, true);
if(CopyHigh(Symbol(), PERIOD_CURRENT, 0, rates_total, High) <= 0) return(rates_total);
ArraySetAsSeries(High, true);
if(BarsCalculated(MA_handle) <= 0)
return(0);
if(CopyBuffer(MA_handle, 0, 0, rates_total, MA) <= 0) return(rates_total);
ArraySetAsSeries(MA, true);
if(CopyLow(Symbol(), PERIOD_CURRENT, 0, rates_total, Low) <= 0) return(rates_total);
ArraySetAsSeries(Low, true);
if(CopyTime(Symbol(), Period(), 0, rates_total, Time) <= 0) return(rates_total);
ArraySetAsSeries(Time, true);
//--- main loop
for(int i = limit-1; i >= 0; i--)
{
if (i >= MathMin(PLOT_MAXIMUM_BARS_BACK-1, rates_total-1-OMIT_OLDEST_BARS)) continue; //omit some old rates to prevent "Array out of range" or slow calculation
//Indicator Buffer 1
if(RSI[i] < RsiLow //Relative Strength Index < fixed value
&& Close[1+i] > Open[1+i] //Candlestick Close > Candlestick Open
&& Close[2+i] < Open[2+i] //Candlestick Close < Candlestick Open
&& Close[1+i] > Open[2+i] //Candlestick Close > Candlestick Open
&& Close[1+i] < High[2+i] //Candlestick Close < Candlestick High
&& Close[1+i] < MA[1+i] //Candlestick Close < Moving Average
&& MA[Shiftpast+i] < MA[Shiftnow+i] //Moving Average < Moving Average
)
{
Buffer1[i] = Low[i]; //Set indicator value at Candlestick Low
if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Buy"); //Alert on next bar open
time_alert = Time[1];
}
else
{
Buffer1[i] = EMPTY_VALUE;
}
//Indicator Buffer 2
if(RSI[i] > RsiHigh //Relative Strength Index > fixed value
&& Close[1+i] < Open[1+i] //Candlestick Close < Candlestick Open
&& Close[2+i] > Open[2+i] //Candlestick Close > Candlestick Open
&& Close[1+i] < Open[2+i] //Candlestick Close < Candlestick Open
&& Close[1+i] > Low[2+i] //Candlestick Close > Candlestick Low
&& Close[1+i] > MA[1+i] //Candlestick Close > Moving Average
&& MA[Shiftpast+i] > MA[Shiftnow+i] //Moving Average > Moving Average
)
{
Buffer2[i] = High[i]; //Set indicator value at Candlestick High
if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Sell"); //Alert on next bar open
time_alert = Time[1];
}
else
{
Buffer2[i] = EMPTY_VALUE;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---