What is wrong with my indicator?

 

I am trying to write an indicator that draws 3 Stochastics curves on the same subwindow:

1. First one to show moment of the current time frame

2. Second one is to show cycle in the current time frame (reduced period...)

3. Third one is to show moment on a bigger time frame

However I am having ugly results, possibly a bug? (image attached)




My code is as follows:


//+------------------------------------------------------------------+
//|                                                 _KKK_tmpHere.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//+-- My work starts here
#property indicator_buffers 6
#property indicator_separate_window // Drawing in a separate window
#property indicator_width1 1 
#property indicator_width2 1
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 3
#property indicator_width6 3
// #property indicator_color1  // Color defined below as I am trying
// #property indicator_width2  // out several methods
#property indicator_width3 Cyan
#property indicator_width4 Green
#property indicator_color5 Blue
#property indicator_color6 Red

double FractalK[]  ;
double FractalD[]  ;
double CycleK[] ;
double CycleD[] ;
double MomentK[];
double MomentD[];

//+----------------------------------------------------- [M: Moment]-+
 extern int  MK=8, MD=3, MSlow=3;  
//+------------------------------------------------------ [C: Cycle]-+
 extern int  CK=5, CD=3, CSlow=2;
//+---------------------------------------------------- [F: Fractal]-+
 extern int  FK=5, FD=3, SlowF=3;  int TimeF;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,FractalK);  SetIndexStyle(0, STYLE_SOLID, 2, Red);
SetIndexBuffer(1,FractalD);  SetIndexStyle(1, STYLE_SOLID, 2, Red);
SetIndexBuffer(2,CycleK ) ;  SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(3,CycleD)  ;  SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(4,MomentK) ;  SetIndexStyle(4,DRAW_LINE);
SetIndexBuffer(5,MomentD) ;  SetIndexStyle(5,DRAW_LINE); 
//--- Now go and chose your Fractal Time (higher time frame)
TimeF = TimeFractal(Period()); 
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
{
//--- Now calc and draw your Stochastics
for(int i=Bars-1; i>=0 ; i--) 
{
MomentK[i]  = iStochastic(NULL,0,    MK,MD,MSlow,0,0,MODE_MAIN,1);
MomentD[i]  = iStochastic(NULL,0,    MK,MD,MSlow,0,0,MODE_MAIN,1);
CycleK[i]   = iStochastic(NULL,0,    CK,CD,CSlow,0,0,MODE_MAIN,1);
CycleK[i]   = iStochastic(NULL,0,    CK,CD,CSlow,0,0,MODE_MAIN,1);
FractalK[i] = iStochastic(NULL,TimeF,FK,FD,MSlow,0,0,MODE_MAIN,1);
FractalD[i] = iStochastic(NULL,TimeF,FK,FD,MSlow,0,0,MODE_MAIN,1); 
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| fractalTime                                                      |
//| Proposes the most suitable higher time frame                     |
//+------------------------------------------------------------------+
int TimeFractal(int Tîm) 
{
int fractalTime = 1440;
switch(Tîm)                                 
 {  
  case 1440: fractalTime=10080   ; break;  // 1Day >> 1 Week ratio: 5
  case 240:  fractalTime=1440    ; break;  // 4hr  >> 1 Day  ratio: 6
  case 60:   fractalTime=240     ; break;  // 1hr  >> 4hr    ratio: 4 
  case 30:   fractalTime=90      ; break;  // 30mn >> 90mn   ratio: 3  
  case 15:   fractalTime=60      ; break;  // 15mn >> 1hr    ratio: 4 
  case 5:    fractalTime=15      ; break;  // 5mn  >> 15mn   ratio: 3
  default:   fractalTime=1440    ; break;  // xxx  >> 1 Day  ratio: x
 }           
return fractalTime;        
}   


Can you help me, please?

 
Ziad El:
 

Can you help me, please?

Instead of your part of code:

#property indicator_width2 Cyan
#property indicator_width3 Green

try this:

#property indicator_color3 Cyan
#property indicator_color4 Green
 

Thank you Petr,

that solved one problem...

But what about lines being straight?

 

Ok I found the mistake..

This is my first indicator, so I was very confused and forgot basic things...


MomentK[i]  = iStochastic(NULL,0,    MK,MD,MSlow,0,0,MODE_MAIN,i);
MomentD[i]  = iStochastic(NULL,0,    MK,MD,MSlow,0,0,MODE_MAIN,i);
CycleK[i]   = iStochastic(NULL,0,    CK,CD,CSlow,0,0,MODE_MAIN,i);
CycleK[i]   = iStochastic(NULL,0,    CK,CD,CSlow,0,0,MODE_MAIN,i);
FractalK[i] = iStochastic(NULL,TimeF,FK,FD,MSlow,0,0,MODE_MAIN,i);
FractalD[i] = iStochastic(NULL,TimeF,FK,FD,MSlow,0,0,MODE_MAIN,i); 
}

I should have inserted "i" for the shift...