# Help little program with stochastic

113
2014.07.28 18:41

Hello everyone, I'll post a little program that I've done:

The program should report me 2 of the stochastic crosses that occur sussessivamente inclusion of 'AE in the graph instead of as soon as I insert the graphic print "DrawAllert (" cross 2 Time = "+ TimeToStr (curtime (), TIME_DATE) +" "+ TimeHour (curtime ()) + ":" + TimeMinute (curtime ()), 15,15, Green); "Updating the time every 2 or 3 min? there is something wrong but I can not figure out what help me?
Then I tried to get me to print the values ​​of "mainnow = iStochastic (NULL, 1, KPeriod1, DPeriod1, Slowing1, Mame thod1, PriceField1, 0, j);
signalnow = iStochastic (NULL, 0, KPeriod1, DPeriod1, Slowing1, Mame thod1, PriceField1, 1, j), "but if I do I print vaalori and compare them with the values ​​of the Mt4 stochastic oscillator are not the same and I always wondered why, know how to give me an explanation?

```#property indicator_chart_window
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
extern int       KPeriod1     =  5;
extern int       DPeriod1     =  3;
extern int       Slowing1     =  3;
extern string note3 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int       MAMethod1    =   0;
extern string note4 = "0=high/low, 1=close/close";
extern int       PriceField1  =   0;

int deinit()
{
//----
ClearObjects();
return(0);
}
void ClearObjects()
{
for(int i=0;i<ObjectsTotal();i++)
{ ObjectDelete(ObjectName(i)); i--; }
}
void DrawAllert(string text, int xdistance, int ydistance, color C=LightGray)
{

ObjectCreate         ("rect",OBJ_LABEL,0,0,0,0,0);
ObjectSet            ("rect",OBJPROP_XDISTANCE,xdistance);
ObjectSet            ("rect",OBJPROP_YDISTANCE,ydistance);
ObjectSetText ("rect",text,20,"Times New Roman",C);
}
bool NewBar()
{
static datetime lastbar;
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);

}
else
return(false);
}
int start() {
int limit;
double mainnow, signalnow, mainprevious, signalprevious, mainafter, signalafter;
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(int j = 0; j <= limit; j++)
{

mainnow = iStochastic(NULL,1,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,0,j);
mainprevious = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,0,j+1);
mainafter = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,0,j-1);
signalnow = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,1,j);
signalprevious = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,1,j+1);
signalafter = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,1,j-1);

if( NewBar() && (mainnow>signalnow) && (mainprevious<signalprevious) && (mainnow>signalnow)))
{
DrawAllert("incrocio Time = "+ TimeToStr(CurTime(),TIME_DATE)+" " + TimeHour(CurTime())+":"+ TimeMinute(CurTime()),10,10,Green);
DrawAllert("incrocio 2 Time = "+ TimeToStr(CurTime(),TIME_DATE)+" " + TimeHour(CurTime())+":"+ TimeMinute(CurTime()),15,15,Green);
}
}
return (0);
}```
440
2014.08.01 11:13
texcs:

Hello everyone, I'll post a little program that I've done:

The program should report me 2 of the stochastic crosses that occur sussessivamente inclusion of 'AE in the graph instead of as soon as I insert the graphic print "DrawAllert (" cross 2 Time = "+ TimeToStr (curtime (), TIME_DATE) +" "+ TimeHour (curtime ()) + ":" + TimeMinute (curtime ()), 15,15, Green); "Updating the time every 2 or 3 min? there is something wrong but I can not figure out what help me?
Then I tried to get me to print the values ​​of "mainnow = iStochastic (NULL, 1, KPeriod1, DPeriod1, Slowing1, Mame thod1, PriceField1, 0, j);
signalnow = iStochastic (NULL, 0, KPeriod1, DPeriod1, Slowing1, Mame thod1, PriceField1, 1, j), "but if I do I print vaalori and compare them with the values ​​of the Mt4 stochastic oscillator are not the same and I always wondered why, know how to give me an explanation?

Hi texcs:,

The way you constructed the indicator has flaws and the code posted has small errors . In the conditions line , at the end you have an extra parenthesis .

` if( NewBar() && (mainnow>signalnow) && (mainprevious<signalprevious) && (mainnow>signalnow))) //here`

Then , you need to check if the object already exists before you try to create it , else you get error trying to create an object that already is there  .

Next, you really want to create both objects at the same time ?

Is what you want to have a label to tell you when was the most recent cross was and a second one to tell you when the previous one was ?

Are you looking for two crosses in the same direction?

Also you have condition 1 : (mainnow>signalnow) same as condition 3 :(mainnow>signalnow).

I think I have an idea but I'm not sure if I'm right about what you want.

Maybe you can try to explain a bit better.

Cheers

113
2014.08.01 12:40

I have corrected as follows:

``` if( NewBar() && (mainprevious<signalprevious) && (mainnow>signalnow))//&&(signalnow<21)&& (mainnow<21))
{
DrawAllert("incrocio Time = "+ TimeToStr(CurTime(),TIME_DATE)+" " + TimeHour(CurTime())+":"+ TimeMinute(CurTime()),10,10,Green);
DrawAllert("incrocio 2 Time = "+ TimeToStr(CurTime(),TIME_DATE)+" " + TimeHour(CurTime())+":"+ TimeMinute(CurTime()),15,15,Green);
} ```
I would like to report me to the last 2 crossings that occur after the EA how do I start?
440
2014.08.01 21:42
texcs:

I have corrected as follows:

I would like to report me to the last 2 crossings that occur after the EA how do I start?

Sorry buddy, still not clear about what you want.

I understand that you want 2 crossings. Do the crossing have to be the same direction or not?

After you start the EA is clear, you only want new crossings, but are you looking for one direction only?

I'm asking because you only have one set of conditions

` if( NewBar() && (mainprevious<signalprevious) && (mainnow>signalnow))//&&(signalnow<21)&& (mainnow<21))`

Clarify that and I'll let you know how I'd do it.

Is it anything like the picture attached?

113
2014.08.04 15:33

At the end of the program I must advise of the following:
1) crossing the stochastic lower between 0 and 20
2) re-opening of the 2 lines upward
3) crossing the stochastic higher between 80 and 100
4) re-opening of the 2 lines do

113
2014.09.06 11:49
thrdel:

Sorry buddy, still not clear about what you want.

I understand that you want 2 crossings. Do the crossing have to be the same direction or not?

After you start the EA is clear, you only want new crossings, but are you looking for one direction only?

I'm asking because you only have one set of conditions

Clarify that and I'll let you know how I'd do it.

Is it anything like the picture attached?

`Let's recap all, the program must show me only the last crossing`
/