Added a simple moving average with an external parameters to set period lenght (MA_Period), that will be showed on the histogram so there's no more need to change manually the Threshold line. Infact the histogram will change its color whenever the bar is above (green) or below (red) its mov avg. value, so now we get a dynamic plot accumulator
Hope you like it
Code: Select all
//+-------------------------------------------------------------------+
//| TRO PLOT Accumulator.mq4 |
//| TRO, 2007 |
//| modified by Skyline on 23 Nov 2007 |
//+-------------------------------------------------------------------+
#property copyright "Copyright ? 2007, Avery T. Horton, Jr. aka TRO"
#property link "http://www.therumpldone.com/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Orange
//---- indicator buffers
double RANGEBuffer[];
double RANGEBuffer1[];
double RANGEBuffer2[];
double TempBuffer[];
//---- indicator parameters
//extern int Threshold = 20;
extern color CurrentBarColor = Yellow;
extern color ThresholdColor = Aqua;
extern bool ShowLabel = false;
extern int MA_Period = 200;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(3,DRAW_NONE);
//---- indicator buffers mapping
SetIndexBuffer(0,RANGEBuffer);
SetIndexBuffer(1,RANGEBuffer1);
SetIndexBuffer(2,RANGEBuffer2);
SetIndexBuffer(3,TempBuffer); // non visualizzato
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("TRO PLOT ACCUMULATOR");
SetIndexLabel(0,"TRO ABOVE");
SetIndexLabel(1,"TRO BELOW");
SetIndexLabel(2,"TRO MOVING AVERAGE");
//---- initialization done
return(0);
}
int deinit()
{
ObjectDelete("CurrentBarValue");
ObjectDelete("LabelCurrentBarValue");
ObjectDelete("Threshold");
}
//+------------------------------------------------------------------+
//| Range |
//+------------------------------------------------------------------+
int start()
{
double HighVal,LowVal;
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
if(counted_bars<0) return(-1);
limit=Bars-counted_bars;
//---- RANGE counted in the 1-st buffer
for(int i=0; i<limit; i++)
{
HighVal = iHigh(NULL,0,i);
LowVal = iLow(NULL,0,i);
TempBuffer[i] = (HighVal-LowVal)/Point;
/*
// Draw Threshold line
ObjectDelete("Threshold");
ObjectCreate("Threshold", OBJ_HLINE, win_idx, Time[0], Threshold);
ObjectSet("Threshold", OBJPROP_COLOR, ThresholdColor);
ObjectSet("Threshold", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("Threshold", OBJPROP_WIDTH, 1);
ObjectSet("Threshold", OBJPROP_BACK, true);
// Label for Threshold
if ( ShowLabel == true)
{
ObjectDelete("LabelThreshold");
ObjectCreate("LabelThreshold", OBJ_TEXT, win_idx, Time[0], Threshold);
ObjectSet("LabelThreshold", OBJPROP_COLOR, ThresholdColor);
ObjectSetText("LabelThreshold", "Threshold",8);
ObjectSet("LabelThreshold", OBJPROP_ANGLE, 0);
}
*/
}
// Calculate MA of Histograms
for(int j=0; j<limit; j++)
{
RANGEBuffer2[j] = iMAOnArray(TempBuffer,0,MA_Period,0,MODE_SMA,j);
}
// Paint Histograms
for ( i=0; i<limit; i++)
{
if ( TempBuffer[i] >= RANGEBuffer2[i]) { RANGEBuffer1[i] = TempBuffer[i]; }
else { RANGEBuffer[i] = TempBuffer[i]; }
}
// Draw Current Bar line value
int win_idx=WindowFind("TRO PLOT ACCUMULATOR");
ObjectDelete("CurrentBarValue");
ObjectCreate("CurrentBarValue", OBJ_HLINE, win_idx, Time[0], (iHigh(NULL,0,0)-iLow(NULL,0,0))/Point);
ObjectSet("CurrentBarValue", OBJPROP_COLOR, CurrentBarColor);
ObjectSet("CurrentBarValue", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("CurrentBarValue", OBJPROP_WIDTH, 1);
ObjectSet("CurrentBarValue", OBJPROP_BACK, true);
// Label per Current Bar Line
if ( ShowLabel == true )
{
ObjectDelete("LabelCurrentBarValue");
ObjectCreate("LabelCurrentBarValue", OBJ_TEXT, win_idx, Time[0], (iHigh(NULL,0,0)-iLow(NULL,0,0))/Point);
ObjectSet("LabelCurrentBarValue", OBJPROP_COLOR, CurrentBarColor);
ObjectSetText("LabelCurrentBarValue", "Current Bar value",8);
ObjectSet("LabelCurrentBarValue", OBJPROP_ANGLE, 0);
}
//---- done
return(0);
}