Alternate Function for IndicatorCounted() - page 2

 
krishna_gopal_2:


Actually in the indicator they are simply drawing arrows. So I edited it to give number 1 for buying 2 for selling. That's all.

For that variable I increased the buffer. That's all. Please tell me whether the EA code is right or wrong. If wrong means why or what should I do.

Is my iCustom() is correct or not?

Does the Indicator do what you mean it to do ?  how have you tested it ?  if the modifications to the Indicator has caused an issue how will you know ?  you will blame it on your iCustom()  call.

Why don't you read the original buffers and check if they are EMPTY_VALUE or not ? 

 
RaptorUK:

Does the Indicator do what you mean it to do ?  how have you tested it ?  if the modifications to the Indicator has caused an issue how will you know ?  you will blame it on your iCustom()  call.

Why don't you read the original buffers and check if they are EMPTY_VALUE or not ? 


My modification doesn't affect the original code. I'm just setting flags. If the indicator draws a buying arrow I'm setting the flag as 1 or if selling arrow, I'm setting it as 2. Thats all. So if I access the actual buffers I ll get the Price where the indicator was set. I dont need it. I want to know whether it is a buy or sell arrow. Can you please help me with that?
 
krishna_gopal_2:

My modification doesn't affect the original code. I'm just setting flags. If the indicator draws a buying arrow I'm setting the flag as 1 or if selling arrow, I'm setting it as 2. Thats all. So if I access the actual buffers I ll get the Price where the indicator was set. I dont need it. I want to know whether it is a buy or sell arrow. Can you please help me with that?

Show your modified Indicator Code.  what you have described will not be accomplished by these modifications . . .

#property indicator_buffers 3   //previous value was 2 here

double trade_signal[];

// In int()   I have added 

 SetIndexBuffer(2, trade_signal);

// In start() I have added

 trade_signal[0] = 1;         //For Buy Signal

 trade_signal[0] = 2;         //For Sell Signal
 
RaptorUK:

Show your modified Indicator Code.  what you have described will not be accomplished by these modifications . . .

 

Modified Code:
#property indicator_chart_window
#property indicator_color1 LawnGreen
#property indicator_color2 Red
#property indicator_width1  1
#property indicator_width2  1
#property indicator_buffers 4
//----
extern bool SoundON=false;
extern bool EmailON=false;
//---- input parameters
extern int KPeriod=5;
extern int DPeriod=3;
extern int Slowing=3;
extern int MA_Method=0; // SMA 0, EMA 1, SMMA 2, LWMA 3
extern int PriceField=0; // Low/High 0, Close/Close 1
extern int OverBoughtLevel  =80;
extern int OverSoldLevel    =20;
extern bool show_KD_cross=false;
extern bool show_K_OBOScross=true;
extern bool show_D_OBOScross=false;
extern string note_Price="PriceField:  Low/High = 0, Close/Close = 1";
extern string _MA_Method="SMA0 EMA1 SMMA2 LWMA3";
double CrossUp[];
double CrossDown[];

double trade_signal[];// HERE
int trade =0;
int flagval1=0;
int flagval2=0;
//datetime signal_time;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(0, CrossUp);
   SetIndexBuffer(1, CrossDown);
   SetIndexBuffer(2, trade_signal);
   SetIndexBuffer(3, trade_signal);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  int start() 
  {
   int limit, i, counter;
   double tmp=0;
   double fastMAnow, slowMAnow, fastMAprevious, slowMAprevious;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit= Bars-counted_bars;
     for(i=1; i<=limit; i++) 
     {
      counter=i;
      Range=0;
      AvgRange=0;
      for(counter=i; counter<=i+9; counter++)
        {
         //AvgRange=AvgRange+MathAbs(iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i)-iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i+1));
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
        }
      Range=AvgRange/10;
      fastMAnow=iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i);
      fastMAprevious=iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i+1);
      slowMAnow=iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_SIGNAL, i);
      slowMAprevious=iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_SIGNAL, i+1);
      CrossUp[i]=EMPTY_VALUE;
      CrossDown[i]=EMPTY_VALUE;
      if
         (((show_KD_cross)&&(fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious))||
            ((show_K_OBOScross)&&(fastMAnow > OverSoldLevel) && (fastMAprevious < OverSoldLevel))||
            ((show_D_OBOScross)&&(slowMAnow > OverSoldLevel) && (slowMAprevious < OverSoldLevel)) )
        {
         if (i==1 && flagval1==0)
           {
            flagval1=1;
            flagval2=0;
            //if (SoundON) Alert("BUY signal at Ask=",Ask,"\n Bid=",Bid,"\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
            //if (EmailON) SendMail("BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
           }
         CrossUp[i]=Low[i] - Range*0.5;
         trade = 1;         //Buy Signal
         signal_time = TimeCurrent();
         CrossDown[i]=EMPTY_VALUE;
        }
      else if
            (((show_KD_cross)&&(fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious))||
               ((show_K_OBOScross)&&(fastMAnow < OverBoughtLevel) && (fastMAprevious > OverBoughtLevel))||
               ((show_D_OBOScross)&&(slowMAnow < OverBoughtLevel) && (slowMAprevious > OverBoughtLevel)) )
           {
            if (i==1 && flagval2==0)
              {
               flagval2=1;
               flagval1=0;
              }
            CrossDown[i]=High[i] + Range*0.5;
            trade = 2;    //Sell Signal
            signal_time = TimeCurrent();
            CrossUp[i]=EMPTY_VALUE;
           }
     }
//----
   //Print("Trade signal = ",trade_signal[0]);
   trade_signal[0] = trade;
   
   return(0);
  }
//+------------------------------------------------------------------+
 
krishna_gopal_2:
Modified Code:

You are not setting any values in the   trade_signal  buffer . . .  and you have 2 buffers with the same name,  does this code even compile ?
 
RaptorUK:
You are not setting any values in the   trade_signal  buffer . . .  and you have 2 buffers with the same name,  does this code even compile ?


I'm not getting anything from those buffers. I used original code of the indicator. Please check the test EA code given below.

Please tell me why I 'm not getting any value other than 2147483647.

double ts0,ts1;  
int init(){}
int deinit(){}
int start()
  {
     ts0=iCustom(NULL,0,"BFS_Stoc",0,0); 
     ts1=iCustom(NULL,0,"BFS_Stoc",1,0); 
     if(ts0==ts1)
     {
     Comment("No Signal @ ",ts0);
     }
     else{
     Print("Cross Up: ",ts0);
     Print("Cross Down: ",ts1);
     }
     return(0); 
  }

 Is there any problem with the shift value? I have attached the original indicator below.

Files:
bfs_stoc.mq4  6 kb
 
krishna_gopal_2:


I'm not getting anything from those buffers. I used original code of the indicator. Please check the test EA code given below.

Please tell me why I 'm not getting any value other than 2147483647.

 Is there any problem with the shift value? I have attached the original indicator below.

You are getting the buffer values for bar 0 . . .

     ts0=iCustom(NULL,0,"BFS_Stoc",0,   0  ); 
     ts1=iCustom(NULL,0,"BFS_Stoc",1  0  );

 . . . there is never an arrow at bar zero so the buffer will always hold EMPTY_VALUE for bar zero,  put the Indicator on a chart and use the Data Window to understand the values in the Indicator's buffers . . .

 

RaptorUK,

I have an EA I made that uses multiple pairs, 28 to be exact. Using iCustom, it loads every used indicator, processes all bars, and unloads every used indicator, each time (OnTimer 10 seconds) for all 28 pairs. This fills up the log fast and embedding the EA code or having an IndicatorCounted alternative (someway to count only bars needed, and has to include special cases where indicator bar uses previous bar in calculations, and get the same values as when using iCustom. There's a valid need for me to have an alternative. Can you provide a way to use an indicator (even if all I have is ex4 since that is all that is provided these days because of copy protection and less people are sharing their source code).

Thanks in advance!

Kindest regards,

Don 

 
disbellj:

I have an EA I made that uses multiple pairs, 28 to be exact. Using iCustom, it loads every used indicator, processes all bars, and unloads every used indicator, each time (OnTimer 10 seconds) for all 28 pairs. This fills up the log fast and...

Try setting the OnTimer to less than 10 sec., 1 or 2 sec. e.g. then the indicators are not unloaded.

 
GoS:

Try setting the OnTimer to less than 10 sec., 1 or 2 sec. e.g. then the indicators are not unloaded.

this is an ongoing problem before onTimer came to MT4. I always have used 1 second between updates and just changed it the other day. This is not the problem. The problem is I'm using iCustom on more than one symbol so it treats it as being on a new symbol and chart 28 times during each run.
Reason: