自己写的指标 在趋势中动态止损

楼主  收藏   举报   帖子创建时间:  2019-05-05 05:53 回复:0 关注量:785
  1. #property indicator_chart_window
  2. #property indicator_buffers 2
  3. #property indicator_color1 DodgerBlue
  4. #property indicator_color2 DodgerBlue
  5. //---- input parameters
  6. extern   double target=2;
  7. extern int AtrPeriod=20;
  8. //---- buffers
  9. double Up[],Dn[];

  10. //+------------------------------------------------------------------+
  11. //| Custom indicator initialization function                         |
  12. //+------------------------------------------------------------------+
  13. int init()
  14.   {
  15.    string short_name;
  16.    IndicatorBuffers(2);
  17. //---- indicator line
  18.    SetIndexStyle(0,DRAW_LINE);
  19.    SetIndexStyle(1,DRAW_LINE);
  20.    SetIndexBuffer(0,Up);
  21.    SetIndexBuffer(1,Dn);
  22. //---- name for DataWindow and indicator subwindow label
  23.    short_name="ATR("+AtrPeriod+")";
  24.    IndicatorShortName(short_name);
  25.    SetIndexLabel(0,short_name);
  26.    SetIndexLabel(1,short_name);
  27. //----
  28.    SetIndexDrawBegin(0,AtrPeriod);
  29.    SetIndexDrawBegin(1,AtrPeriod);
  30. //----
  31.    return(0);
  32.   }
  33. //+------------------------------------------------------------------+
  34. //| Average True Range                                               |
  35. //+------------------------------------------------------------------+
  36. int start()
  37.   {
  38.    int i,counted_bars=IndicatorCounted();
  39. //----
  40.    if(counted_bars>0) counted_bars--;
  41.    int limit=Bars-counted_bars;
  42.    
  43.    for(i=0; i<limit; i++)
  44.    {
  45.       Up[i]=Open[i]+target*iATR(NULL,0,AtrPeriod,i);
  46.       Dn[i]=Open[i]-target*iATR(NULL,0,AtrPeriod,i);
  47.     }
  48. //----
  49.    return(0);
  50.   }
  51. //+------------------------------------------------------------------+
打赏