please fix my code!!

 

I would like this indicator to alert me on current candle and not after candle closes because I'm trading 60 seconds. Please help...



//+------------------------------------------------------------------+
//| binary alert based on RSI+MFI+Demarker
//+------------------------------------------------------------------+

#property copyright "tradista@tradegest.com"
#property version "1.0"
#property description "Oversold/Overbought signal based RSI+MFI+Demarker with alert."
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

//---- external parameters
extern int RSIPeriod = 2;         // RSI Period
extern int MFIPeriod = 4;         // Money Flow Index Period
extern int DemarkerPeriod = 4;    // Demark Period
extern double RSI_OB = 90;        // RSI overbought value
extern double RSI_OS = 10;        // RSI oversold value
extern double MFI_OB = 100;       // MFI overbought value
extern double MFI_OS = 0;         // MFI oversold value
extern double Demarker_OB = 1;    // Demarker overbought value
extern double Demarker_OS = 0;    // Demarker overbought value
// extern int Step = 3;              // Max bars back to check for cross sincronicity
extern bool AlertOn=true;        // Enable alert
extern int CountBars=500;

//---- buffers
double buy_buf[];
double sell_buf[];

datetime BarTime;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
  {
   IndicatorBuffers(2);
  
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexBuffer(0,buy_buf);
     
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexBuffer(1,sell_buf);
  
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int start()
  {  
   int counted_bars = IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit = MathMin(Bars-counted_bars,Bars-1);
  
   int i=CountBars-1;
  
   while(i>=0)
  
   {    
   buy_buf[i]=EMPTY_VALUE;
   sell_buf[i]=EMPTY_VALUE;
     
   double RSI = iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i);
   double MFI = iMFI(NULL,0,MFIPeriod,i);
   double DMK = iDeMarker(NULL,0,DemarkerPeriod,i);
  
   double RSI_b = iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i+1);
   double MFI_b = iMFI(NULL,0,MFIPeriod,i+1);
   double DMK_b = iDeMarker(NULL,0,DemarkerPeriod,i+1);  
         
   //buy signal
  
   // ************************* set buy arrow value ************************

      if ( RSI>=RSI_OS && RSI<RSI_OB && RSI_b<=RSI_OS &&
           MFI>=MFI_OS && MFI<MFI_OB && MFI_b<=MFI_OS &&
           DMK>=Demarker_OS && DMK_b<=Demarker_OS)
      {
      buy_buf[i]=Low[i]-5*Point;
      if (AlertOn==true && i<=1)        
      {
         PlaySound("alert.wav");        
         Alert(TimeMonth(CurTime()),"/",TimeDay(CurTime())," at ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"   -   Possible buy on ",Symbol()," ", Period());
         }
      }

   /////////////////////////////////////////////////////////////////////////////////////////////////

      //sell signal
     if ( RSI<=RSI_OB && RSI>RSI_OS && RSI_b>=RSI_OB &&
          MFI<=MFI_OB && MFI>MFI_OS && MFI_b>=MFI_OB &&
          DMK<=Demarker_OB && DMK_b>=Demarker_OB)
      {
      // ************************* set sell arrow value ************************     
      sell_buf[i]=High[i]+5*Point;
      if (AlertOn==true && i<=1)
         {
         PlaySound("alert.wav");        
         Alert(TimeMonth(CurTime()),"/",TimeDay(CurTime())," at ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"   -   Possible sell on ",Symbol()," ", Period());
         }
      }
   ///////////////////////////////////////////////////////////////////////////////////////////////////
   i--;
     
   }     
  
   return(0);
  }
 


 

queentrade: I would like this indicator to alert me on current candle and not after candle closes ...

  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2.      if (AlertOn==true && i<=1){
             PlaySound("alert.wav");
  3. It's doing that already current bar and previous bar.
  4. Perhaps your loop
    Do your look back, correctly. No need for decrement
       int counted_bars = IndicatorCounted();
       if(counted_bars<0) return(-1);
       if(counted_bars>0) counted_bars--;
       int limit = MathMin(Bars-counted_bars,Bars-1);
       int i=CountBars-1;
       while(i>=0)
     
    // lookback1 RSIPeriod + 1       iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i+1);
    // lookback2 MFIPeriod + 1       iMFI(NULL,0,MFIPeriod,i+1);
    // lookback3 DemarkerPeriod, + 1 iDeMarker(NULL,0,DemarkerPeriod,i+1);
    int lookback = MathMax(RSIPeriod, MathMax(MFIPeriod, DemarkerPeriod)) + 1;
      int counted_bars = IndicatorCounted();
       if(counted_bars<0) return(-1);
       int i=Bars - 1 - MathMax(lookback, counted_bars);
       while(i>=0)