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

 
You draw in a separate window by specifiying the window number in the ObjectCreate() function.
 

Hello Phy

I tried from this morning, nothing appears in the screen. Your code would be really helpful so i can start to concentrate on others

i used object create

with type as rectangle, big and small, nothing appears on the screen. i dont know how to specifiy the time and price levels and get a candlestick pattern

Pleasse provide your code would much appreciated or an example for getting a candlestick using create Object funciton

 
Here is a sample:

It draws simple bars.

#property indicator_separate_window
 
#property indicator_buffers 2
#property indicator_color1 CLR_NONE
#property indicator_color2 CLR_NONE
 
 
double high[];
double low[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
    SetIndexBuffer(0, high);
    SetIndexBuffer(1, low);
    SetIndexStyle(0, DRAW_LINE);
    SetIndexStyle(1, DRAW_LINE);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start(){
  
   string basename = "test";
   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];
 
       string name = basename+i;
  
       if(ObjectFind(name) != -1) ObjectDelete(name);
       ObjectCreate(name, OBJ_TREND, window, Time[i], High[i], Time[i], Low[i]);
       ObjectSet(name, OBJPROP_RAY, 0);
   }
   return(0);
  }
 

Hello Phy thanks for the code, but the code does not create candle stick bars, it creates a line bar. I need something for candle stcik bars plzz..zzz,>

I am so puzzled why is it so hard to create a candlestick bar using these functions?

Please help

thanks for your support

 
So add the body:


...
...
string name = basename+i;
  
   if(ObjectFind(name) != -1) ObjectDelete(name);
       ObjectCreate(name, OBJ_TREND, window, Time[i], High[i], Time[i], Low[i]);
       ObjectSet(name, OBJPROP_RAY, 0);
   }
   name = basename+"Body"+i;
  
   if(ObjectFind(name) != -1) ObjectDelete(name);
       ObjectCreate(name, OBJ_TREND, window, Time[i], Open[i], Time[i], Close[i]);
       ObjectSet(name, OBJPROP_WIDTH, 3);
       ObjectSet(name, OBJPROP_RAY, 0);

   }
...
...
 

Finally thank you so much Got it working but the candle body is all smugged at the top and bottom why? any idea? and worse around last 20 candles...


#property indicator_separate_window

#property indicator_buffers 5
#property indicator_color1 CLR_NONE
#property indicator_color2 CLR_NONE


double high[];
double low[];
double open[];
double close[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
SetIndexStyle(3, DRAW_LINE);
SetIndexBuffer(0, high);

SetIndexBuffer(1, low);
SetIndexBuffer(2, open);
SetIndexBuffer(3, close);


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=(Open[i+1]+Close[i+1])/2;
open[i] = haOpen;
haClose=(Open[i]+High[i]+Low[i]+Close[i])/4;
close[i] = haClose;
haHigh=MathMax(haOpen,High[i]);
haLow=MathMax(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, 1);

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, 3);
//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);
}

 
What is "smugged" ?

Also, I notice there are no lower tails using your code.
I don't think your HA calculation is entirely correct.
 

Thanks phy

for your kind reply, smugged means the body are not proper rectangles the edges are curved. Your right as well, there is no bottom tails... I am wondering whyy all this.


How can i make bodies perfect rectangles like price chart?


Question:

1. We declare indicators and buffers on the top and then say index style as DRAW_LINE. Then we say insert trend line with this width and color to represent a indicator. So we just use the buffers for painting the object(trendline) do we need to declare indicators on the top and make index style as draw_line?

It is a bit confusing to have both drawline and insert object trendline?


Please your expert comments and would apprecite if you can correct my thinking?

 

THAT WAS THe problem with tails,

haLow=MathMax(haOpen,Low[i]);

should be

haLow=MathMin(haOpen,Low[i]);

My previous question still stays there please help?

for your kind reply, smugged means the body are not proper rectangles the edges are curved. How can i make bodies perfect rectangles like price chart?

Question:

1. We declare indicators and buffers on the top and then say index style as DRAW_LINE. Then we say insert trend line with this width and color to represent a indicator. So we just use the buffers for painting the object(trendline) do we need to declare indicators on the top and make index style as draw_line?

It is a bit confusing to have both drawline and insert object trendline?

Please your expert comments and would apprecite if you can correct my thinking?

 
The indicator window can be a specified size, using #property indicator_maximum and #property indicator_minumum

If these are not specified (they are not in my sample), then the indicator window resizes itself based on the displayed
highest and lowest values of one of the indicator indexes.

We never say "insert trend line"... Objects are drawn with specific time and price attributes.

The index buffers are there ( but invisible ) to appropriately size the subwindow as prices change over time.
Reason: