Mousa Lotfi: I developed an indicator that detects clouds with up to 17 candles and displays a buy or sell indicator on the chart if found. When I compile this indicator it works fine, but when a new candle appears the loop doesn't work. please guide me.
Your attached ".mq4" file was empty, so I removed it. Please reattach the file again.
#property copyright "Copyright 2023, MetaQuotes Ltd. Moussa" #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window #property indicator_buffers 2 extern int BuyArrow_Width = 2; //Buy Signal Arrow Width extern color BuyArrow_color = clrLime; //Buy Signal Arrow Color extern int SellArrow_Width = 2; //Sell Signal Arrow Width extern color SellArrow_color = clrRed; //Sell Signal Arrow Color double Komu_Up_Cross []; double Komu_Down_Cross []; //+---------- --------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Komu_Up_Cross); SetIndexBuffer(1,Komu_Down_Cross); SetIndexStyle(0,DRAW_ARROW,EMPTY,BuyArrow_Width,BuyArrow_color); SetIndexStyle(1,DRAW_ARROW,EMPTY,SellArrow_Width,SellArrow_color); SetIndexArrow(0,233); SetIndexArrow(1,234); //--- 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 UpDownDist = 0; int DownUpDist = 0; int limit = rates_total - prev_calculated; if(limit == 0 )limit++; //if(limit == Bars-1) limit++; ////---- main loop //for(int i=limit-2;i>=0;i--) //for(int i=0;i<Bars;i++) for(int i=Bars-2; i>=0; i--) { double SenkouA = (iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_TENKANSEN, i+1)+(iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_KIJUNSEN, i+1)))/2; double SenkouA_perv = (iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_TENKANSEN, i+2)+(iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_KIJUNSEN, i+2)))/2; double SenkouB = iIchimoku(NULL, PERIOD_CURRENT, 52, 26, 52, MODE_TENKANSEN, i+1); double SenkouB_perv = iIchimoku(NULL, PERIOD_CURRENT, 52, 26, 52, MODE_TENKANSEN, i+2); double TenkanSen = iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_TENKANSEN, i); double KijunSen = iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_KIJUNSEN, i); double TenkanSen_perv = iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_TENKANSEN, i+1); double KijunSen_prev = iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_KIJUNSEN, i+1); if(SenkouA > SenkouB &&(SenkouA_perv < SenkouB_perv || SenkouA_perv == SenkouB_perv)) UpDownDist = i; if(SenkouA < SenkouB &&(SenkouA_perv > SenkouB_perv || SenkouA_perv == SenkouB_perv)) DownUpDist = i; if(SenkouA > SenkouB &&(SenkouA_perv < SenkouB_perv || SenkouA_perv == SenkouB_perv)&& KijunSen_prev < TenkanSen_perv && Close[i+1] > TenkanSen_perv && (DownUpDist - UpDownDist)<18 && DownUpDist > UpDownDist) Komu_Up_Cross[i] = (Low[i] + TenkanSen)/2; if(SenkouA < SenkouB &&(SenkouA_perv > SenkouB_perv || SenkouA_perv == SenkouB_perv) && KijunSen_prev > TenkanSen_perv && Close[i+1] < TenkanSen_perv && (UpDownDist - DownUpDist)<18 && DownUpDist < UpDownDist) Komu_Down_Cross[i] = (High[i]+ TenkanSen)/2; } //---- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Fernando Carreiro #:
Your attached ".mq4" file was empty, so I removed it. Please reattach the file again.
Your attached ".mq4" file was empty, so I removed it. Please reattach the file again.

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
Hello everyone
I developed an indicator that detects clouds with up to 17 candles and displays a buy or sell indicator on the chart if found. When I compile this indicator it works fine, but when a new candle appears the loop doesn't work.
please guide me. Thanks