仕事が完了した
指定
I need an indicatorv for MQL5, It uses CCi and 2 EMA, the strategy is; Ema 50 and 200, when Above ema 50 we look for buy signal and when below we look for sell, the CCI should be 20 period with 150 and -150 once the price is overbought and oversold and it renter the level 150 and -150 with the confermition of ema we have the signal
I want to add the alert to the signal
#property indicator_chart_mode ANY
#property indicator_separate_window true // Optional: Separate window for indicator
#include "iCustom\\iCustom.mqh" // Include for custom indicator functions (if needed)
int ema50Length = 50;
int ema200Length = 200;
int cciLength = 20;
double overbought = 150;
double oversold = -150;
double ema50[], ema200[], cci[];
bool trendBullish, trendBearish;
bool buySignal[], sellSignal[]; // Arrays for storing signals
// Function to calculate EMA (replace with custom function if needed)
double iCustom_EMA(double price[], int period) {
double sum = 0.0;
for (int i = 0; i < period; i++) {
sum += price[Close];
}
return sum / period * (2.0 / (period + 1.0));
}
int OnInit() {
ema50 = ArrayDimension(ema50Length); // Allocate arrays
ema200 = ArrayDimension(ema200Length);
cci = ArrayDimension(cciLength);
buySignal = ArrayDimension(Bars); // Allocate arrays for signals
sellSignal = ArrayDimension(Bars);
return(INIT_SUCCEEDED);
}
int OnCalculate(const int start, const int end) {
if(start == 0) {
// Initialize arrays on the first call
for (int i = 0; i < ArraySize(ema50); i++) {
ema50[i] = iCustom_EMA(Close, ema50Length); // Replace with custom EMA function if needed
ema200[i] = iCustom_EMA(Close, ema200Length); // Replace with custom EMA function if needed
}
}
for (int i = start; i <= end; i++) {
// Calculate CCI
cci[i] = iCustom_CCI(Close, cciLength); // Replace with custom CCI function if needed
// Calculate trend and signals
trendBullish = ema50[i] > ema200[i];
trendBearish = ema50[i] < ema200[i];
buySignal[i] = trendBullish && iCustom_CrossOver(cci[i], oversold); // Replace with custom crossover function if needed
sellSignal[i] = trendBearish && iCustom_CrossUnder(cci[i], overbought); // Replace with custom crossunder function if needed
}
// Plotting (modify colors, styles, and window as needed)
PlotLine(ema50, SHIFT, colorBlue, 1, title="EMA 50");
PlotLine(ema200, SHIFT, colorRed, 1, title="EMA 200");
PlotIcon(buySignal, SHIFT, STYLE_ARROWUP, colorGreen, 10); // Consider using labels or different icons
PlotIcon(sellSignal, SHIFT, STYLE_ARROWDOWN, colorRed, 10); // Consider using labels or different icons
return(0);
}