Thank you all, Massimo.
Hi, I post all the code. I would like, if possible, that the alert is shown when opening the spark plug if the conditions are complied with the code.
There must be 3 bars of decreasing CCI, but the alert should appear only once at the opening of the current candle.
I hope I was clear. Sorry for my poor English, greetings, thank you, Max.
//+------------------------------------------------------------------+ //| CCI alert.mq4 | //| Massimo | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Massimo" #property link "https://www.mql5.com" #property version "1.00" //--- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_type1 DRAW_ARROW #property indicator_width1 1 #property indicator_color1 0xFFAA00 #property indicator_label1 "Buy" #property indicator_type2 DRAW_ARROW #property indicator_width2 1 #property indicator_color2 0x0000FF #property indicator_label2 "Sell" //--- indicator buffers double Buffer1[]; double Buffer2[]; double myPoint; //initialized in OnInit void myAlert(string type, string message) { if(type == "print") Print(message); else if(type == "error") { Print(type+" | Test @ "+Symbol()+","+Period()+" | "+message); } else if(type == "order") { } else if(type == "modify") { } } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(2); SetIndexBuffer(0, Buffer1); SetIndexEmptyValue(0, 0); SetIndexArrow(0, 241); SetIndexBuffer(1, Buffer2); SetIndexEmptyValue(1, 0); SetIndexArrow(1, 242); //initialize myPoint myPoint = Point(); if(Digits() == 5 || Digits() == 3) { myPoint *= 10; } 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, 0); ArrayInitialize(Buffer2, 0); } else limit++; //--- 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(iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, false, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, i) > iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) //CCI Histogram > CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) > iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 2+i) //CCI Histogram > CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) < 0 //CCI Histogram < fixed value && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 2+i) < 0 //CCI Histogram < fixed value ) { Buffer1[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick Low - Average True Range } else { Buffer1[i] = 0; } //Indicator Buffer 2 if(iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, false, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, i) < iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 1+i) //CCI Histogram < CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 1+i) < iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 2+i) //CCI Histogram < CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 1+i) > 0 //CCI Histogram > fixed value && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 2+i) > 0 //CCI Histogram > fixed value ) { Buffer2[i] = High[i] + iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick High + Average True Range } else { Buffer2[i] = 0; } } return(rates_total); } //+------------------------------------------------------------------+
Hello Gumrai. I updated the file that works in part. The alert appears at the opening of the candle but in the course of its
formation may disappear. I would rather that once appeared, if the conditions are valid at the opening of the candle, do not disappear anymore.
Greetings, Massimo.
PS:
Attack the file to which I refer to the alert
//+------------------------------------------------------------------+ //| CCI alert.mq4 | //| Massimo | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Massimo" #property link "https://www.mql5.com" #property version "1.00" //--- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_type1 DRAW_ARROW #property indicator_width1 1 #property indicator_color1 0xFFAA00 #property indicator_label1 "Buy" #property indicator_type2 DRAW_ARROW #property indicator_width2 1 #property indicator_color2 0x0000FF #property indicator_label2 "Sell" static datetime pippo; //Per fare leggere l'indicatore solo all'pertura candela 1 di 3 //--- indicator buffers double Buffer1[]; double Buffer2[]; double myPoint; //initialized in OnInit void myAlert(string type, string message) { if(type == "print") Print(message); else if(type == "error") { Print(type+" | Test @ "+Symbol()+","+Period()+" | "+message); } else if(type == "order") { } else if(type == "modify") { } } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(2); SetIndexBuffer(0, Buffer1); SetIndexEmptyValue(0, 0); SetIndexArrow(0, 241); SetIndexBuffer(1, Buffer2); SetIndexEmptyValue(1, 0); SetIndexArrow(1, 242); pippo= TimeCurrent(); //Per fare leggere l'indicatore solo all'pertura candela 2 di 3 //initialize myPoint myPoint = Point(); if(Digits() == 5 || Digits() == 3) { myPoint *= 10; } 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, 0); ArrayInitialize(Buffer2, 0); } else limit++; //--- 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(iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, false, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, i) > iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) //CCI Histogram > CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) > iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 2+i) //CCI Histogram > CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) < 0 //CCI Histogram < fixed value && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 2+i) < 0 //CCI Histogram < fixed value && TimeCurrent() > pippo //Per fare leggere l'indicatore solo all'pertura candela 3 di 3 ) { Buffer1[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick Low - Average True Range } else { Buffer1[i] = 0; } //Indicator Buffer 2 if(iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, false, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, i) < iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 1+i) //CCI Histogram < CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 1+i) < iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 2+i) //CCI Histogram < CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 1+i) > 0 //CCI Histogram > fixed value && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 2+i) > 0 //CCI Histogram > fixed value && TimeCurrent() > pippo //Per fare leggere l'indicatore solo all'pertura candela 3 di 3 ) { Buffer2[i] = High[i] + iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick High + Average True Range } else { Buffer2[i] = 0; } } return(rates_total); } //+------------------------------------------------------------------+
I am very inexperienced and I hope someone can help me.
Sorry and thanks to all, Massimo.
Valid only at the opening | if(Volume[0] < 5) Buffer2[i] = 0; if(Volume[0] < 5) Buffer1[i] = 0; |
Valid anytime during the candle | // Buffer2[i] = 0; // Buffer1[i] = 0; |
Valid at the end of the candle | Buffer2[i] = 0; Buffer1[i] = 0; |
thank you so much, Massimo.
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 if( Volume[0]<5) Buffer2[i]=0; if(Volume[0]<5) Buffer1[i]=0; //Indicator Buffer 1 if( iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, false, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, i) > iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) //CCI Histogram > CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) > iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 2+i) //CCI Histogram > CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 1+i) < 0 //CCI Histogram < fixed value && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 1, 2+i) < 0 //CCI Histogram < fixed value && TimeCurrent()>BarStart ) { Buffer1[i]=Low[i]-iATR(NULL,PERIOD_CURRENT,14,i); //Set indicator value at Candlestick Low - Average True Range } else { Buffer1[i]=0; } //Indicator Buffer 2 if(iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,false,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,i)<iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,true,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,1+i) //CCI Histogram < CCI Histogram && iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,true,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,1+i)<iCustom(NULL,PERIOD_CURRENT,"CCI Histogram",4,0,true,0,false,1,"TrendCCI",false,50,14,50,14,14,6,14,6,14,6,14,6,14,6,14,6,14,6,0,2+i) //CCI Histogram < CCI Histogram && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 1+i) > 0 //CCI Histogram > fixed value && iCustom(NULL, PERIOD_CURRENT, "CCI Histogram", 4, 0, true, 0, false, 1, "TrendCCI", false, 50, 14, 50, 14, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 14, 6, 0, 2+i) > 0 //CCI Histogram > fixed value && TimeCurrent()>BarStart ) { Buffer2[i]=High[i]+iATR(NULL,PERIOD_CURRENT,14,i); //Set indicator value at Candlestick High + Average True Range } else { Buffer2[i]=0; } } return(rates_total); } //+------------------------------------------------------------------+
You cannot use Sleep in an indicator.
Ok GumRai,
I was trying and I've seen that does not work. How can I do? He's trying to study, but I can not find the solution.
thanks Massimo.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone, I'm Max. I am a neophyte in the MQL4 programming and speak little English, so excuse me. I have a problem I can not solve.
I have an indicator / alert built on CCI Histogram. I inserted the conditions that work. I would like that the last bar of the histogram, was read at the opening
of candelstick and not the closure of candelstick.
I hope someone can help me.
Thank you all, greetings, Massimo.