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

 
angevoyageur:

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

2) Why do you want to change your loop ?

3) Also why are you using objects for Tenkan_sen and not an indicator's buffer ?

1)  !?    i don't understand what do you mean .  do you mean below ?

     & i used this in " OnDeinit " but still have problem :

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

 do you mean above ?

2) i want learn this case and solve this problem if it is possible.

3)i have this :

.
.
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;
string Ichimoku_Line;
.
.
.
//-----------
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_Line("Tenkan_sen_Line"+TimeToString(Time[ich+1]),Time[ich+1],Time[ich],Tenkan_sen[ich+1],Tenkan_sen[ich],clrRed,STYLE_DOT);
       Draw_Ichimoku_Line("Kijun_sen_Line"+TimeToString(Time[ich+1]),Time[ich+1],Time[ich],Kijun_sen[ich+1],Kijun_sen[ich],clrBlue,STYLE_DOT);
       Draw_Ichimoku_Line("Senkou_Span_A_Line"+TimeToString(Time[ich+1]),Time[ich+1],Time[ich],Senkou_Span_A[ich+1],Senkou_Span_A[ich],clrWhite,STYLE_SOLID);
       Draw_Ichimoku_Line("Senkou_Span_B_Line"+TimeToString(Time[ich+1]),Time[ich+1],Time[ich],Senkou_Span_B[ich+1],Senkou_Span_B[ich],clrWheat,STYLE_SOLID);
       Draw_Ichimoku_Line("Chinkou_Span_Line"+TimeToString(Time[ich+1]),Time[ich+1],Time[ich],Chinkou_Span[ich+1],Chinkou_Span[ich],clrLime,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(),")");
      
      if(StringFind(ObjectName(0,j),"Kijun_sen_Line")!=-1)
         if(!ObjectDelete(0,ObjectName(0,j)))
            Print("Error in deleting object (",GetLastError(),")");
      
      if(StringFind(ObjectName(0,j),"Senkou_Span_A_Line")!=-1)
         if(!ObjectDelete(0,ObjectName(0,j)))
            Print("Error in deleting object (",GetLastError(),")");
      
      if(StringFind(ObjectName(0,j),"Senkou_Span_B_Line")!=-1)
         if(!ObjectDelete(0,ObjectName(0,j)))
            Print("Error in deleting object (",GetLastError(),")");
            
      if(StringFind(ObjectName(0,j),"Chinkou_Span_Line")!=-1)
         if(!ObjectDelete(0,ObjectName(0,j)))
            Print("Error in deleting object (",GetLastError(),")");
     }
   
.
  }
//+------------------------------------------------------------------+
void Draw_Ichimoku_Line(string label,datetime x1,datetime x2,double y1,double y2,color lineColor,int style)
  {
   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);
     }
  }
and i want draw Ichimok's line in chart. ( my indicator is seperate window indicator )

i want to have Ichimok's directly from buffer's i have from copybuffer ,

and the other problem is to shift " Senkou_Span_A_Line & Senkou_Span_B_Line " to forward , 

 

1° You are drawing your objects (ichimoku) with name like :

"Tenkan_sen_Line"+TimeToString(Time[ich+1])

so you can't delete them with :

ObjectDelete(0,"Tenkan_sen_Line"+TimeToString(j));

Instead you have to use :

ObjectDelete(0,"Tenkan_sen_Line"+TimeToString(Time[j]));
 

2° You always have to count down when removing object from a collection of objects.

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(),")");
     }

If you are doing this :

for(int j=0;j<ObjectsTotal(0);j++)

Imagine object with j=0 is deleted. ObjectsTotal(0) will change and indexing also, your object 1 become object 0.

So your new object 0 will remain on the chart, even if it's an object you want to delete, as j is now=1.

 

3° If you want Ichimoku on main chart, while using buffer's value in your indicator (on a separate window), why not simply add to Ichimoku indicator on the main chart ?

  ChartIndicatorAdd(0,0,Ichimoku_handle);
See documentation.
 

4° About "the other problem is to shift Senkou_Span_A_Line & Senkou_Span_B_Line to forwar". Ad this line in your OnInit() function, replacing plot with good plot number.

//--- lines shifts when drawing

   PlotIndexSetInteger(plot,PLOT_SHIFT,kijun_sen);
 

wow... thank you;

*  i could not connect to the www.mql5 ( for few min. ) is this was by control from you to answer to me ?

/////////////

start with 1.

1) i try this before;

Time[] is in  :

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[])
{

and in this case :


should define it before?

 

angevoyageur:

2° You always have to count down when removing object from a collection of objects.

4° About "the other problem is to shift Senkou_Span_A_Line & Senkou_Span_B_Line to forwar". Ad this line in your OnInit() function, replacing plot with good plot number.

2) thank you for explaination.

4) i have draw lines by " OBJ_TREND " & "  void Draw_Ichimoku_Line() "

in this case

PlotIndexSetInteger(plot,PLOT_SHIFT,kijun_sen);

 plot = ?


Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Drawing Styles
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Drawing Styles
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Drawing Styles - Documentation on MQL5
 
TIMisthebest:

2) thank you for explaination.

4) i have draw lines by " OBJ_TREND " & "  void Draw_Ichimoku_Line() "

in this case

 plot = ?


In this case plot=nothing, what I suggested is for indicator's plot.
 
TIMisthebest:

wow... thank you;

*  i could not connect to the www.mql5 ( for few min. ) is this was by control from you to answer to me

Of course not.


/////////////

start with 1.

1) i try this before;

Time[] is in  :

and in this case :


should define it before?

Yes, Time[] is define for OnCalculate(), if you need it outside you have to define it one way or another.

But, I think you are over-complicate things. If you want to remove objects draw by your indicator, you can do it with 1 simple loop.

 
angevoyageur:
Of course not.

Yes, Time[] is define for OnCalculate(), if you need it outside you have to define it one way or another.

But, I think you are over-complicate things.

If you want to remove objects draw by your indicator, you can do it with 1 simple loop.

2 & 3 & 4 )

thank you , i used :

if(!ChartIndicatorAdd(0,0,Ichimoku_handle))
     {
      PrintFormat("Failed to add MACD indicator on %d chart window. Error code  %d",
                  0,GetLastError());
     }   

very good . i do not know this.

===================

HOW ?????????????????  

Reason: