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..
{
//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
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..
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..
{
//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 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.
thank u very much james for your kind reply please check why arrow not appear here
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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