Ichimoku advisor only working on M1 Chart

 

Hi,

So I've done a basic script that sends me an alert when the price crosses the ichimoku cloud but it only seems to work on the M1 Chart.

Any other chart leads to no comment appearing and no alerts, I've tried changing period_current to PERIOD_H1 but that doesn't work. Just starting to learn

and it'd be great if someone could help me.

Thanks alot.

#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


input int TenkanSen = 9;
input int KijunSen = 26;
input int SenkouSpanB = 52;



input string Commentary = "Comment";
input int Magic = 1;

int totalBars;

int OnInit(){
   totalBars = iBars(_Symbol,PERIOD_CURRENT);


   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason){
   

   
}

void OnTick(){
   
   int bars = iBars(_Symbol,PERIOD_CURRENT);
   if(totalBars != bars){
      totalBars = bars; 


      double tenkanSen1 = iIchimoku (_Symbol, PERIOD_CURRENT,TenkanSen, KijunSen, SenkouSpanB, MODE_TENKANSEN, 0);
      double kijunSen1 = iIchimoku (_Symbol, PERIOD_CURRENT, TenkanSen, KijunSen, SenkouSpanB, MODE_KIJUNSEN, 0);
      double tenkanSen2 = iIchimoku (_Symbol, PERIOD_CURRENT,TenkanSen, KijunSen, SenkouSpanB, MODE_TENKANSEN, 1);
      double kijunSen2 = iIchimoku (_Symbol, PERIOD_CURRENT, TenkanSen, KijunSen, SenkouSpanB, MODE_KIJUNSEN, 1);
      double senkouSpanA2 = iIchimoku (_Symbol, PERIOD_CURRENT, TenkanSen, KijunSen, SenkouSpanB, MODE_SENKOUSPANA, 0);
      double senkouSpanB2 = iIchimoku (_Symbol, PERIOD_CURRENT, TenkanSen, KijunSen, SenkouSpanB, MODE_SENKOUSPANB, 0);
      double senkouSpanA1 = iIchimoku (_Symbol, PERIOD_CURRENT, TenkanSen, KijunSen, SenkouSpanB, MODE_SENKOUSPANA, 1);
      double senkouSpanB1 = iIchimoku (_Symbol, PERIOD_CURRENT, TenkanSen, KijunSen, SenkouSpanB, MODE_SENKOUSPANB, 1);
      
  
      Comment(
               "Tenkansen value: ",tenkanSen1, "\n",
               "KjiunSen value: ",kijunSen1,"\n",
               "SenkouSpanA Value: ",senkouSpanA2,"\n",
               "SenkouSpanB Value: ",senkouSpanB2," \n"
             );
  
  
  
      
      if (NormalizeDouble(Ask,_Digits) > senkouSpanA2 && NormalizeDouble(Ask,_Digits) > senkouSpanB2 && (NormalizeDouble(Ask,_Digits) < senkouSpanA1 || NormalizeDouble(Ask,_Digits) < senkouSpanB1 )){
         SendNotification(_Symbol + " is above Ichimoku Cloud");
         
      }
      
      if (NormalizeDouble(Bid,_Digits) < senkouSpanA2 && NormalizeDouble(Bid,_Digits) < senkouSpanB2 && (NormalizeDouble(Bid,_Digits) > senkouSpanA1 || NormalizeDouble(Bid,_Digits) > senkouSpanB1 )){
         SendNotification(_Symbol + " is below Ichimoku Cloud");
         
      }
    }   
} 
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions