un-needed lines on Stochastic

 

Hello there,
I am working on a indicator in which i could switch between oscillators indicators ; and i am implementing the indicators but i have a problem with the stochastic.

Undesired lines are drawn ;
i need them not to be drawn BUT with no level set in #property

// I don't want to set levels to hide the extra lines

// #property indicator_minimum    0
// #property indicator_maximum    100

....i didn't succed to do it.
I tried with "DRAW_NONE", "NULL"...etc

I need your help please.

Here is the screen shot :


And here is the Stochactic indicator's code :

//+------------------------------------------------------------------+
//|                                                   Stochastic.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Stochastic Oscillator"
#property strict

#property indicator_separate_window
// #property indicator_minimum    0
// #property indicator_maximum    100
#property indicator_buffers    9
#property indicator_color6     LightSeaGreen
#property indicator_color7     Red
#property indicator_level1     20.0
#property indicator_level2     80.0
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT
//--- input parameters
input int InpKPeriod=5; // K Period
input int InpDPeriod=3; // D Period
input int InpSlowing=3; // Slowing
//--- buffers
double Sto_ExtMainBuffer[];
double Sto_ExtSignalBuffer[];
double Sto_ExtHighesBuffer[];
double Sto_ExtLowesBuffer[];
//---
int Sto_draw_begin1=0;
int Sto_draw_begin2=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
    
//--- STO
   string short_name;
//--- 2 additional buffers are used for counting.
  //  IndicatorBuffers(4);
   SetIndexBuffer(7, Sto_ExtHighesBuffer);
   SetIndexBuffer(8, Sto_ExtLowesBuffer);
//--- indicator lines
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5, Sto_ExtMainBuffer);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6, Sto_ExtSignalBuffer);
//--- name for DataWindow and indicator subwindow label
   short_name="Sto("+IntegerToString(InpKPeriod)+","+IntegerToString(InpDPeriod)+","+IntegerToString(InpSlowing)+")";
   IndicatorShortName(short_name);
   SetIndexLabel(5,short_name);
   SetIndexLabel(6,"Signal");
//---
   Sto_draw_begin1=InpKPeriod+InpSlowing;
   Sto_draw_begin2=Sto_draw_begin1+InpDPeriod;
   SetIndexDrawBegin(5,Sto_draw_begin1);
   SetIndexDrawBegin(6,Sto_draw_begin2);
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Stochastic oscillator                                            |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {  
//--- STO
   int    i_Sto,k,pos;
//--- check for bars count
   if(rates_total<=InpKPeriod+InpDPeriod+InpSlowing)
      return(0);
//--- counting from 0 to rates_total
   ArraySetAsSeries(Sto_ExtMainBuffer,false);
   ArraySetAsSeries(Sto_ExtSignalBuffer,false);
   ArraySetAsSeries(Sto_ExtHighesBuffer,false);
   ArraySetAsSeries(Sto_ExtLowesBuffer,false);
   ArraySetAsSeries(low,false);
   ArraySetAsSeries(high,false);
   ArraySetAsSeries(close,false);
//---
   pos=InpKPeriod-1;
   if(pos+1<prev_calculated)
      pos=prev_calculated-2;
   else
     {
      for(i_Sto=0; i_Sto<pos; i_Sto++)
        {
         Sto_ExtLowesBuffer[i_Sto]=0.0;
         Sto_ExtHighesBuffer[i_Sto]=0.0;
        }
     }
//--- calculate HighesBuffer[] and Sto_ExtHighesBuffer[]
   for(i_Sto=pos; i_Sto<rates_total && !IsStopped(); i_Sto++)
     {
      double dmin=1000000.0;
      double dmax=-1000000.0;
      for(k=i_Sto-InpKPeriod+1; k<=i_Sto; k++)
        {
         if(dmin>low[k])
            dmin=low[k];
         if(dmax<high[k])
            dmax=high[k];
        }
      Sto_ExtLowesBuffer[i_Sto]=dmin;
      Sto_ExtHighesBuffer[i_Sto]=dmax;
     }
//--- %K line
   pos=InpKPeriod-1+InpSlowing-1;
   if(pos+1<prev_calculated)
      pos=prev_calculated-2;
   else
     {
      for(i_Sto=0; i_Sto<pos; i_Sto++)
         Sto_ExtMainBuffer[i_Sto]=0.0;
     }
//--- main cycle
   for(i_Sto=pos; i_Sto<rates_total && !IsStopped(); i_Sto++)
     {
      double sumlow=0.0;
      double sumhigh=0.0;
      for(k=(i_Sto-InpSlowing+1); k<=i_Sto; k++)
        {
         sumlow +=(close[k]-Sto_ExtLowesBuffer[k]);
         sumhigh+=(Sto_ExtHighesBuffer[k]-Sto_ExtLowesBuffer[k]);
        }
      if(sumhigh==0.0)
         Sto_ExtMainBuffer[i_Sto]=100.0;
      else
         Sto_ExtMainBuffer[i_Sto]=sumlow/sumhigh*100.0;
     }
//--- signal
   pos=InpDPeriod-1;
   if(pos+1<prev_calculated)
      pos=prev_calculated-2;
   else
     {
      for(i_Sto=0; i_Sto<pos; i_Sto++)
         Sto_ExtSignalBuffer[i_Sto]=0.0;
     }
   for(i_Sto=pos; i_Sto<rates_total && !IsStopped(); i_Sto++)
     {
      double sum=0.0;
      for(k=0; k<InpDPeriod; k++)
         sum+=Sto_ExtMainBuffer[i_Sto-k];
      Sto_ExtSignalBuffer[i_Sto]=sum/InpDPeriod;
     }
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Thierry Ramaniraka:

Hello there,
I am working on a indicator in which i could switch between oscillators indicators ; and i am implementing the indicators but i have a problem with the stochastic.

Undesired lines are drawn ;
i need them not to be drawn BUT with no level set in #property

....i didn't succed to do it.
I tried with "DRAW_NONE", "NULL"...etc

I need your help please.

Here is the screen shot :


And here is the Stochactic indicator's code :

Hi dear,

Which lines do you mean?

Level Lines?

 
Arash Lakzadeh:

Hi dear,

Which lines do you mean?

Level Lines?

hello,
It's the black line swan in the screen shot (just above the stochastic).
 
Thierry Ramaniraka:

Hello there,
I am working on a indicator in which i could switch between oscillators indicators ; and i am implementing the indicators but i have a problem with the stochastic.

Undesired lines are drawn ;
i need them not to be drawn BUT with no level set in #property

....i didn't succed to do it.
I tried with "DRAW_NONE", "NULL"...etc

I need your help please.

Here is the screen shot :


And here is the Stochactic indicator's code :

Your problem is in indexing. I've attached an updated code. Hope it helps.
Files:
 
Petr Nosek:
Your problem is in indexing. I've attached an updated code. Hope it helps.

Thank you for your help.
Now i can see where the problem came from.
But my problem still remain because, i need the "original" indexing i gave, because there are others indicators / Buffers, before the stochastic.

How can i keep your result with my indexing ?
Still need help.

Regards.

 
Thierry Ramaniraka:

Thank you for your help.
Now i can see where the problem came from.
But my problem still remain because, i need the "original" indexing i gave, because there are others indicators / Buffers, before the stochastic.

How can i keep your result with my indexing ?
Still need help.

Regards.

Without your broken code I can't help you. If you want you can send me your whole code and I will try to fix it.

 
Petr Nosek:

Without your broken code I can't help you. If you want you can send me your whole code and I will try to fix it.

Really perfect.
Thank you very for your kind help.

: )

Reason: