Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
你好
请教一个问题就是我要在附图中画两个柱状图的差值,如下图:
但是我改编程MT4之后,达不到这个效果,重叠部分也画出来了。如下图
请问怎么解决这个问题? 烦请帮忙解答。感谢
下面是源码:
//+------------------------------------------------------------------+
//| FXBS2.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 3
//--- plot FXBS_d
#property indicator_label1 "FXBS_d"
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//--- plot FXBS_x
#property indicator_label2 "FXBS_x"
#property indicator_type2 DRAW_HISTOGRAM
#property indicator_color2 clrGreen
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//--- plot 生命线
#property indicator_label3 "生命线"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrYellow
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
input int InpPeriod_1=9; //
input int InpPeriod_2=60; //
input int InpPeriod_3=34; //
//--- indicator buffers
double FXBS_dBuffer[];
double FXBS_xBuffer[];
double 生命线Buffer[];
double VAR1Buffer[];
double VAR2Buffer[];
double VAR3Buffer[];
double VAR4Buffer[];
double VAR5Buffer[];
double VAR6Buffer[];
double VAR7Buffer[];
double VAR8Buffer[];
double VAR9Buffer[];
double VAR10Buffer[];
double VAR11Buffer[];
double VAR12Buffer[];
double VAR13Buffer[];
double VAR14Buffer[];
double VAR15Buffer[];
double VAR16Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
string short_name;
IndicatorBuffers(18);
//--- indicator buffers mapping
// SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2,Red);
// SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2,Green);
SetIndexBuffer(0,VAR12Buffer);
SetIndexBuffer(1,VAR13Buffer);
// SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Yellow);// SetIndexStyle(1,DRAW_NONE);
SetIndexBuffer(2,生命线Buffer);
SetIndexStyle(3,DRAW_NONE); // SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,White);
SetIndexBuffer(3,VAR1Buffer);
SetIndexStyle(4,DRAW_NONE); // SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1,White);
SetIndexBuffer(4,VAR2Buffer);
SetIndexStyle(5,DRAW_NONE); // SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1,White);
SetIndexBuffer(5,VAR3Buffer);
SetIndexStyle(6,DRAW_NONE); // SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1,White);
SetIndexBuffer(6,VAR4Buffer);
SetIndexStyle(7,DRAW_NONE); // SetIndexStyle(6,DRAW_LINE,STYLE_SOLID,1,Red);
SetIndexBuffer(7,VAR5Buffer);
SetIndexStyle(8,DRAW_NONE); // SetIndexStyle(7,DRAW_LINE,STYLE_SOLID,1,White);
SetIndexBuffer(8,VAR6Buffer);
SetIndexStyle(9,DRAW_NONE); // SetIndexStyle(8,DRAW_LINE,STYLE_SOLID,1,Red);
SetIndexBuffer(9,VAR7Buffer);
SetIndexStyle(10,DRAW_NONE); //SetIndexStyle(9,DRAW_LINE,STYLE_SOLID,1,White);
SetIndexBuffer(10,VAR8Buffer);
SetIndexStyle(11,DRAW_NONE); //SetIndexStyle(10,DRAW_LINE,STYLE_SOLID,1,White);
SetIndexBuffer(11,VAR9Buffer);
SetIndexStyle(12,DRAW_NONE);// SetIndexStyle(11,DRAW_LINE,STYLE_SOLID,1,White);
SetIndexBuffer(12,VAR10Buffer);
SetIndexStyle(13,DRAW_NONE); // SetIndexStyle(12,DRAW_LINE,STYLE_SOLID,1,White);
SetIndexBuffer(13,VAR11Buffer);
SetIndexStyle(14,DRAW_NONE); // SetIndexStyle(15,DRAW_LINE,STYLE_SOLID,1,Red);
SetIndexBuffer(14,VAR14Buffer);
SetIndexStyle(15,DRAW_NONE); //SetIndexStyle(16,DRAW_LINE,STYLE_SOLID,1,Red);
SetIndexBuffer(15,VAR15Buffer);
SetIndexStyle(16,DRAW_NONE); // SetIndexStyle(17,DRAW_LINE,STYLE_SOLID,1,White);
SetIndexBuffer(16,VAR16Buffer);
short_name="FXBS2("+IntegerToString(InpPeriod_1)+","+IntegerToString(InpPeriod_2)+","+IntegerToString(InpPeriod_3)+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
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[])
{
//---
int i,limit;
//---
if(rates_total<InpPeriod_2)
return(0);
//--- last counted bar will be recounted
limit=rates_total-prev_calculated;
if(prev_calculated>0)
limit++;
//--- macd counted in the 1-st buffer
for(i=0; i<limit; i++)
{
VAR1Buffer[i]= High[iHighest(NULL,0,MODE_HIGH,InpPeriod_1,i)] -Low[iLowest(NULL,0,MODE_LOW,InpPeriod_1,i)];
VAR2Buffer[i]= High[iHighest(NULL,0,MODE_HIGH,InpPeriod_1,i)]-close[i];
VAR3Buffer[i]= close[i]-Low[iLowest(NULL,0,MODE_LOW,InpPeriod_1,i)];
if(VAR1Buffer[i] !=0)
VAR4Buffer[i] =VAR2Buffer[i]/VAR1Buffer[i]*100-70;
if((High[iHighest(NULL,0,MODE_HIGH,InpPeriod_2,i)]-Low[iLowest(NULL,0,MODE_LOW,InpPeriod_2,i)])>0)
VAR5Buffer[i]=(close[i]-Low[iLowest(NULL,0,MODE_LOW,InpPeriod_2,i)])/(High[iHighest(NULL,0,MODE_HIGH,InpPeriod_2,i)]-Low[iLowest(NULL,0,MODE_LOW,InpPeriod_2,i)])*100;
VAR6Buffer[i]=(2*close[i]+high[i]+low[i])/4;
if(VAR1Buffer[i] !=0)
VAR14Buffer[i]=VAR3Buffer[i]/VAR1Buffer[i]*100;
}
for(i=0; i<limit; i++)
{
// VAR7Buffer[i]=SimpleMA(i,3,VAR14Buffer);
VAR7Buffer[i]=iMAOnArray(VAR14Buffer,0,3,0,MODE_SMA,i);
VAR8Buffer[i]=Low[iLowest(NULL,0,MODE_LOW,InpPeriod_3,i)];
}
for(i=0; i<limit; i++)
{
//VAR9Buffer[i]=SimpleMA(i,3,VAR7Buffer)-SimpleMA(i,9,VAR4Buffer);
VAR9Buffer[i]=iMAOnArray(VAR7Buffer,0,3,0,MODE_SMA,i)-iMAOnArray(VAR4Buffer,0,9,0,MODE_SMA,i);
}
for(i=0; i<limit; i++)
{
VAR10Buffer[i]=0;
if(VAR9Buffer[i]>100) VAR10Buffer[i]=VAR9Buffer[i]-100;
else VAR10Buffer[i]=0;
VAR11Buffer[i]=High[iHighest(NULL,0,MODE_HIGH,InpPeriod_3,i)];
if((VAR11Buffer[i]-VAR8Buffer[i])!=0)
VAR15Buffer[i]=(VAR6Buffer[i]-VAR8Buffer[i])/(VAR11Buffer[i]-VAR8Buffer[i])*100;
}
for(i=0; i<limit; i++)
{
//VAR12Buffer[i]=ExponentialMA(i,13,0,VAR15Buffer);
VAR12Buffer[i]=iMAOnArray(VAR15Buffer,0,13,0,MODE_EMA,i);
}
for(i=0; i<limit; i++)
{
if(prev_calculated==0 && i==limit-1)
VAR16Buffer[i]=0.667*VAR12Buffer[i]+0.333*VAR12Buffer[i];
else
VAR16Buffer[i]=0.667*VAR12Buffer[i+1]+0.333*VAR12Buffer[i];
}
for(i=0; i<limit; i++)
{
//VAR13Buffer[i]=ExponentialMA(i,2,0,VAR16Buffer);
VAR13Buffer[i]=iMAOnArray(VAR16Buffer,0,2,0,MODE_EMA,i);
}
for(i=0; i<limit; i++)
{
// 生命线Buffer[i]=ExponentialMA(i,5,0,VAR13Buffer);
生命线Buffer[i]=iMAOnArray(VAR13Buffer,0,5,0,MODE_EMA,i);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+