第七色最新导航地址:[i★] 23 副图macd在主图显信号

来源:百度文库 编辑:偶看新闻 时间:2024/04/27 22:04:06
副图macd在主图显信号  

2011-07-01 16:42:10|  分类: 好指标 |  标签: |字号大中小 订阅

 

// [i] 23 副图macd在主图显信号 (含未来)

#property indicator_buffers 5
#property indicator_separate_window
#property indicator_color1 HotPink
#property indicator_color2 Lime
#property indicator_color3 Gray
#property indicator_color4 Blue
#property indicator_color5 Black

double 现MACD粉线[];
double 信号绿线[];
double 灰柱线[];
double 前MACD蓝线[];
double 零水平黑线[];
//
extern int 快Ma周期          = 12;
extern int 慢Ma周期          = 26;
extern int 信Ma周期          = 9;
extern bool 使用箭头显示信号 = true;
extern double 验证点值       = 0;      // 因含当前值的变动,故使用曾变动一定幅度来做为确认

int  最少计 = 0;
int  i      = 0;
bool 买信号 = false;
bool 卖信号 = false;

//------------初始化-------------+

int init()
  {
   ObjectsDeleteAll();

   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 2);
   SetIndexStyle(3, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, 1);
   //
   SetIndexBuffer(0, 现MACD粉线);
   SetIndexBuffer(1, 信号绿线);
   SetIndexBuffer(2, 灰柱线);
   SetIndexBuffer(3, 前MACD蓝线);
   SetIndexBuffer(4, 零水平黑线);

   SetIndexDrawBegin(1, 信Ma周期);

   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS)+1);

   IndicatorShortName("MACD("+快Ma周期+", "+慢Ma周期+", "+信Ma周期+")");

   SetIndexLabel(0, "现MACD");
   SetIndexLabel(1, "现信号线");
   SetIndexLabel(2, "差柱");
   SetIndexLabel(3, "前一MACD");
   SetIndexLabel(4, "0");
   //
   return(0);
  }
 
//------------绘制主图箭头 子函数()---------------+

string 绘制主图箭头子(datetime 时标X, double 价标Y, color 用色)
  {
   //--名称
   string 箭头名= StringConcatenate("箭头", 用色, "-", TimeToStr(时标X)); // 转换为字串
  
   //--选定箭码
   int    箭头码= SYMBOL_STOPSIGN;  // 默认为叉
   if(用色==Blue)
      箭头码= SYMBOL_ARROWUP;       // 上涨箭头
   if(用色==Red)
      箭头码= SYMBOL_ARROWDOWN;     // 下跌箭头
     
   //--创置物件
   ObjectCreate(箭头名, OBJ_ARROW, 0, 时标X, 价标Y);  // 0 为主图显示
   ObjectSet(箭头名, OBJPROP_ARROWCODE, 箭头码);
   ObjectSet(箭头名, OBJPROP_COLOR, 用色);
   ObjectSet(箭头名, OBJPROP_WIDTH, 1);
   //--刷新绘制
   WindowRedraw();
  
   return(箭头名);
  }
 
//-------------反初始化--------------+

int deinit()
  {
   ObjectsRedraw();
   return(0);
  }
 
//-------------主函数--------------+

int start()
  {
   int 已计= IndicatorCounted();
   if(已计<0)
      return(-1);
   if(已计>0)
      已计--;
   最少计= Bars-已计;

   for(i=0; i<最少计; i++)
      现MACD粉线[i]= iMA(NULL, 0, 快Ma周期, 0, MODE_EMA, PRICE_CLOSE, i)-iMA(NULL, 0, 慢Ma周期, 0, MODE_EMA, PRICE_CLOSE, i);

   for(i=0; i<最少计; i++)
      信号绿线[i]= iMAOnArray(现MACD粉线, Bars, 信Ma周期, 0, MODE_SMA, i);

   for(i=0; i<最少计; i++)
     {
      灰柱线[i]= (现MACD粉线[i]-信号绿线[i])*2;
      零水平黑线[i]= 0;
     }

   for(i=1; i<最少计; i++)
      前MACD蓝线[i]= iMA(NULL, 0, 快Ma周期, 0, MODE_EMA, PRICE_CLOSE, i-1)-iMA(NULL, 0, 慢Ma周期, 0, MODE_EMA, PRICE_CLOSE, i-1);

   if(使用箭头显示信号==true)
     {
      ObjectsDeleteAll();
      买信号= false;
      卖信号= false;
      //--(以下信号含未来函数)
      for(int i=Bars;i>= 0;i--){
         //--上穿
         if(灰柱线[i-1]>0 && 灰柱线[i]<0 && 灰柱线[i-1]>验证点值){
            string 蓝上涨箭= 绘制主图箭头子(Time[i-1], Low[i-1]+0.0005, Blue);
            买信号= true;
        
           }
         //--下穿
         if(灰柱线[i-1]<0 && 灰柱线[i]>0 && 灰柱线[i-1]<-验证点值){
            string 红下跌箭= 绘制主图箭头子(Time[i-1], High[i-1]-0.0003, Red);
            卖信号= true;
 
           }
         //--下跌趋势中的逆拐点
         if(卖信号==true && 灰柱线[i-1]>灰柱线[i])//Short End
           {
            string 青上穿箭= 绘制主图箭头子(Time[i-1], Low[i-1]-0.0003, Aqua);
            卖信号= false;
           }
         //--上涨趋势中的逆拐点
         if(买信号==true && 灰柱线[i-1]<灰柱线[i])//Long End
           {
            string 青下穿箭= 绘制主图箭头子(Time[i-1], High[i-1]+0.0005, Aqua);
            买信号= false;  
           }
        }
     }
   return(0);
  }