I am a newbie and want to get HA in a new window.. - page 3

 

Thanks for that

What role does this line do SetIndexStyle(0, DRAW_LINE) in the above code when we have just used Objects to draw line? Do we need to mention them at all, I understand the role of buffers I dont know why a buffer should be linked to a index and why an index should have style as what we see is out of the createObject call with price atributes?


Did u see your self using above code the candles have curved edges and not pure rectangles as price chart?

 

I have explained it already.

If you want rectangles draw rectangles instead of trendline objects.

 

Hello Phy

Sorry for being a pain, RECTANGLE option dint work, thats why i am troubling you, thanks for your patience and please try this and let me know, I have fixed the HA calculations.

Please try one last time thanks, I wish i can get this rectangle work properly.


#property indicator_separate_window

#property indicator_buffers 6
#property indicator_color1 CLR_NONE
#property indicator_color2 CLR_NONE


double high[];
double low[];
double open[];
double close[];
double haOpen1[];
double haClose1[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
SetIndexStyle(3, DRAW_LINE);
SetIndexStyle(4, DRAW_LINE);
SetIndexStyle(5, DRAW_LINE);
SetIndexBuffer(0, high);
SetIndexBuffer(1, low);
SetIndexBuffer(2, open);
SetIndexBuffer(3, close);
SetIndexBuffer(4, haOpen1);
SetIndexBuffer(5, haClose1);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{

return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start(){

string basename = "Heikin-Ashi";
IndicatorShortName(basename);
int window = WindowFind(basename);

for (int i = Bars-100; i >= 0; i--){

// these two indexes are used to control the size of the subwindow
// they are not visible
high[i] = High[i];
low[i] = Low[i];
double haOpen, haHigh, haLow, haClose,haDiffCo;
haOpen=(haOpen1[i+1]+haClose1[i+1])/2;
haOpen1[i] = haOpen;
haClose=(Open[i]+High[i]+Low[i]+Close[i])/4;
haClose1[i] = haClose;
haHigh=MathMax(haOpen,High[i]);
haLow=MathMin(haOpen,Low[i]);
string name1 = "Heikin-Ashi-HL-"+i;

if(ObjectFind(name1) != -1) ObjectDelete(name1);
ObjectCreate(name1, OBJ_TREND, window, Time[i], haHigh, Time[i], haLow);
ObjectSet(name1, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(name1, OBJPROP_RAY, 0);
ObjectSet(name1, OBJPROP_WIDTH, 2);

string name2 = "Heikin-Ashi-OC-"+i;
if(ObjectFind(name2) != -1) ObjectDelete(name2);
ObjectCreate(name2, OBJ_RECTANGLE, window, Time[i], haOpen, Time[i], haClose);
ObjectSet(name2, OBJPROP_WIDTH, 5);
//ObjectSet(name2, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(name2, OBJPROP_RAY, 0);

if (haOpen < haClose) {
ObjectSet(name1, OBJPROP_COLOR, Chartreuse);
ObjectSet(name2, OBJPROP_COLOR, Chartreuse);
}else{
ObjectSet(name1, OBJPROP_COLOR, Red);
ObjectSet(name2, OBJPROP_COLOR, Red);
}

}

return(0);
}

 

The candles should be trendlines

Body width 2 or more likely, 3

I don't know what you are talking about "rounding" of the lines


Show a picture

 
See picture plz..
 

Sometimes when you scroll to the left you get this as well (Mixed green and red)

 

Yes, I see that.

I think you have some stale bars to delete there.

 
thanks for your reply,How to do that?
 

figure out what is wrong, then think about how you might fix it. are there duplicate bars, what's happening?

 

Hello Phy

If I am right, the problem might be due to the fact i do this

SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
SetIndexStyle(3, DRAW_LINE);
SetIndexStyle(4, DRAW_LINE);
SetIndexStyle(5, DRAW_LINE);

I do the above and make the buffers to be drawn and at the same time i do


if(ObjectFind(name1) != -1) ObjectDelete(name1);
ObjectCreate(name1, OBJ_TREND, window, Time[i], haHigh, Time[i], haLow);
ObjectSet(name1, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(name1, OBJPROP_RAY, 0);
ObjectSet(name1, OBJPROP_WIDTH, 2);

string name2 = "Heikin-Ashi-OC-"+i;
if(ObjectFind(name2) != -1) ObjectDelete(name2);
ObjectCreate(name2, OBJ_TREND, window, Time[i], haOpen, Time[i], haClose);
ObjectSet(name2, OBJPROP_WIDTH, 5);
//ObjectSet(name2, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(name2, OBJPROP_RAY, 0);

So both the data in buffer and the objects are drawn on top of each other, Am i correct?

I should remove the setting of index style code as i am just using the buffer for data storage and do not want to draw it?

I am right?