Download MetaTrader 5
To add comments, please log in or register
Improve your rating. Execute orders in Freelance service!
udaqe
11
udaqe 2009.08.31 14:29 

Hi all


I have the following Heikin Ashi Smoothed indicator and i am trying to add it in a subwindow instead of the main window.

i changed the #property indicator_chart_window to indicator_separate_window but i get the following picture. i have the original heikin ashi smoothed in the main window and the one after the change in the subwindow, as you can see i have some problems.


Any help will be welcomed.


//+------------------------------------------------------------------+
//|                                         Heiken Ashi Smoothed.mq4 |
//|                                                                  |
//|                                                      mod by Raff |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "https://www.forex-tsd.com/"
//----
#property  indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 Lime
//---- parameters
extern int MaMetod =2;
extern int MaPeriod=6;
extern int MaMetod2 =3;
extern int MaPeriod2=2;
extern string smbl="EURUSD";
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int init()
  {
//---- indicators
   IndicatorBuffers(8);
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, Red);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, Lime);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, Red);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, Lime);
   SetIndexBuffer(3, ExtMapBuffer4);
//----
   SetIndexDrawBegin(0,5);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexBuffer(7,ExtMapBuffer8);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double maOpen, maClose, maLow, maHigh;
   double haOpen, haHigh, haLow, haClose;
   if(Bars<=10) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
   int pos=Bars-ExtCountedBars-1;
   while(pos>=0)
     {
      maOpen=iMA(smbl,0,MaPeriod,0,MaMetod,MODE_OPEN,pos);
      maClose=iMA(smbl,0,MaPeriod,0,MaMetod,MODE_CLOSE,pos);
      maLow=iMA(smbl,0,MaPeriod,0,MaMetod,MODE_LOW,pos);
      maHigh=iMA(smbl,0,MaPeriod,0,MaMetod,MODE_HIGH,pos);
//----
      haOpen=(ExtMapBuffer5[pos+1]+ExtMapBuffer6[pos+1])/2;
      haClose=(maOpen+maHigh+maLow+maClose)/4;
      haHigh=MathMax(maHigh, MathMax(haOpen, haClose));
      haLow=MathMin(maLow, MathMin(haOpen, haClose));
      if (haOpen<haClose)
        {
         ExtMapBuffer7[pos]=haLow;
         ExtMapBuffer8[pos]=haHigh;
        }
      else
        {
         ExtMapBuffer7[pos]=haHigh;
         ExtMapBuffer8[pos]=haLow;
        }
      ExtMapBuffer5[pos]=haOpen;
      ExtMapBuffer6[pos]=haClose;
      pos--;
     }
   int i;
   for(i=0; i<Bars; i++) ExtMapBuffer1[i]=iMAOnArray(ExtMapBuffer7,Bars,MaPeriod2,0,MaMetod2,i);
   for(i=0; i<Bars; i++) ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer8,Bars,MaPeriod2,0,MaMetod2,i);
   for(i=0; i<Bars; i++) ExtMapBuffer3[i]=iMAOnArray(ExtMapBuffer5,Bars,MaPeriod2,0,MaMetod2,i);
   for(i=0; i<Bars; i++) ExtMapBuffer4[i]=iMAOnArray(ExtMapBuffer6,Bars,MaPeriod2,0,MaMetod2,i);
//----
   return(0);
  }
//+------------------------------------------------------------------+
Ray
2655
Ray 2009.08.31 19:54  

Histogram can make "candle bars" in the main window, but cannot do it in a sub-window

If you want bars in a subwindow, you have to draw them using ObjectCreate().

David McCollum
29
David McCollum 2009.09.02 16:59  
phy:

Histogram can make "candle bars" in the main window, but cannot do it in a sub-window

If you want bars in a subwindow, you have to draw them using ObjectCreate().

Phy,


Is it possible to show a code example of how you use ObjectCreate() to build your "candles" in the sub-window? This a very interesting concept!


I'd like to be able to replace the Kumo histogram in the Ichimoku indicator with with a drawing solution that completely fills or shades in the area between the Senkou Span A & Senkou Span B (cloud). Maybe it is possible to accomplish that by using ObjectCreate() to construct the Kumo as apposed to a histogram. Your thoughts or ideas?


Thanks!!

Ray
2655
Ray 2009.09.02 18:15  

ObjectCreate(wickName, OBJ_TREND, subwindowNumber, barTime, High, barTimeLow);

ObjectSet(wickName,..., ...) Set width 1, set no ray

ObjectCreate(bodyName, OBJ_TREND, subwindowNumber, barTime, High, barTimeLow);

ObjectSet(bodyName,..., ...) Set width 3 or 5, set no ray

use new names for each bar

David McCollum
29
David McCollum 2009.09.04 03:30  
phy:

ObjectCreate(wickName, OBJ_TREND, subwindowNumber, barTime, High, barTimeLow);

ObjectSet(wickName,..., ...) Set width 1, set no ray

ObjectCreate(bodyName, OBJ_TREND, subwindowNumber, barTime, High, barTimeLow);

ObjectSet(bodyName,..., ...) Set width 3 or 5, set no ray

use new names for each bar

Thanks for your reply!!!

whroeder1
13653
whroeder1 2016.09.02 12:38  
udaqe111: i changed the #property indicator_chart_window to indicator_separate_window but i get the following picture. i have the original heikin ashi smoothed in the main window and the one after the change in the subwindow, as you can see i have some problems.
  1. This is because on the main window, the bars are drawn between two histogram buffers. On the subwindow, they are drawn between the buffer and zero
  2. See my solution How to Draw Cnadle chart in indicator_separate_window ? (XDXD) - MQL4 forum

Fernando Carreiro
1571
Fernando Carreiro 2016.09.02 14:18  
WHRoeder:
  1. This is because on the main window, the bars are drawn between two histogram buffers. On the subwindow, they are drawn between the buffer and zero
  2. See my solution How to Draw Cnadle chart in indicator_separate_window ? (XDXD) - MQL4 forum
Just curious! Why are you answering a post/thread that is 7 years old?
whroeder1
13653
whroeder1 2016.09.02 14:48  
FMIC: Just curious! Why are you answering a post/thread that is 7 years old?
Only because the spam (deleted by moderator) brought it to the top.
/
To add comments, please log in or register