乐于分享
好东西不私藏

趋势交易必入!一款非常适合做趋势的EA源码分享

趋势交易必入!一款非常适合做趋势的EA源码分享
大家上午好,我是EA侠!
趋势交易大家都爱做,当然了侠哥也是。为啥呢?因为他顺啊。
说白了做交易是件很累的事情,天天盯盘盯到眼花,行情不好心情也不好,时间久了整个人的心态也会受到很大影响。
所以,一般来说刚入门的新手可能喜欢玩短线,刺激来钱快,但像我们这种老鸟还是喜欢做趋势,顺势而为才不费力。
不小心扯远了,今天分享给大家一个我实盘用了挺久的--ATR趋势箭头指标。
这个指标虽然不能自动下单交易,但是作为辅助我们判断趋势、找入场点位的信号指标来说还是不错的!
他的核心优势给大家整理好了,大家按需使用:

1.  信号靠谱,无重绘、无未来函数

这也是我当初选择这款指标的核心原因。很多廉价指标最让人头疼的就是“信号漂移”,盘中反复变,复盘看着准确率拉满,实盘一操作就亏。这个指标,要等新K线完全成型后才会定格信号,不会漂移、不会重绘,复盘能直接参考,实盘用着也更放心。

2.  基于ATR动态追踪,适配所有行情

它的核心逻辑是ATR动态追踪止损,和我们平时手动设的固定点位止损不一样,它能根据行情的波动大小自动调整。不管是震荡行情,还是趋势行情,都能很好适配,不用我们频繁手动修改止损参数,省了不少麻烦。

3.  支持跨周期共振,找点位更精准

这点对做波段的朋友特别友好,能实现“大周期定方向、小周期找入场”的逻辑。比如我们用H4周期定好整体趋势,再在M15周期等箭头信号进场,能大幅过滤掉无效的杂信号,入场点位也更精准,胜率自然能提升一些。

4.  操作简单,新手也能快速上手

操作特别简单,新手也能快速上手。图表上会直接显示做多、做空的箭头,一眼就能分清方向,还能自定义箭头颜色,根据自己的习惯调整。另外,它还支持普通K线和Heikin Ashi平均K线切换,喜欢用平滑K线过滤杂波的朋友,也能适配。

5.  不用时刻盯盘,有全渠道提醒

结合我自己的使用体验,它更适合做趋势跟随、波段交易的朋友。不管是中线拿单,还是上班做兼职交易,用起来都很合适,不用花费太多时间盯盘。

源码给大家分享出来,但是需要大家去编译,如果不知道怎么编译可以联系侠哥

源码:
// More information about this indicator can be found at:// https://fxcodebase.com/code/viewtopic.php?f=38&t=73431//+------------------------------------------------------------------------------------------------+//|                                                            Copyright © 2023, Gehtsoft USA LLC  |//|                                                                         http://fxcodebase.com  |//+------------------------------------------------------------------------------------------------+//|                                                                   Developed by : Mario Jemic   |//|                                                                       mario.jemic@gmail.com    |//|                                                        https://AppliedMachineLearning.systems  |//|                                                                       https://mario-jemic.com/ |//+------------------------------------------------------------------------------------------------+//+------------------------------------------------------------------------------------------------+//|                                           Our work would not be possible without your support. |//+------------------------------------------------------------------------------------------------+//|                                                               Paypal: https://goo.gl/9Rj74e    |//|                                                             Patreon :  https://goo.gl/GdXWeN   |//+------------------------------------------------------------------------------------------------+#property copyright "Copyright © 2023, Gehtsoft USA LLC"#property link "http://fxcodebase.com"#property version "1.0"#property strict#property indicator_chart_window#property indicator_buffers 2#property indicator_plots 2#property indicator_label1 "Arrow Up"#property indicator_type1  DRAW_ARROW#property indicator_color1 clrWhite#property indicator_style1 STYLE_SOLID#property indicator_width1 1#property indicator_label2 "Arrow Down"#property indicator_type2  DRAW_ARROW#property indicator_color2 clrWhite#property indicator_style2 STYLE_SOLID#property indicator_width2 1#property indicator_type2 DRAW_NONE//--- indicator buffers// ------------------------------------------------------------------extern ENUM_TIMEFRAMES TimeFrame   = PERIOD_CURRENT;    // Time frameinput double m                     = 2;      // Key value:input double atrPeriods            = 14;     // ATR periods:input bool   h                     = false;  // Signals From Heinken Ashi Candlesinput string T1                    = "== Notifications ==";  // ————————————input bool   notifications         = false;                  // Notifications On?input bool   desktop_notifications = false;                  // Desktop MT4 Notificationsinput bool   email_notifications   = false;                  // Email Notificationsinput bool   push_notifications    = false;                  // Push Mobile Notificationsinput string T2                    = "== Set Arrows ==";     // ————————————input bool   ArrowsOn              = true;                   // Arrows On?input bool   inpArrowsOnFirst      = false;                  // Arrows on first mtf barinput color  ArrowUpClr            = clrWhite;                // Arrow Up Color:input color  ArrowDnClr            = clrWhite;                 // Arrow Down Color:double ArrowUp[];double ArrowDn[];double xATRTrailingStop[],count[];//--- variablesdouble nLoss, xATR;string indicatorFileName;#define _mtfCall(_buff,_ind) iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,m,atrPeriods,h,T1,notifications,desktop_notifications,email_notifications,push_notifications,T2,ArrowsOn,inpArrowsOnFirst,ArrowUpClr,ArrowDnClr,_buff,_ind)// ------------------------------------------------------------------class CCandle{  int    _timeFrame;  string _symbol;  double _open;  double _high;  double _low;  double _close;  float  _size;  string _type;  string _direction;  float  _bodySize;  float  _shadowSup;  float  _shadowInf; public:  CCandle() { ; }  CCandle(string sym, int tf) : _symbol(sym), _timeFrame(tf) {}  ~CCandle() { ; }  // Getters  floatSize(void) { return _size; }  stringType(void) { return _type; }  doubleOpen(void) { return _open; }  doubleHigh(void) { return _high; }  doubleLow(void) { return _low; }  doubleClose(void) { return _close; }  stringDirection(void) { return _direction; }  floatBodySize(void) { return _bodySize; }  floatShadowSup(void) { return _shadowSup; }  floatShadowInf(void) { return _shadowInf; }  voidsetCandle(int shift = 1)  {    _open  = iOpen(_symbol, _timeFrame, shift);    _high  = iHigh(_symbol, _timeFrame, shift);    _low   = iLow(_symbol, _timeFrame, shift);    _close = iClose(_symbol, _timeFrame, shift);    setDirection();    setSize();    setBodySize();    setShadows();  }  voidsetSize()  {    _size = 1;    if (Distance(_high, _low, _symbol) > 0)    {      _size = Distance(_high, _low, _symbol);    }  }  voidsetBodySize()  {    _bodySize = 1;    if (Distance(_open, _close, _symbol) > 0)    {      _bodySize = Distance(_open, _close, _symbol);    }  }  voidsetDirection()  {    if (_open < _close)    {      _direction = "up";    }    if (_open > _close)    {      _direction = "down";    }    if (_open == _close)    {      _direction = "null";    }  }  voidPrintCandle()  {    Print(__FUNCTION__, " ""symbol"" ", _symbol);    Print(__FUNCTION__, " ""open"" ", _open);    Print(__FUNCTION__, " ""high"" ", _high);    Print(__FUNCTION__, " ""low"" ", _low);    Print(__FUNCTION__, " ""close"" ", _close);    Print(__FUNCTION__, " ""_size;"" ", _size);    Print(__FUNCTION__, " ""_type;"" ", _type);    Print(__FUNCTION__, " ""_direction;"" ", _direction);    Print(__FUNCTION__, " ""_bodySize;"" ", _bodySize);    Print(__FUNCTION__, " ""_shadowSup;"" ", _shadowSup);    Print(__FUNCTION__, " ""_shadowInf;"" ", _shadowInf);  }  voidsetShadows()  {    if (Direction() == "up")    {      _shadowInf = Distance(_open, _low, _symbol);      _shadowSup = Distance(_close, _high, _symbol);    }    if (Direction() == "down")    {      _shadowInf = Distance(_close, _low, _symbol);      _shadowSup = Distance(_open, _high, _symbol);    }    if (Direction() == "null")    {      _shadowInf = Distance(_close, _low, _symbol);      _shadowSup = Distance(_open, _high, _symbol);    }  }  floatDistance(double precioA, double precioB, string par)  {    double mPoint     = MarketInfo(par, MODE_POINT);    double dist       = fabs(precioA - precioB);    double distReturn = 0;    if (mPoint > 0) distReturn = dist / mPoint;    return distReturn;  }};CCandle candle1();CCandle candle2();class CNewCandle{ private:  int    _initialCandles;  string _symbol;  int    _tf; public:  CNewCandle(string symbol, int tf) : _symbol(symbol), _tf(tf), _initialCandles(iBars(symbol, tf)) {}  CNewCandle()  {    // toma los valores del chart actual    _initialCandles = iBars(Symbol(), Period());    _symbol         = Symbol();    _tf             = Period();  }  ~CNewCandle() { ; }  boolIsNewCandle()  {    int _currentCandles = iBars(_symbol, _tf);    if (_currentCandles > _initialCandles)    {      _initialCandles = _currentCandles;      return true;    }    return false;  }};CNewCandle newCandle();// ------------------------------------------------------------------intOnInit(){  IndicatorBuffers(4);  SetIndexBuffer(0, ArrowUp, INDICATOR_DATA);  SetIndexArrow(0233);  SetIndexStyle(0, DRAW_ARROW, EMPTY, 3, ArrowUpClr);  SetIndexBuffer(1, ArrowDn, INDICATOR_DATA);  SetIndexArrow(1234);  SetIndexStyle(1, DRAW_ARROW, EMPTY, 3, ArrowDnClr);  SetIndexBuffer(2, xATRTrailingStop);  //SetIndexStyle(2, DRAW_NONE);  SetIndexBuffer(3, count);  if (!ArrowsOn)  {    SetIndexStyle(0, DRAW_NONE);    SetIndexStyle(1, DRAW_NONE);  }  indicatorFileName = WindowExpertName();  TimeFrame         = fmax(TimeFrame,_Period);   return (INIT_SUCCEEDED);}voidOnDeinit(constint reason) {}// ------------------------------------------------------------------intOnCalculate(constint       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=rates_total-prev_calculated+1if (i>=rates_total) i=rates_total-1; count[0]=i;      if (TimeFrame!=_Period)      {         i = (int)fmax(i,fmin(rates_total-1,_mtfCall(3,0)*TimeFrame/_Period));         for (; i>=0 && !_StopFlag; i--)         {             int y = iBarShift(_Symbol,TimeFrame,time[i]);             int x = y;             if (inpArrowsOnFirst)                   {  if (i<rates_total-1) x = iBarShift(_Symbol,TimeFrame,time[i+1]);               }             else  {  if (i>0)             x = iBarShift(_Symbol,TimeFrame,time[i-1]); else x = -1;  }                  ArrowUp[i] = ArrowDn[i] = EMPTY_VALUE;                  if (x!=y)                  {                    ArrowUp[i] = _mtfCall(0,y);                    ArrowDn[i] = _mtfCall(1,y);                  }          }              return(rates_total);   }   //   //   //   for (; i>=0 && !_StopFlag; i--)   {     xATR  = iATR(NULL, 0, (int)atrPeriods, i);     nLoss = m * xATR;     double cl  = close[i];     double cl1 = (i<rates_total-1) ? close[i+1] : close[i];// clang-format off    xATRTrailingStop[i] = (i<rates_total-1) ? cl > xATRTrailingStop[i + 1] && cl1 > xATRTrailingStop[i + 1] ? fmax(xATRTrailingStop[i + 1], cl - nLoss) : 		   					                      cl < xATRTrailingStop[i + 1] && cl1 < xATRTrailingStop[i + 1] ? fmin(xATRTrailingStop[i + 1], cl + nLoss) : 													       cl > xATRTrailingStop[i + 1] ? cl - nLoss : cl + nLoss : 0;bool crossUp = (i<rates_total-1) ? cl > xATRTrailingStop[i] && cl1 < xATRTrailingStop[i+1] : 0;bool crossDn = (i<rates_total-1) ? cl < xATRTrailingStop[i] && cl1 > xATRTrailingStop[i+1] : 0;      ArrowUp[i] = ArrowDn[i] = EMPTY_VALUE;if (cl > xATRTrailingStop[i] && crossUp==true)    {      ArrowUp[i] = low[i] - xATR/2;      if (newCandle.IsNewCandle()) { Notifications(0); }    }    if (cl < xATRTrailingStop[i] && crossDn == true)    {      ArrowDn[i] = high[i] + xATR/2;      if (newCandle.IsNewCandle()) { Notifications(1); }    }  }  return (rates_total);}// ------------------------------------------------------------------voidsetCandles(int i, int shift){  candle1.setCandle(i + shift);  candle2.setCandle(i);}// clang-format offboolhaveSignalUp(int i) {  // TODO: signal up// double cl =  iClose(NULL,0,i);// if(cl > xATRTrailingStop[i] )  // {  //   return true;  // }  return false;}boolhaveSignalDown(int i){  // TODO: signal down// double cl =  iClose(NULL,0,i);// if(cl  < xATRTrailingStop[i] )  // {  //   return true;  // }  return false;}voidNotifications(int type){  string text = "";  if (type == 0)    text += _Symbol + " " + GetTimeFrame(_Period) + " BUY ";  else    text += _Symbol + " " + GetTimeFrame(_Period) + " SELL ";  text += " ";  if (!notifications)    return;  if (desktop_notifications)    Alert(text);  if (push_notifications)    SendNotification(text);  if (email_notifications)    SendMail("MetaTrader Notification", text);}stringGetTimeFrame(int lPeriod){  switch (lPeriod)  {    case PERIOD_M1:      return ("M1");    case PERIOD_M5:      return ("M5");    case PERIOD_M15:      return ("M15");    case PERIOD_M30:      return ("M30");    case PERIOD_H1:      return ("H1");    case PERIOD_H4:      return ("H4");    case PERIOD_D1:      return ("D1");    case PERIOD_W1:      return ("W1");    case PERIOD_MN1:      return ("MN1");  }  return IntegerToString(lPeriod);}//////string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};stringtimeFrameToString(int tf){   for (int i=ArraySize(iTfTable)-1; i>=0; i--)          if (tf==iTfTable[i]) return(sTfTable[i]);                              return("");}//+------------------------------------------------------------------------------------------------+//|                                                                    We appreciate your support. |//+------------------------------------------------------------------------------------------------+//|                                                               Paypal: https://goo.gl/9Rj74e    |//|                                                             Patreon :  https://goo.gl/GdXWeN   |//+------------------------------------------------------------------------------------------------+//|                                                                   Developed by : Mario Jemic   |//|                                                                       mario.jemic@gmail.com    |//|                                                        https://AppliedMachineLearning.systems  |//|                                                                       https://mario-jemic.com/ |//+------------------------------------------------------------------------------------------------+//+------------------------------------------------------------------------------------------------+//|BitCoin                    : 15VCJTLaz12Amr7adHSBtL9v8XomURo9RF                                 |//|Ethereum                   : 0x8C110cD61538fb6d7A2B47858F0c0AaBd663068D                         |//|SOL Address                : 4tJXw7JfwF3KUPSzrTm1CoVq6Xu4hYd1vLk3VF2mjMYh                       |//|Cardano/ADA                : addr1v868jza77crzdc87khzpppecmhmrg224qyumud6utqf6f4s99fvqv         |//|Dogecoin Address           : DBGXP1Nc18ZusSRNsj49oMEYFQgAvgBVA8                                 |//|SHIB Address               : 0x1817D9ebb000025609Bf5D61E269C64DC84DA735                         |//|Binance(ERC20 & BSC only)  : 0xe84751063de8ade7c5fbff5e73f6502f02af4e2c                         |//|BitCoin Cash               : 1BEtS465S3Su438Kc58h2sqvVvHK9Mijtg                                 |//|LiteCoin                   : LLU8PSY2vsq7B9kRELLZQcKf5nJQrdeqwD                                 |//+------------------------------------------------------------------------------------------------+