//---- plot indicator in a separate window #property indicator_separate_window //---- indicator buffers #property indicator_buffers 3 //---- indicator plots #property indicator_plots 1 //+-----------------------------------+ //| Indicator plot settings | //+-----------------------------------+ //---- drawing type #property indicator_type1 DRAW_COLOR_ARROW //---- colors #property indicator_color1 clrBlue,clrRed //---- the indicator line is a continuous curve #property indicator_style1 STYLE_SOLID //---- indicator line width is equal to 2 #property indicator_width1 2 //---- label #property indicator_label1 "DSS Cooper" //+----------------------------------------------+ //| Horizontal levels | //+----------------------------------------------+ #property indicator_level1 80.0 #property indicator_level2 20.0 #property indicator_levelcolor Gray #property indicator_levelstyle STYLE_DASHDOTDOT //+-----------------------------------+ //| Indicator input parameters | //+-----------------------------------+ input uint EMA_period=32; // EMA period input uint Sto_period=9; // Stochastic period input int Shift=0; // Horizontal shift (in bars) //+-----------------------------------+ //---- declaration of integer variables int min_rates_total; //---- declaration of dynamic arrays, used as indicator buffers //--- A buffer to store color indexes double DssBuffer[]; double ColorArrowColors[]; double MitBuffer[]; //---- declaration of local variables double smooth_coefficient; //+------------------------------------------------------------------+ //| XMA indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { ArraySetAsSeries(DssBuffer,true); ArraySetAsSeries(ColorArrowColors,true); ArraySetAsSeries(MitBuffer,true); //---- calc min rates needed min_rates_total=int(Sto_period+1); //---- initialization of variables smooth_coefficient=2.0/(1.0+EMA_period); PlotIndexSetString(0,PLOT_LABEL,"DSS Value"); /* PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2); PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrBlue); PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrRed);*/ //---- set DssBuffer[] as indicator buffer, and color indexes SetIndexBuffer(0,DssBuffer,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_ARROW,159); //---- set plot shift PlotIndexSetInteger(0,PLOT_SHIFT,Shift); //---- set plot draw begin PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //---- define empty value (not plotted at chart) PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); SetIndexBuffer(1,ColorArrowColors,INDICATOR_COLOR_INDEX); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE); SetIndexBuffer(2,MitBuffer,INDICATOR_CALCULATIONS); //---- prepare indicator short name string shortname; StringConcatenate(shortname,"DSS Cooper(",EMA_period,", ",Sto_period,")"); //--- set indicator short name (shown in the separate window and tooltip) IndicatorSetString(INDICATOR_SHORTNAME,shortname); //---- determination of accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,0); } //+------------------------------------------------------------------+ //| XMA iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history at current tick const int prev_calculated,// number of bars, calculated at previous call const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //---- checking of bars if(rates_total<min_rates_total) return(0); //---- declare variables of double type double HighRange,LowRange,delta,MIT,DSS,zero; //---- declare variables of integer type (used for calculated bars) int limit,bar; //---- set indexing as time series ArraySetAsSeries(low,true); ArraySetAsSeries(high,true); ArraySetAsSeries(close,true); //---- calculation of limit starting bar index if(prev_calculated>rates_total || prev_calculated<=0)// checking of first call { limit=rates_total-min_rates_total-1; // starting bar index for all bars MitBuffer[limit+1]=50; DssBuffer[limit+1]=50; } else limit=rates_total-prev_calculated; // starting bar index for new bars //---- calculation of Mit indicator values for(bar=limit; bar>=0 && !IsStopped(); bar--) { HighRange=high[ArrayMaximum(high,bar,Sto_period)]; LowRange=low[ArrayMinimum(low,bar,Sto_period)]; zero=NormalizeDouble(HighRange-LowRange,8); if(zero==0) zero=0.0000001; delta=close[bar]-LowRange; MIT=delta/(zero)*100.0; MitBuffer[bar]=smooth_coefficient*(MIT-MitBuffer[bar+1])+MitBuffer[bar+1]; } //---- calculation of DSS indicator values for(bar=limit; bar>=0 && !IsStopped(); bar--) { HighRange=MitBuffer[ArrayMaximum(MitBuffer,bar,Sto_period)]; LowRange=MitBuffer[ArrayMinimum(MitBuffer,bar,Sto_period)]; delta=MitBuffer[bar]-LowRange; zero=NormalizeDouble(HighRange-LowRange,8); if(zero==0) zero=0.0000001; DSS=delta/(zero)*100.0; DssBuffer[bar]=NormalizeDouble(smooth_coefficient*(DSS-DssBuffer[bar+1])+DssBuffer[bar+1],0); if(DssBuffer[bar]>DssBuffer[bar+1]) ColorArrowColors[bar]=0.0; else if(DssBuffer[bar]<DssBuffer[bar+1]) ColorArrowColors[bar]=1.0; else if(DssBuffer[bar]==DssBuffer[bar+1]) ColorArrowColors[bar]=ColorArrowColors[bar+1]; } //---- return(rates_total); } //+------------------------------------------------------------------+
Attention, You need to explicitly specify a character code:
//---- set DssBuffer[] as indicator buffer, and color indexes SetIndexBuffer(0,DssBuffer,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_ARROW,159); //---- set plot shift PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
Attention - zero divide:
zero=NormalizeDouble(HighRange-LowRange,8); if(zero==0) zero=0.0000001; delta=close[bar]-LowRange;
Note: ordering instructions buffers:
//---- declaration of dynamic arrays, used as indicator buffers //--- A buffer to store color indexes double DssBuffer[]; double ColorArrowColors[]; double MitBuffer[]; ... SetIndexBuffer(0,DssBuffer,INDICATOR_DATA); ... SetIndexBuffer(1,ColorArrowColors,INDICATOR_COLOR_INDEX); ... SetIndexBuffer(2,MitBuffer,INDICATOR_CALCULATIONS); //---- prepare indicator short name
barabashkakvn:
Attention, You need to explicitly specify a character code:
Attention - zero divide:
Note: ordering instructions buffers:
Thank you
Will try all.....
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello
Color arrow indicator works fine in main window (plots the arrows), but not in tester.(it shows the value but not the arrows) What is the problem?
Thanks, G
//---- plot indicator in a separate window
#property indicator_separate_window
//---- indicator buffers
#property indicator_buffers 3
//---- indicator plots
#property indicator_plots 1
//+-----------------------------------+
//| Indicator plot settings |
//+-----------------------------------+
//---- drawing type
#property indicator_type1 DRAW_COLOR_ARROW
//---- colors
#property indicator_color1 clrBlue,clrRed
//---- the indicator line is a continuous curve
#property indicator_style1 STYLE_SOLID
//---- indicator line width is equal to 2
#property indicator_width1 2
//---- label
#property indicator_label1 "DSS Cooper"
//+----------------------------------------------+
//| Horizontal levels |
//+----------------------------------------------+
#property indicator_level1 80.0
#property indicator_level2 20.0
#property indicator_levelcolor Gray
#property indicator_levelstyle STYLE_DASHDOTDOT
//+-----------------------------------+
//| Indicator input parameters |
//+-----------------------------------+
input uint EMA_period=32; // EMA period
input uint Sto_period=9; // Stochastic period
input int Shift=0; // Horizontal shift (in bars)
//+-----------------------------------+
//---- declaration of integer variables
int min_rates_total;
//---- declaration of dynamic arrays, used as indicator buffers //--- A buffer to store color indexes
double DssBuffer[],MitBuffer[], ColorArrowColors[];
//---- declaration of local variables
double smooth_coefficient;
//+------------------------------------------------------------------+
//| XMA indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
ArraySetAsSeries(ColorArrowColors,true);
ArraySetAsSeries(DssBuffer,true);
ArraySetAsSeries(MitBuffer,true);
//---- calc min rates needed
min_rates_total=int(Sto_period+1);
//---- initialization of variables
smooth_coefficient=2.0/(1.0+EMA_period);
PlotIndexSetString(0,PLOT_LABEL,"DSS Value");
/*
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrBlue);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrRed);*/
//---- set DssBuffer[] as indicator buffer, and color indexes
SetIndexBuffer(0,DssBuffer,INDICATOR_DATA);
//---- set plot shift
PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
//---- set plot draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- define empty value (not plotted at chart)
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
SetIndexBuffer(1,ColorArrowColors,INDICATOR_COLOR_INDEX);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
SetIndexBuffer(2,MitBuffer,INDICATOR_CALCULATIONS);
//---- prepare indicator short name
string shortname;
StringConcatenate(shortname,"DSS Cooper(",EMA_period,", ",Sto_period,")");
//--- set indicator short name (shown in the separate window and tooltip)
IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//---- determination of accuracy of displaying the indicator values
IndicatorSetInteger(INDICATOR_DIGITS,0);
}
//+------------------------------------------------------------------+
//| XMA iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // number of bars in history at current tick
const int prev_calculated,// number of bars, calculated at previous call
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---- checking of bars
if(rates_total<min_rates_total) return(0);
//---- declare variables of double type
double HighRange,LowRange,delta,MIT,DSS;
//---- declare variables of integer type (used for calculated bars)
int limit,bar;
//---- set indexing as time series
ArraySetAsSeries(low,true);
ArraySetAsSeries(high,true);
ArraySetAsSeries(close,true);
//---- calculation of limit starting bar index
if(prev_calculated>rates_total || prev_calculated<=0)// checking of first call
{
limit=rates_total-min_rates_total-1; // starting bar index for all bars
MitBuffer[limit+1]=50;
DssBuffer[limit+1]=50;
}
else limit=rates_total-prev_calculated; // starting bar index for new bars
//---- calculation of Mit indicator values
for(bar=limit; bar>=0 && !IsStopped(); bar--)
{
HighRange=high[ArrayMaximum(high,bar,Sto_period)];
LowRange=low[ArrayMinimum(low,bar,Sto_period)];
delta=close[bar]-LowRange;
MIT=delta/(HighRange-LowRange)*100.0;
MitBuffer[bar]=smooth_coefficient*(MIT-MitBuffer[bar+1])+MitBuffer[bar+1];
}
//---- calculation of DSS indicator values
for(bar=limit; bar>=0 && !IsStopped(); bar--)
{
HighRange=MitBuffer[ArrayMaximum(MitBuffer,bar,Sto_period)];
LowRange=MitBuffer[ArrayMinimum(MitBuffer,bar,Sto_period)];
delta=MitBuffer[bar]-LowRange;
if(HighRange-LowRange==0)
continue;
DSS=delta/(HighRange-LowRange)*100.0;
DssBuffer[bar]=NormalizeDouble(smooth_coefficient*(DSS-DssBuffer[bar+1])+DssBuffer[bar+1],0);
if(DssBuffer[bar] > DssBuffer[bar+1]) ColorArrowColors[bar] = 0;
else if(DssBuffer[bar] < DssBuffer[bar+1]) ColorArrowColors[bar] = 1;
else if(DssBuffer[bar]== DssBuffer[bar+1]) ColorArrowColors[bar]= ColorArrowColors[bar+1];
}
//----
return(rates_total);
}