My alert won't triggered event the condition is fulfilled

 
Hello, I am try to make an indicator and use ArrowDownCreate() function to create arrow when the condition met but I try to alert when only the arrow appear at bar shift 1 But when I wrote the script, the alert always trigger when bar shift 0 appear. Anyone can help me?
 
  • Usually people who can't code don't receive free help on this forum.
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
  • To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Documentation.
  • If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
  • Finally, you also have the option to hire a programmer in the Freelance section.
 

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked, so we can't see your machine.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code.

Always post all relevant code (using Code button) or attach the source file.

 
for(int i=limit;i<rates_total-2;i++){
         double l[2],h[2];
         ArrayCopy(l,low,0,i,2);
         ArrayCopy(h,high,0,i,2);
        
         //valc[i] = (i>0) ? (val[i]>val[i-1]) ? 1 :(val[i]<val[i-1]) ? 2 : valc[i-1]: 0;

         if(MA){
            TrendCreate(ChartID(),"Fractal_TREND_MA_"+TimeToString(time[i]),0,time[i],val[i],time[i+1],val[i+1],Trendclr[i],STYLE_SOLID,2,true,false,false,false,true,0);
            TrendCreate(ChartID(),"Fractal_TREND_MA_"+TimeToString(time[i+1]),0,time[i+1],val[i+1],time[i+2],val[i+2],Trendclr[i],STYLE_SOLID,2,true,false,false,false,true,0);
         }
   
         if((open[i+1] < close[i+1]) && (open[i] > close[i])){
         
            //if bullish
            if(ArrayMinimum(l,0,WHOLE_ARRAY) == 1){
   
               //ArrowDownCreate(ChartID(),"Fractal_Arrow_Down_" + TimeToString(time[i+2]),0,time[i+2],low[i+2],ANCHOR_TOP,ArrowDownColor,STYLE_SOLID,1,false,false,true,0);
               
               if(filter){
                  //if((val[i+1] < low[i+1]))
                  if ((Trendclr[i] == MAColorup )){
                     //Signal Buy
                     
                     RectangleCreate(ChartID(),"Fractal_" + TimeToString(time[i+1]),0,time[i],high[i+1],time[i+1],low[i+1],pairBullColor,STYLE_SOLID,1,true,true,false,true,0);
              
                     ArrowUpCreate(ChartID(),"Fractal_Arrow_Up_" + TimeToString(time[i+1]),0,time[i+1],low[i+1],ANCHOR_TOP,ArrowUpColor,STYLE_SOLID,1,true,false,true,0);
                     if(i == 0)arrowUpDisplayed = true;
                     buy[i+1] = close[i+1];
                    
                     ObjectsDeleteAll(ChartID(),objname+"_Signal");
                     
                     //labelInfoSignal("VALUE","BUY",80);
                     if(showinfo){
                        labelSIGNAL.Create(ChartID(),"SIGNAL",0,AppWindow.Left()+10,AppWindow.Top()+80,AppWindow.Left()+200,AppWindow.Top()+100);
                        labelSIGNAL.Text("SIGNAL: BUY");
                        labelSIGNAL.Color(fontClrBuy);
                        labelSIGNAL.FontSize(fontSize);
                          
                     }

                     //Print(buy[i+1]," ",close[i+1]);
                     ArrayResize(signal,signalCnt+1);
                     signal[signalCnt]=1;
                     signalCnt++;
                  }
               }else{
                  buy[i+1] = close[i+1];

                  RectangleCreate(ChartID(),"Fractal_" + TimeToString(time[i+1]),0,time[i],high[i+1],time[i+1],low[i+1],pairBullColor,STYLE_SOLID,1,true,true,false,true,0);

                  ArrowUpCreate(ChartID(),"Fractal_Arrow_Up_" + TimeToString(time[i+1]),0,time[i+1],low[i+1],ANCHOR_TOP,ArrowUpColor,STYLE_SOLID,1,true,false,true,0);
                  
                   if(i == 0)arrowUpDisplayed = true;
                  
              ObjectsDeleteAll(ChartID(),objname+"_Signal");
                  if(showinfo){
                     labelSIGNAL.Create(ChartID(),"SIGNAL",0,AppWindow.Left()+10,AppWindow.Top()+80,AppWindow.Left()+200,AppWindow.Top()+100);
                     labelSIGNAL.Text("SIGNAL: BUY");
                     labelSIGNAL.Color(fontClrBuy);
                     labelSIGNAL.FontSize(fontSize);
                  }
                    
                  //Print(buy[i+1]," ",close[i+1]);
                  ArrayResize(signal,signalCnt+1);
                  signal[signalCnt]=1;
                  signalCnt++;
               }
               
               if(i == 1 && arrowUpDisplayed )
                       {
                       if(alertEnabled && time[0] != time_alert)
                         {
                         myAlert("indicator", "Buy");
                         time_alert = time[0];
                         arrowUpDisplayed = false;
                         }
                      
                       }
               //i++;
               //TrendCreate(ChartID(),"Fractal_TREND_MA_"+TimeToString(time[i]),0,time[i],bufferMA[i],time[i+1],bufferMA[i+1],MAColor,STYLE_SOLID,1,false,false,false,false,true,0);
            }
         }
         
         //if Bearish
         else if((open[i+1] > close[i+1]) && (open[i] < close[i])) {
             
            if(ArrayMaximum(h,0,WHOLE_ARRAY) == 1){
      
               //ArrowUpCreate(ChartID(),"Fractal_Arrow_Up_" + TimeToString(time[i+2]),0,time[i+2],high[i+2],ANCHOR_BOTTOM,ArrowUpColor,STYLE_SOLID,1,false,false,true,0);
               
              
               if(filter){
                  if ((Trendclr[i] == MAColordn)){
                     //Signal Sell
               
                     ObjectsDeleteAll(ChartID(),objname+"_Signal");
 
                     //labelInfoSignal("VALUESELL","SELL",80);
                     if(showinfo){
                        labelSIGNAL.Create(ChartID(),"SIGNAL",0,AppWindow.Left()+10,AppWindow.Top()+80,AppWindow.Left()+200,AppWindow.Top()+100);
                        labelSIGNAL.Text("SIGNAL: SELL");
                        labelSIGNAL.Color(fontClrSell);
                        labelSIGNAL.FontSize(fontSize);
                  
                     }
                     sell[i+1]=close[i+1];
                     RectangleCreate(ChartID(),"Fractal_" + TimeToString(time[i+1]),0,time[i],high[i+1],time[i+1],low[i+1],pairBearColor,STYLE_SOLID,1,true,true,false,true,0);
                     
                     ArrowDownCreate(ChartID(),"Fractal_Arrow_Down_" + TimeToString(time[i+1]),0,time[i+1],high[i+1],ANCHOR_BOTTOM,ArrowDownColor,STYLE_SOLID,1,true,false,true,0);
                     if(i == 0)
                       {
                        arrowDownDisplayed = true;
                       }
                    
                     ArrayResize(signal,signalCnt+1);
                     signal[signalCnt]=-1;
                     signalCnt++;
                    
                  }
               }else{
                  
                     //Signal Sell
                     ObjectsDeleteAll(ChartID(),objname+"_Signal");
                     //labelInfoSignal("VALUESELL","SELL",80);
                     if(showinfo){
                        labelSIGNAL.Create(ChartID(),"SIGNAL",0,AppWindow.Left()+10,AppWindow.Top()+80,AppWindow.Left()+200,AppWindow.Top()+100);
                        labelSIGNAL.Text("SIGNAL: SELL");
                        labelSIGNAL.Color(fontClrSell);
                        labelSIGNAL.FontSize(fontSize);
                     }
                     sell[i+1]=close[i+1];
                     RectangleCreate(ChartID(),"Fractal_" + TimeToString(time[i+1]),0,time[i],high[i+1],time[i+1],low[i+1],pairBearColor,STYLE_SOLID,1,true,true,false,true,0);
                  
                     ArrowDownCreate(ChartID(),"Fractal_Arrow_Down_" + TimeToString(time[i+1]),0,time[i+1],high[i+1],ANCHOR_BOTTOM,ArrowDownColor,STYLE_SOLID,1,true,false,true,0);
                     
                     if(i == 0)
                       {
                        arrowDownDisplayed = true;
                       }
         
                  ObjectsDeleteAll(ChartID(),objname+"_Signal");
                  //labelInfoSignal("BUY","BUY",80);
           
                     ArrayResize(signal,signalCnt+1);
                     signal[signalCnt]=-1;
                     signalCnt++;
                  
               }
                     if(i == 1 && arrowDownDisplayed && alertEnabled && time[0] != time_alert)
                {
                         myAlert("indicator", "Sell");
                         time_alert = time[0];
                      arrowDownDisplayed = false;
                }
these are the codes
 
William Roeder #:

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked, so we can't see your machine.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code.

Always post all relevant code (using Code button) or attach the source file.

can you help me fix it?the code already attached above
 

The variable gets a true value only when i==0. This would not work.

You need to review your logic.

if(i == 0)arrowUpDisplayed = true;
if(i == 1 && arrowUpDisplayed )
{
   if(alertEnabled && time[0] != time_alert)
   {
      myAlert("indicator", "Buy");
      time_alert = time[0];
      arrowUpDisplayed = false;
   }             
}
 
Yashar Seyyedin #:

The variable gets a true value only when i==0. This would not work.

You need to review your logic.

thank you for your reply, I have found the probblem