1赞

12评论

1收藏

自己写的ATR不能实时更新

avatar funky0311 | 5127 人阅读 | 12 人评论 | 2016-06-20

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Gold
#property indicator_width1  1
#property indicator_width2  2

extern int periods = 14;

double TR[];
double ATR[];

int init()
  {
   IndicatorDigits(Digits+1);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,TR);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ATR);
   IndicatorShortName("MyATR");
   SetIndexLabel(0,"TR");
   SetIndexLabel(1,"ATR");

   return(0);
  }

int start()
  {

   int counted_bars = IndicatorCounted();
   if(counted_bars > 0)
      counted_bars--;
   int remanent_bars = Bars - counted_bars;
   int i;

   for(i = 0; i < remanent_bars; i++)
      TR[i] = MAX(High[i] - Low[i], High[i] - Close[i + 1], Close[i + 1] - Low[i]);
   for(i = 0; i < remanent_bars; i++)
      ATR[i] = iMAOnArray(TR,Bars,periods,0,MODE_SMA,i);

   return(0);
  }


double MAX(double x, double y, double z)
{
   if(x < y) x = y;
   if(x < z) x = z;
   return(x);
}

有两个问题:
1. 指标只能在加载的时候执行一次,不能随新K线的出现一起更新。
2. 图表上只有波幅TR,没有均线ATR[]。

请问该怎么修改?

""
还没有人打赏,支持一下

评论|共 12 个

yujopozb

发表于 2020-1-24 19:32:41 | 显示全部楼层

前排支持下分享

笑看风云

发表于 2020-7-20 13:31:10 | 显示全部楼层

谢谢楼主分享

外汇博客

发表于 2020-8-8 22:11:19 | 显示全部楼层

帮你顶下哈!!

父亲

发表于 2020-8-26 18:46:28 | 显示全部楼层

学习了,不错

等待

发表于 2020-9-4 22:27:32 | 显示全部楼层

学习了,不错

别生气咯

发表于 2020-9-9 20:32:40 | 显示全部楼层

谢谢楼主分享

成都外汇

发表于 2020-11-18 21:08:17 | 显示全部楼层

顶下

iwnn0263

发表于 2020-11-23 21:58:34 | 显示全部楼层

支持下

umtsqmwm

发表于 2021-7-20 13:30:34 | 显示全部楼层

12下一页
您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则