|
- //+------------------------------------------------------------------+
- //| 多均线交叉.mq4 |
- //| Copyright 2018, MetaQuotes Software Corp. |
- //| https://www.mql5.com |
- //+------------------------------------------------------------------+
- #property copyright "Copyright 2018, MetaQuotes Software Corp."
- #property link "https://www.mql5.com"
- #property version "1.00"
- #property strict
- #property indicator_chart_window
- #property indicator_buffers 7
- #property indicator_plots 7
- extern int MA1 = 5;
- extern int MA2 = 10;
- extern int MA3 = 20;
- extern int MA4 = 30;
- extern int MA5 = 60;
- extern string 选择 = "默认选择最后两个均线交叉,标出箭头";
- extern string 选择1 = "如需其他均线交叉请修改其数值";
- extern ENUM_MA_METHOD method = MODE_SMA;
- datetime time1 = 0;
- int 箭头间隔 = 100,juli = 20;
- //--- plot ma1
- #property indicator_label1 "ma1"
- #property indicator_type1 DRAW_LINE
- #property indicator_color1 clrYellow
- #property indicator_style1 STYLE_SOLID
- #property indicator_width1 1
- //--- plot ma2
- #property indicator_label2 "ma2"
- #property indicator_type2 DRAW_LINE
- #property indicator_color2 clrPink
- #property indicator_style2 STYLE_SOLID
- #property indicator_width2 1
- //--- plot ma3
- #property indicator_label3 "ma3"
- #property indicator_type3 DRAW_LINE
- #property indicator_color3 clrRed
- #property indicator_style3 STYLE_SOLID
- #property indicator_width3 1
- //--- plot ma4
- #property indicator_label4 "ma4"
- #property indicator_type4 DRAW_LINE
- #property indicator_color4 clrDeepSkyBlue
- #property indicator_style4 STYLE_SOLID
- #property indicator_width4 1
- //--- plot ma5
- #property indicator_label5 "ma5"
- #property indicator_type5 DRAW_LINE
- #property indicator_color5 clrLightSeaGreen
- #property indicator_style5 STYLE_SOLID
- #property indicator_width5 1
- //--- indicator buffers
- double ma1Buffer[];
- double ma2Buffer[];
- double ma3Buffer[];
- double ma4Buffer[];
- double ma5Buffer[];
- double upBuffer[];
- double downBuffer[];
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- //--- indicator buffers mapping
- SetIndexBuffer(0,ma1Buffer);
- SetIndexBuffer(1,ma2Buffer);
- SetIndexBuffer(2,ma3Buffer);
- SetIndexBuffer(3,ma4Buffer);
- SetIndexBuffer(4,ma5Buffer);
- SetIndexBuffer(5,upBuffer);
- SetIndexBuffer(6,downBuffer);
-
- SetIndexStyle(5,DRAW_ARROW,0,3,clrMagenta);
- SetIndexArrow(5,241);
- SetIndexLabel(5,"up");
-
- SetIndexStyle(6,DRAW_ARROW,0,3,clrYellow);
- SetIndexArrow(6,242);
- SetIndexLabel(6,"down");
-
- if(Period() == 5){ 箭头间隔 = 15;juli = 20;} //Period()返回当前图表的时间表 属于几分钟图
- if(Period() == 15){ 箭头间隔 = 25;juli =30;}
- if(Period() == 30){ 箭头间隔 = 35;juli =40;}
- if(Period() == 60){ 箭头间隔 = 66;juli =50;}
- if(Period() == 240){ 箭头间隔 = 88;juli =66;}
- if(Period() == 1440){ 箭头间隔 = 150;juli = 100;}
- if(Period() == 10080){ 箭头间隔 = 250;juli = 120;}
- if(Period() == 1){ 箭头间隔 = 10;juli =15;}
- //---
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| Custom indicator iteration function |
- //+------------------------------------------------------------------+
- int OnCalculate(const int 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 counted_bars=IndicatorCounted();
- if (counted_bars<0) return(-1);
- if (counted_bars>0) counted_bars--;
- int limit=Bars-counted_bars;
-
-
- for(int i=limit-3; i>=0; i--)//int i=0;i<5000;i++)
- {
-
- ma1Buffer[i] = iMA(Symbol(),PERIOD_CURRENT,MA1,0,method,PRICE_CLOSE,i); //最后一个参数表示第几个MA值
- ma2Buffer[i] = iMA(Symbol(),PERIOD_CURRENT,MA2,0,method,PRICE_CLOSE,i);
- ma3Buffer[i] = iMA(Symbol(),PERIOD_CURRENT,MA3,0,method,PRICE_CLOSE,i);
- ma4Buffer[i] = iMA(Symbol(),PERIOD_CURRENT,MA4,0,method,PRICE_CLOSE,i);
- ma5Buffer[i] = iMA(Symbol(),PERIOD_CURRENT,MA5,0,method,PRICE_CLOSE,i);
-
- if(ma4Buffer[i+2]<ma5Buffer[i+2] && ma4Buffer[i+1]>ma5Buffer[i+1]){
- upBuffer[i] = Low[i] - 箭头间隔*Point;
-
- }
-
- if(ma4Buffer[i+2]>ma5Buffer[i+2] && ma4Buffer[i+1]<ma5Buffer[i+1]){
- downBuffer[i] = High[i] + 箭头间隔*Point;
-
- }
-
- }
- return(rates_total);
- }
- //+------------------------------------------------------------------+
复制代码 |
|