Problem Double Stoch Arrow

 

hello friends

i m working on double stoch  arrow indicator ..two stoch i use 5,3,3 and 14,3,3 logic is when both stoch>50 buy arrow appears if both two stoch<50 sell arrow appear this inidcator works good but missing some arrows please modify and guide me where i m wrong here is code and chart 

 

I suspect that where you are not seeing arrows that the 2 stochastics have not crossed the level on the same bar, your code requires that they both cross on the same bar. So you need to re-think. Maybe just have 1 cross and the other just be above/below the level.

I surprised that you code runs without an array out of range error.


 int limit = rates_total;
 int count=prev_calculated;
 //Main function
 for(int i=limit-count; i>=0;i--)
 {
 //Getting Stochastic buffer values using the iCustom function
  double Stoch1 = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_MAIN,i);
  double Stoch2 = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_MAIN,i+1);
 
  double Stoch3 = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MODE_SMA,0,MODE_MAIN,i);
  double Stoch4 = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MODE_SMA,0,MODE_MAIN,i+1);


when prev_calculated==0

i=rates_total, whereas the highest bar index will be rates_total-1

then you check i+1, so it should be 2 bars out of range

maybe use something like


 int i=prev_calculated>0 ? rates_total-prev_calculated : rates_total-2;
 //Main function
 for(;i>=0;i--)



 

I believe the reason he is not getting an array out of range is because he is not calling an array such as the High[i+1] or Close[i+1]. When the iStochastic() function reaches those unavailable candles it just stores a zero... If you will put this in your code.. you can see the very first stoch values generated on the left edge of the chart. Note it takes 20 iterations to fully get all four pieces of stoch information..

for(int i=limit-count; i>limit-20;i--)
{
//Getting Stochastic buffer values using the iCustom function
  double Stoch1 = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_MAIN,i);
  double Stoch2 = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_MAIN,i+1);
  
  double Stoch3 = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MODE_SMA,0,MODE_MAIN,i);
  double Stoch4 = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MODE_SMA,0,MODE_MAIN,i+1);
  Print("Oldest Bar is ",Bars-1," i is ",i," Stoch1 is ",Stoch1,"   Stoch2 is ",Stoch2,"   Stoch3 is ",Stoch3,"   Stoch4 is ",Stoch4);

Experts Journal Showing the first 20 Iterations

The faster stoch will many time cross the 50 before the slower stoch. You may want to alter your code so that it makes and arrow when the slower stoch has JUST crossed up and the faster is still up.. or the slower has just crossed down and the fast is still down...

  
  if(Stoch1>Level && Stoch3>Level  && Stoch4<Level   )
  {
   UP[i]=Low[i]-distance*MyPoint;
   if(CTime!=Time[0])
    {
     if(PopUpAlert){Alert(Symbol()," ","Buy Arrow");}
     if(EmailAlert){SendMail(Symbol()+" Buy Arrow"+"","Buy Signal");}
     if(PushAlert){SendNotification(Symbol()+" Buy Arrow"+"");}
     CTime=Time[0];
    }
  }
  if(Stoch1<Level && Stoch3<Level && Stoch4>Level )
  {
   DOWN[i]=High[i]+distance*MyPoint;
   if(CTime!=Time[0])
    {
     if(PopUpAlert){Alert(Symbol()," ","Sell Arrow");}
     if(EmailAlert){SendMail(Symbol()+" Sell Arrow"+"","Sell Signal");}
     if(PushAlert){SendNotification(Symbol()+" Sell Arrow"+"");}
     CTime=Time[0];
    }
  }

 

PipPip...Jimdandy 

 
James Hodges:

I believe the reason he is not getting an array out of range is because he is not calling an array such as the High[i+1] or Close[i+1]. When the iStochastic() function reaches those unavailable candles it just stores a zero... If you will put this in your code.. you can see the very first stoch values generated on the left edge of the chart. Note it takes 20 iterations to fully get all four pieces of stoch information..

Yes, of course you are right. As the stochastic calls return zero, an out of range buffer can't be given a value.
 
thank u very much for your kind response.. i just need arrow when both stoch>50 or both stoch<50 doest not matter wich candle when both below or above 50 then arrow show
 
James Hodges:

I believe the reason he is not getting an array out of range is because he is not calling an array such as the High[i+1] or Close[i+1]. When the iStochastic() function reaches those unavailable candles it just stores a zero... If you will put this in your code.. you can see the very first stoch values generated on the left edge of the chart. Note it takes 20 iterations to fully get all four pieces of stoch information..

for(int i=limit-count; i>limit-20;i--)
{
//Getting Stochastic buffer values using the iCustom function
  double Stoch1 = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_MAIN,i);
  double Stoch2 = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_MAIN,i+1);
  
  double Stoch3 = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MODE_SMA,0,MODE_MAIN,i);
  double Stoch4 = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MODE_SMA,0,MODE_MAIN,i+1);
  Print("Oldest Bar is ",Bars-1," i is ",i," Stoch1 is ",Stoch1,"   Stoch2 is ",Stoch2,"   Stoch3 is ",Stoch3,"   Stoch4 is ",Stoch4);


The faster stoch will many time cross the 50 before the slower stoch. You may want to alter your code so that it makes and arrow when the slower stoch has JUST crossed up and the faster is still up.. or the slower has just crossed down and the fast is still down...

  
  if(Stoch1>Level && Stoch3>Level  && Stoch4<Level   )
  {
   UP[i]=Low[i]-distance*MyPoint;
   if(CTime!=Time[0])
    {
     if(PopUpAlert){Alert(Symbol()," ","Buy Arrow");}
     if(EmailAlert){SendMail(Symbol()+" Buy Arrow"+"","Buy Signal");}
     if(PushAlert){SendNotification(Symbol()+" Buy Arrow"+"");}
     CTime=Time[0];
    }
  }
  if(Stoch1<Level && Stoch3<Level && Stoch4>Level )
  {
   DOWN[i]=High[i]+distance*MyPoint;
   if(CTime!=Time[0])
    {
     if(PopUpAlert){Alert(Symbol()," ","Sell Arrow");}
     if(EmailAlert){SendMail(Symbol()+" Sell Arrow"+"","Sell Signal");}
     if(PushAlert){SendNotification(Symbol()+" Sell Arrow"+"");}
     CTime=Time[0];
    }
  }

 

PipPip...Jimdandy 

thank u very much james for your kind reply please check why arrow not appear here
Files:
 
zahidmahmood:
thank u very much for your kind response.. i just need arrow when both stoch>50 or both stoch<50 doest not matter wich candle when both below or above 50 then arrow show

You could use a static bool, set it to true when both are above the level.

Then if the bool is true, don't set any more arrows until they are both below the level, place the arrow and set the bool to false.

In other words, when the bool is true, only check for both below. If false, only check for both above.

Mind you, when you use something like this, you should not check bar[0], so only check closed bars. Otherwise it gets a bit more complicated.

 
zahidmahmood:
thank u very much james for your kind reply please check why arrow not appear here
As you have already been told, your code as it stands will only place an arrow when both stochastics cross the level on the same bar.
 
Keith Watford:
As you have already been told, your code as it stands will only place an arrow when both stochastics cross the level on the same bar.
 
zahidmahmood:
I don't see how that first arrow was placed with your code, have you changed it?
 
please check this