define Ichimoku's buffer in separate window indicator by using iIchimoku

 

i want to use value of Ichimoku buffer in my separate window indicator by using; iIchimoku

i have this:

.
.
.
//------------------------------------------------------------------------------------------ Ichimoku
input int tenkan_sen=9;              // period of Tenkan-sen
input int kijun_sen=26;              // period of Kijun-sen
input int senkou_span_b=52;          // period of Senkou Span B
//--- indicator buffer
double         Tenkan_sen[];
double         Kijun_sen[];
double         Senkou_Span_A[];
double         Senkou_Span_B[];
double         Chinkou_Span[];
//--- variable for storing the handle of the iIchimoku indicator
int    Ichimoku_handle;
.
.
.
//-----------
void OnInit()
{
 .
 . 
 .
 //------------------------------------------------------------------------------------------ Ichimoku
   SetIndexBuffer(48,Tenkan_sen,INDICATOR_DATA);         //---  INDICATOR_data_store
   ArraySetAsSeries(Tenkan_sen,true);
   
   SetIndexBuffer(49,Kijun_sen,INDICATOR_DATA);          //---  INDICATOR_data_store
   ArraySetAsSeries(Kijun_sen,true);

   SetIndexBuffer(50,Senkou_Span_A,INDICATOR_DATA);               //---  INDICATOR_data_store
   ArraySetAsSeries(Senkou_Span_A,true);

   SetIndexBuffer(51,Senkou_Span_B,INDICATOR_DATA);              //---  INDICATOR_data_store
   ArraySetAsSeries(Senkou_Span_B,true);

   SetIndexBuffer(52,Chinkou_Span,INDICATOR_CALCULATIONS);      //---  INDICATOR_data_store
   ArraySetAsSeries(Chinkou_Span,true);
   
   Ichimoku_handle=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b);
   //--- if the handle is not created
   if(Ichimoku_handle==INVALID_HANDLE) Print(" Failed to get handle of the Ichimoku indicator");
 .
 .
 .
}
//-----------
int OnCalculate(...)
{
.
.
.
//------------------------------------------------------------------------------------------ Ichimoku
   int copy_Ichimoku_Tenkan_sen=CopyBuffer(Ichimoku_handle,0,0,rates_total,Tenkan_sen);                   <---  give correct value
   int copy_Ichimoku_Kijun_sen=CopyBuffer(Ichimoku_handle,1,0,rates_total,Kijun_sen);                     <---  give correct value      
   int copy_Ichimoku_Senkou_Span_A=CopyBuffer(Ichimoku_handle,2,kijun_sen,rates_total,Senkou_Span_A);
   int copy_Ichimoku_Senkou_Span_B=CopyBuffer(Ichimoku_handle,3,-kijun_sen,rates_total,Senkou_Span_B);   <---  give correct value  
   int copy_Ichimoku_Chinkou_Span=CopyBuffer(Ichimoku_handle,4,kijun_sen,rates_total,Chinkou_Span);
//-----------
.
.
.
//--- done
   return(rates_total);
}

value for " Tenkan_sen , Kijun_sen , Senkou_Span_B " are correct but for other buffer i have problem.

can you please help.

thank's in advance.

 
TIMisthebest:

i want to use value of Ichimoku buffer in my separate window indicator by using; iIchimoku

i have this:

value for " Tenkan_sen , Kijun_sen , Senkou_Span_B " are correct but for other buffer i have problem.

can you please help.

thank's in advance.

What do you mean by "other buffer I have problem". What problem ?
 
angevoyageur:
What do you mean by "other buffer I have problem". What problem ?

hi angevoyageur, and thank you.

as you can see in below:


this buffer are wrong.

there is on chart " Ichimoku.mq5 " to campare with my indicator exit for buffer's.

i think "CopyBuffer" is incorrect , can you please check them?

 
TIMisthebest:

hi angevoyageur, and thank you.

as you can see in below:


this buffer are wrong.

You don't check the returned value of CopyBuffer, are you sure there is "rates_total" bar to copy ?

EDIT: It's an interesting exercise to understand how CopyBuffer and indicator PLOT_SHIFT works.

   if(CopyBuffer(hIchimoku,TENKANSEN_LINE,0,rates_total,TenkanBuffer)<rates_total) return(0);
   if(CopyBuffer(hIchimoku,KIJUNSEN_LINE,0,rates_total,KijunBuffer)<rates_total) return(0);
   if(CopyBuffer(hIchimoku,SENKOUSPANA_LINE,-InpKijun,rates_total,SpanABuffer)<rates_total) return(0);
   if(CopyBuffer(hIchimoku,SENKOUSPANB_LINE,-InpKijun,rates_total,SpanBBuffer)<rates_total) return(0);
   if(CopyBuffer(hIchimoku,CHINKOUSPAN_LINE,0,rates_total,ChinkouBuffer)<rates_total) return(0);

Thank you Mehrdad.

 
angevoyageur:
You don't check the returned value of CopyBuffer, are you sure there is "rates_total" bar to copy ?

!

.
.
.
//------------------------------------------------------------------------------------------ Ichimoku
input int tenkan_sen=9;              // period of Tenkan-sen
input int kijun_sen=26;              // period of Kijun-sen
input int senkou_span_b=52;          // period of Senkou Span B
//--- indicator buffer
double         Tenkan_sen[];
double         Kijun_sen[];
double         Senkou_Span_A[];
double         Senkou_Span_B[];
double         Chinkou_Span[];
//--- variable for storing the handle of the iIchimoku indicator
int    Ichimoku_handle;
//--- we will keep the number of values in the Ichimoku Kinko Hyo indicator
int    bars_calculated=0;
.
.
.
//-----------
void OnInit()
{
 .
 . 
 .
 //------------------------------------------------------------------------------------------ Ichimoku
   SetIndexBuffer(48,Tenkan_sen,INDICATOR_DATA);         //---  INDICATOR_data_store
   ArraySetAsSeries(Tenkan_sen,true);
   
   SetIndexBuffer(49,Kijun_sen,INDICATOR_DATA);          //---  INDICATOR_data_store
   ArraySetAsSeries(Kijun_sen,true);

   SetIndexBuffer(50,Senkou_Span_A,INDICATOR_DATA);               //---  INDICATOR_data_store
   ArraySetAsSeries(Senkou_Span_A,true);

   SetIndexBuffer(51,Senkou_Span_B,INDICATOR_DATA);              //---  INDICATOR_data_store
   ArraySetAsSeries(Senkou_Span_B,true);

   SetIndexBuffer(52,Chinkou_Span,INDICATOR_CALCULATIONS);      //---  INDICATOR_data_store
   ArraySetAsSeries(Chinkou_Span,true);
   
   Ichimoku_handle=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b);
   //--- if the handle is not created
   if(Ichimoku_handle==INVALID_HANDLE) Print(" Failed to get handle of the Ichimoku indicator");
 .
 .
 .
}
//-----------
int OnCalculate(...)
{
.
.
.
//------------------------------------------------------------------------------------------ Ichimoku
      //--- number of values copied from the iIchimoku indicator
   int values_to_copy;
   //--- determine the number of values calculated in the indicator
   int calculated=BarsCalculated(Ichimoku_handle);
   if(calculated<=0)
     {
      PrintFormat("BarsCalculated() returned %d, error code %d",calculated,GetLastError());
      return(0);
     }
   //--- if it is the first start of calculation of the indicator or if the number of values in the iIchimoku indicator changed
//---or if it is necessary to calculated the indicator for two or more bars (it means something has changed in the price history)
   if(prev_calculated==0 || calculated!=bars_calculated || rates_total>prev_calculated+1)
     {
      //--- if the Tenkan_sen_Buffer array is greater than the number of values in the iIchimoku indicator for symbol/period, then we don't copy everything 
      //--- otherwise, we copy less than the size of indicator buffers
      if(calculated>rates_total) values_to_copy=rates_total;
      else                       values_to_copy=calculated;
     }
   else
     {
      //--- it means that it's not the first time of the indicator calculation, and since the last call of OnCalculate())
      //--- for calculation not more than one bar is added
      values_to_copy=(rates_total-prev_calculated)+1;
     }
     
   int copy_Ichimoku_Tenkan_sen=CopyBuffer(Ichimoku_handle,0,0,values_to_copy,Tenkan_sen);
   int copy_Ichimoku_Kijun_sen=CopyBuffer(Ichimoku_handle,1,0,values_to_copy,Kijun_sen);
   int copy_Ichimoku_Senkou_Span_A=CopyBuffer(Ichimoku_handle,2,-kijun_sen,values_to_copy,Senkou_Span_A);
   int copy_Ichimoku_Senkou_Span_B=CopyBuffer(Ichimoku_handle,3,-kijun_sen,values_to_copy,Senkou_Span_B);
   int copy_Ichimoku_Chinkou_Span=CopyBuffer(Ichimoku_handle,4,0,values_to_copy,Chinkou_Span);
   
   //--- memorize the number of values in the Ichimoku Kinko Hyo indicator
   bars_calculated=calculated;
//-----------


.
.
.
//--- done
   return(rates_total);
}

this is better , isn't ? 

is this correct?
 
TIMisthebest:

!

this is better , isn't ? 

is this correct?
Yes, see my previous post.
 
angevoyageur:
Yes, see my previous post.

you answer to my next question for simplest & The easiest solution. thank you.

& there is my last problem . for " Chinkou_Span " buffer i get fault value .

i have this :

.
.
.
//------------------------------------------------------------------------------------------ Ichimoku
input int tenkan_sen=9;              // period of Tenkan-sen
input int kijun_sen=26;              // period of Kijun-sen
input int senkou_span_b=52;          // period of Senkou Span B
//--- indicator buffer
double         Tenkan_sen[];
double         Kijun_sen[];
double         Senkou_Span_A[];
double         Senkou_Span_B[];
double         Chinkou_Span[];
//--- variable for storing the handle of the iIchimoku indicator
int    Ichimoku_handle;
.
.
.
//-----------
void OnInit()
{
 .
 . 
 .
 //------------------------------------------------------------------------------------------ Ichimoku
   SetIndexBuffer(48,Tenkan_sen,INDICATOR_DATA);         //---  INDICATOR_data_store
   ArraySetAsSeries(Tenkan_sen,true);
   
   SetIndexBuffer(49,Kijun_sen,INDICATOR_DATA);          //---  INDICATOR_data_store
   ArraySetAsSeries(Kijun_sen,true);

   SetIndexBuffer(50,Senkou_Span_A,INDICATOR_DATA);               //---  INDICATOR_data_store
   ArraySetAsSeries(Senkou_Span_A,true);

   SetIndexBuffer(51,Senkou_Span_B,INDICATOR_DATA);              //---  INDICATOR_data_store
   ArraySetAsSeries(Senkou_Span_B,true);

   SetIndexBuffer(52,Chinkou_Span,INDICATOR_CALCULATIONS);      //---  INDICATOR_data_store
   ArraySetAsSeries(Chinkou_Span,true);
   
   Ichimoku_handle=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b);
   //--- if the handle is not created
   if(Ichimoku_handle==INVALID_HANDLE) Print(" Failed to get handle of the Ichimoku indicator");
 .
 .
 .
}
//-----------
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     &TickVolume[],
                const long     &Volume[],
                const int      &Spread[])
{
.
.
ArraySetAsSeries(Time,true);
.
.
//------------------------------------------------------------------------------------------ Ichimoku
 if(CopyBuffer(Ichimoku_handle,0,0,rates_total,Tenkan_sen)<rates_total) return(0);
   if(CopyBuffer(Ichimoku_handle,1,0,rates_total,Kijun_sen)<rates_total) return(0);
   if(CopyBuffer(Ichimoku_handle,2,-kijun_sen,rates_total,Senkou_Span_A)<rates_total) return(0);
   if(CopyBuffer(Ichimoku_handle,3,-kijun_sen,rates_total,Senkou_Span_B)<rates_total) return(0);
   if(CopyBuffer(Ichimoku_handle,4,0,rates_total,Chinkou_Span)<rates_total) return(0);   
//-----------
.
.
.
//--- done
   return(rates_total);
}

for " Chinkou_Span " buffer i get fault value .


where is the problem?

 
TIMisthebest:

you answer to my next question for simplest & The easiest solution. thank you.

& there is my last problem . for " Chinkou_Span " buffer i get fault value .

i have this :

for " Chinkou_Span " buffer i get fault value .


where is the problem?

It's not a fault, it's normal value for candle 0. Chikou Span is shifted to past by 26 period (Kijun input parameter), so the value for candle 0 is EMPTY VALUE, this is what you get.
 
angevoyageur:

Thank you Alain.

 

hi;

in addition, draw Ichimok's line , and this is for Tenkan_sen

.
.
int TOTAL_BAR;
.
//------------------------------------------------------------------------------------------ Ichimoku
input int tenkan_sen=9;              // period of Tenkan-sen
input int kijun_sen=26;              // period of Kijun-sen
input int senkou_span_b=52;          // period of Senkou Span B
//--- indicator buffer
double         Tenkan_sen[];
double         Kijun_sen[];
double         Senkou_Span_A[];
double         Senkou_Span_B[];
double         Chinkou_Span[];
//--- variable for storing the handle of the iIchimoku indicator
int    Ichimoku_handle;
.
.
.
//-----------
void OnInit()
{
 .
 . 
 .
 //------------------------------------------------------------------------------------------ Ichimoku
   SetIndexBuffer(49,Tenkan_sen,INDICATOR_DATA);         //---  INDICATOR_data_store
   ArraySetAsSeries(Tenkan_sen,true);
   
   SetIndexBuffer(50,Kijun_sen,INDICATOR_DATA);          //---  INDICATOR_data_store
   ArraySetAsSeries(Kijun_sen,true);

   SetIndexBuffer(51,Senkou_Span_A,INDICATOR_DATA);               //---  INDICATOR_data_store
   ArraySetAsSeries(Senkou_Span_A,true);

   SetIndexBuffer(52,Senkou_Span_B,INDICATOR_DATA);              //---  INDICATOR_data_store
   ArraySetAsSeries(Senkou_Span_B,true);

   SetIndexBuffer(53,Chinkou_Span,INDICATOR_CALCULATIONS);      //---  INDICATOR_data_store
   ArraySetAsSeries(Chinkou_Span,true);
   
   Ichimoku_handle=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b);
   //--- if the handle is not created
   if(Ichimoku_handle==INVALID_HANDLE) Print(" Failed to get handle of the Ichimoku indicator");
 .
 .
 .
}
//-----------
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     &TickVolume[],
                const long     &Volume[],
                const int      &Spread[])
{
.
.
ArraySetAsSeries(Time,true);
TOTAL_BAR=rates_total;
.
.
//------------------------------------------------------------------------------------------ Ichimoku
   if(CopyBuffer(Ichimoku_handle,0,0,rates_total,Tenkan_sen)<rates_total) return(0);
   if(CopyBuffer(Ichimoku_handle,1,0,rates_total,Kijun_sen)<rates_total) return(0);
   if(CopyBuffer(Ichimoku_handle,2,-kijun_sen,rates_total,Senkou_Span_A)<rates_total) return(0);
   if(CopyBuffer(Ichimoku_handle,3,-kijun_sen,rates_total,Senkou_Span_B)<rates_total) return(0);
   if(CopyBuffer(Ichimoku_handle,4,0,rates_total,Chinkou_Span)<rates_total) return(0);  
 
for(int ich=0; ich<rates_total-26; ich++)
      {
       Draw_Ichimoku_Tenkan_sen_Line(Time[ich+1],Time[ich],Tenkan_sen[ich+1],Tenkan_sen[ich],Aqua,STYLE_DOT);
      }
//-----------
.
.
.
//--- done
   return(rates_total);
}
.
.
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   .
   .
   for(int j=ObjectsTotal(0);j>=0;j--)
     {
      if(StringFind(ObjectName(0,j),"Tenkan_sen_Line")!=-1)
         if(!ObjectDelete(0,ObjectName(0,j)))
            Print("Error in deleting object (",GetLastError(),")");
     }
   /*  
   for(int j=0;j<=TOTAL_BAR;j++)
      {
       if(ObjectFind(0,"Tenkan_sen_Line"+TimeToString(j))>=0) 
          ObjectDelete(0,"Tenkan_sen_Line"+TimeToString(j));
      }  
    */ 
.
.
  }
//+------------------------------------------------------------------+
void Draw_Ichimoku_Tenkan_sen_Line(datetime x1,datetime x2,double y1,double y2,color lineColor,int style)
  {
   string label="Tenkan_sen_Line"+TimeToString(x1);
   if(ObjectFind(0,label)==-1)
     {
      ObjectCreate(0,label,OBJ_TREND,0,x1,y1,x2,y2);
      ObjectSetInteger(0,label,OBJPROP_COLOR,lineColor);
      ObjectSetInteger(0,label,OBJPROP_STYLE,style);
      ObjectSetInteger(0,label,OBJPROP_WIDTH,0);
      ObjectSetInteger(0,label,OBJPROP_RAY,0);
      ObjectSetInteger(0,label,OBJPROP_BACK,false);
     }
   else
     {
      ObjectMove(0,label,0,x1,y1);
      ObjectMove(0,label,1,x2,y2);
     }
  }

it is ok with current " for " used in " OnDeinit ".

for(int j=ObjectsTotal(0);j>=0;j--)
     {
      if(StringFind(ObjectName(0,j),"Tenkan_sen_Line")!=-1)
         if(!ObjectDelete(0,ObjectName(0,j)))
            Print("Error in deleting object (",GetLastError(),")");
     }

with above in " OnDeinit " it's ok.

but if i change it by this:

for(int j=0;j<=TOTAL_BAR;j++)
      {
       if(ObjectFind(0,"Tenkan_sen_Line"+TimeToString(j))>=0) 
          ObjectDelete(0,"Tenkan_sen_Line"+TimeToString(j));
      }  

in this case when time frame changed, the Tenkan_sen line for previouse time frame don't  remove.

i don't understand this ;

what is the problem in second case for  " OnDeinit " ?

 
TIMisthebest:

hi;

in addition, draw Ichimok's line , and this is for Tenkan_sen

it is ok with current " for " used in " OnDeinit ".

with above in " OnDeinit " it's ok.

but if i change it by this:

in this case when time frame changed, the Tenkan_sen line for previouse time frame don't  remove.

i don't understand this ;

what is the problem in second case for  " OnDeinit " ?

When you are removing Objects inside a loop, you always have to count down.

Why do you want to change your loop ? Also why are you using objects for Tenkan_sen and not an indicator's buffer ?