这是在论坛里找到的一个掘金者的指标,加载后 走过的K线有些不自动消除,需要重新加载模板或切换下时间才能完整显示,如下图
,请牛版看看源码
//+------------------------------------------------------------------------+
//| Symphonie_Trendline_Indicator_v3.0.mq4 |
//|Based on basic Trendline by MetaTrader_Experts_and_Indicators |
//+------------------------------------------------------------------------+
#property copyright "Symphonie Trader System"
#property link "MetaTrader_Experts_and_Indicators"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DodgerBlue
extern int CCIPeriod=89;
extern int ATRPeriod=1;
double TrendUp[];
double TrendDown[];
int st = 0;
//extern int SlowerEMA = 6;
//+------------------------------------------------------------------+
//| Custom indicator initialization function|
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1, TrendDown);
/*SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 159);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 159);
SetIndexBuffer(1, TrendDown);*/
/*for(int i = 0; i 0) counted_bars--;
limit=Bars-counted_bars;
for(i = limit; i >= 0; i--) {
cciTrendNow = iCCI(NULL, 0, CCIPeriod, PRICE_TYPICAL, i);
cciTrendPrevious = iCCI(NULL, 0, CCIPeriod, PRICE_TYPICAL, i+1);
//st = st * 100;
counter = i;
Range = 0;
AvgRange = 0;
for (counter = i; counter >= i-9; counter--) {
AvgRange = AvgRange + MathAbs(Low[counter]-High[counter]);
}
Range = AvgRange/10;
if (cciTrendNow >= st && cciTrendPrevious st) {
TrendDown[i+1] = TrendUp[i+1];
}
if (cciTrendNow >= st) {
TrendUp = Close - iATR(NULL, 0, ATRPeriod, i);
if (TrendUp TrendDown[i+1]) {
TrendDown = TrendDown[i+1];
}
}
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
|