Add indicator_plots to the top as #property and define them. You can read in documentation about it
how do I define it given this case... I'm new to MQL4
Ferhat Mutlu #:
Add indicator_plots to the top as #property and define them. You can read in documentation about it
Add indicator_plots to the top as #property and define them. You can read in documentation about it
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I keep getting 'INDICATOR_PLOT' - undeclared identifier
Wrote the code below but keep getting undeclared indicator error. Code is meant to draw arrows and give alert if price closes outside of 5ema
//+------------------------------------------------------------------+
//| 5EMA Candle Cross.mq4 |
//| by Blue |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
//--- input parameters
input int InpEMAPeriod=5;
//--- buffers
double EMA_Buffer[];
double Cross_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,EMA_Buffer,INDICATOR_DATA);
SetIndexBuffer(1,Cross_Buffer,INDICATOR_PLOT);
//---
IndicatorShortName("5EMA Candle Cross");
SetIndexStyle(1,DRAW_ARROW);
SetIndexLabel(1,"Cross");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| 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 i,limit;
if(rates_total<=InpEMAPeriod) return(0);
if(prev_calculated>0) limit=prev_calculated-1;
else limit=rates_total-1;
//---
for(i=limit;i>=0;i--)
{
//--- EMA
if(i==limit) EMA_Buffer[i]=close[i];
else EMA_Buffer[i]=EMA_Buffer[i+1]+(2.0/(InpEMAPeriod+1))*(close[i]-EMA_Buffer[i+1]);
//--- Cross
if(i==limit) Cross_Buffer[i]=0;
else
{
if(((close[i]>EMA_Buffer[i])&&(close[i+1]<=EMA_Buffer[i+1]))
||((close[i]<EMA_Buffer[i])&&(close[i+1]>=EMA_Buffer[i+1]))) Cross_Buffer[i]=close[i];
else Cross_Buffer[i]=0;
}
}
//---
if(prev_calculated==0) Alert("5EMA Candle Cross - Indicator calculated successfully!");
// Modification: Draw arrow based on trade direction
// Modification: Draw arrow based on trade direction
for (i = limit; i >= 0; i--)
{
if (Cross_Buffer[i] != 0)
{
if (close[i] > EMA_Buffer[i])
{
SetIndexArrow(1, 158);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 158);
SetIndexLabel(1, "Buy");
SetIndexBuffer(1, Cross_Buffer, INDICATOR_PLOT, 0, Green);
}
else
{
SetIndexArrow(1, 159);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 159);
SetIndexLabel(1, "Sell");
SetIndexBuffer(1, Cross_Buffer, INDICATOR_PLOT, 0, Red);
}
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}