Help function with stochastic

 
    void DrawAllert(string text, color C=LightGray)
    {

    ObjectCreate ("rect",OBJ_LABEL,0,0,0,0,0);
    ObjectSet ("rect",OBJPROP_XDISTANCE,10);
    ObjectSet ("rect",OBJPROP_YDISTANCE,20);
    ObjectSetText ("rect",text,10,"Times New Roman",C);
    }
    bool IperComp (double stochastic1now, double signal1now, double LimitUpIperComp, double LimitDownIperComp)
    {
    if ((stochastic1now && signal1now < LimitUpIperComp) && ( stochastic1now && signal1now > LimitDownIperComp) )
    return 1;
    else
    return 0;
    }


    bool IperVend (double stochastic1now, double signal1now, double LimitUpIperVend, double LimitDownIperVend){

    if ((stochastic1now && signal1now > LimitDownIperVend) && ( stochastic1now && signal1now < LimitUpIperVend))
    return 1;
    else
    return 0;
    }
    int start() {
    int limit, i; //counter;
    double stochastic1now, stochastic1previous, stochastic2previous, stochastic1after, signal1previous, signal1now;

    //double stochastic2after,;
    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;
    bool iperVenduto=false, iperComprato=false;
    for(i = 0; i < limit; i++) {


    stochastic1now = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,0,1,0,i); //Stocastic ora
    signal1now = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,0,1,MODE_SIGNAL,i); //Segnale ora
    stochastic1previous = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,0,1,0,i+1); //Stocastic precedente
    signal1previous = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,0,1,MODE_SIGNAL,i+1); //Segnale precedente

    if (IperComp(stochastic1now,signal1now,LimitUpIpercompr,LimitDownIpercompr))
    {
    iperComprato = true;
    }
    if (IperVend(stochastic1now,signal1now,LimitUpIpervend,LimitDownIpervend))
    {
    iperVenduto=true;
    }

    }
    if (iperComprato=true)
    DrawAllert("Gli stocastici sono in zona ipercomprato Stoc:"+ stochastic1now + "Signal:"+ signal1now, Red);
    else if (iperVenduto=true)
    DrawAllert("Gli stocastici sono in zona ipervenduto Stoc:"+ stochastic1now + "Signal:"+ signal1now, Red);

Guys I have done for this function to display the value of the stochastic signal, however, I have this problem when I insert it on the graph where there is already added to the indicator stochatstico default this happens MT:
the indicator of default MT me a value different from the value that gives me the indicator that I did, where is the error? how to correct it?
 
"Hello, I created this function to visualize the stochastic and signal value, but I have this problem:when i put it on the graph in which already is the default stochastic value MT this happens: The default stochastic value MT results as a different value compared to the value which I made, Where is the mistake? How do I fix it.    Thanks
 
  1. You shouldn't have made your second post. You should have edited your original post.
  2.  bool IperVend (double stochastic1now, double signal1now, double LimitUpIperVend, double LimitDownIperVend){
    
        if ((stochastic1now && signal1now > LimitDownIperVend) && ( stochastic1now && signal1now < LimitUpIperVend))
        return 1;
        else
        return 0;
        }
    
    stochastic1now is a double say 5. What does it mean when you write if ((5 ...?
  3. Your function returns a bool. Why are you returning an int?
  4. Simplify your code.
     bool IperVend (double NOTUSED, double signal1now, double LimitUpIperVend, double LimitDownIperVend){
        bool condition1 = signal1now > LimitDownIperVend;
        bool condition2 = signal1now < LimitUpIperVend;
        return condition1 && condition2;
    }

  5.     if(counted_bars>0) counted_bars--;
        limit=Bars-counted_bars;
    
    No need for the decrement. Contradictory information on IndicatorCounted() - MQL4 forum
    //  if(counted_bars>0) counted_bars--;
        limit=Bars-counted_bars;

  6. MODE_SIGNAL,i+1); //Segnale precedente
    Handle your lookback
    //  stochastic1now = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,0,1,0,i); //Stocastic ora
    //  signal1now = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,0,1,MODE_SIGNAL,i); //Segnale ora
    //  stochastic1previous = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,0,1,0,i+1); //Stocastic precedente
    //  signal1previous = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,0,1,MODE_SIGNAL,i+1); //Segnale precedente
    int LOOKBACK = KPeriod1 + 1;
    //  if(counted_bars>0) counted_bars--;
        if(counted_bars < LOOKBACK) counted_bars=LOOKBACK;
        limit=Bars -counted_bars;

  7. Get in the habit of counting down.
  8.     bool iperVenduto=false, iperComprato=false;
        for(i = 0; i < limit; i++) {
           :
           if (IperComp(stochastic1now,signal1now,LimitUpIpercompr,LimitDownIpercompr))
              iperComprato = true;
    
    Do you really want to issue an alert when ANY bar on the chart is IperComp? or only bar zero?
 
Any bar
Reason: