Price Data Components
Indicators Used
0
Views
0
Downloads
0
Favorites
EMA on RSI
//+------------------------------------------------------------------+
//| Indicator: EMA on RSI.mq5 |
//| Created with EABuilder.com |
//| https://eabuilder.com |
//+------------------------------------------------------------------+
#property copyright "Created with EABuilder.com"
#property link "https://eabuilder.com"
#property version "1.00"
#property description ""
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_color1 0xFFAA00
#property indicator_label1 "EMA on RSI"
//--- indicator buffers
double Buffer1[];
input int RSI_Period = 21;
input int EMA_Period = 21;
double myPoint; //initialized in OnInit
int RSI_handle;
double RSI[];
int MA_handle;
double MA[];
void myAlert(string type, string message)
{
if(type == "print")
Print(message);
else if(type == "error")
{
Print(type+" | EMA on RSI @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
}
else if(type == "order")
{
}
else if(type == "modify")
{
}
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, Buffer1);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//initialize myPoint
myPoint = Point();
if(Digits() == 5 || Digits() == 3)
{
myPoint *= 10;
}
RSI_handle = iRSI(NULL, PERIOD_CURRENT, RSI_Period, 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, EMA_Period, 0, MODE_EMA, RSI_handle);
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);
//--- initial zero
if(prev_calculated < 1)
{
ArrayInitialize(Buffer1, 0);
}
else
limit++;
if(BarsCalculated(MA_handle) <= 0)
return(0);
if(CopyBuffer(MA_handle, 0, 0, rates_total, MA) <= 0) return(rates_total);
ArraySetAsSeries(MA, true);
//--- main loop
for(int i = limit-1; i >= 0; i--)
{
if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation
//Indicator Buffer 1
if(true //Custom Code
)
{
Buffer1[i] = MA[i]; //Set indicator value at Moving Average
}
else
{
Buffer1[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
---