MQL5變色線畫法(比MQL4更簡單) [MT4]
作者:
MT4 來源:
cxh99.com 發布時間:2012年05月25日 點擊數:
【
收藏到本網的會員中心】
- MQL5里有一種特殊指標數組“顏色數組”,他是和畫線的指標數組配合使用的。通過對他的簡單賦值可以使畫出的線變色。
首先要在指標頭部定義里指定一條線對應的數組是要使用變色畫線方式,指定方法是:
#property indicator_typeX DRAW_COLOR_LINE
這里X代表畫線的數組序號
DRAW_COLOR_LINE代表畫線,此外還可以有如下畫線方式:
復制代碼-
- DRAW_COLOR_LINE
- Colorful Line彩色線
- DRAW_COLOR_SECTION
- Multicolored section彩色塊
- DRAW_COLOR_HISTOGRAM
- Multicolored histogram from the zero line彩色柱狀圖
- DRAW_COLOR_HISTOGRAM2
- Multicolored histogram of the two indicator buffers彩色柱狀圖2
- DRAW_COLOR_ARROW
- Drawing colored arrows彩色箭頭
- DRAW_COLOR_ZIGZAG
- Colorful ZigZag彩色ZigZag
- DRAW_COLOR_BARS
- Multi-colored bars彩色竹線圖
- DRAW_COLOR_CANDLES
- Multi-colored candles彩色蠟燭圖
然后緊跟一個顏色的定義語句:
#property indicator_colorX Red,Green
兩個顏色之間用逗號分隔
============================================
針對上面程序頭部的定義,之后要開始全局數組的定義。
這里要注意實現變色需要針對一條線使用兩個數組,
例如:
double bMaBuffer[],bColorBuffer[];
然后進入OnInit事件進行兩個數組的分別設定:
SetIndexBuffer(0,bMaBuffer,INDICATOR_DATA);//INDICATOR_DATA表示是用于畫線的數組
SetIndexBuffer(1,bColorBuffer,INDICATOR_COLOR_INDEX);//INDICATOR_COLOR_INDEX表示是用于變色的顏色數組
注意:
如果這里要畫多條彩色線,則畫線數組和顏色數組的序號要緊鄰。
============================================
下一步就是在OnCaculate事件里進行畫線數組的計算,同時根據自定義的條件對顏色數組進行賦值。
賦值規則是:
當對應K線序號的顏色數組被賦值1.0時,對應畫線數組的顏色為 第一個顏色
當對應K線序號的顏色數組被賦值0.0時,對應畫線數組的顏色為 第二個顏色
完。
程序舉例源碼如下:【畫出兩個變色線】
復制代碼- //+------------------------------------------------------------------+
- //| Test.mq5 |
- //| Copyright 2009, MetaQuotes Software Corp. |
- //| http://bbs.520fx.com |
- //+------------------------------------------------------------------+
- #property copyright "2009, 520FX"
- #property link "http://www.mql5.com"
- #property version "1.00"
- #property indicator_chart_window
- #property indicator_buffers 4
- #property indicator_plots 2
- #property indicator_color1 Red,Green
- #property indicator_type1 DRAW_COLOR_LINE
- #property indicator_style1 STYLE_SOLID
- #property indicator_width1 2
- #property indicator_color2 Yellow,Blue
- #property indicator_type2 DRAW_COLOR_LINE
- #property indicator_style2 STYLE_SOLID
- #property indicator_width2 2
- input int MaPeriod=13;
- double bMaBuffer[],bMaBuffer1[],bColorBuffer[],bColorBuffer1[];
- int iMaHandle,iMaHandle1;
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- //--- indicator buffers mapping
- SetIndexBuffer(0,bMaBuffer,INDICATOR_DATA);
- SetIndexBuffer(1,bColorBuffer,INDICATOR_COLOR_INDEX);
- SetIndexBuffer(2,bMaBuffer1,INDICATOR_DATA);
- SetIndexBuffer(3,bColorBuffer1,INDICATOR_COLOR_INDEX);
- IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
- iMaHandle=iMA(NULL,0,MaPeriod,0,MODE_SMA,PRICE_CLOSE);
- iMaHandle1=iMA(NULL,0,MaPeriod+50,0,MODE_SMA,PRICE_CLOSE);
- //---
- return(0);
- }
- //+------------------------------------------------------------------+
- //| 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[])
- {
- //--- return value of prev_calculated for next call
- //--- checking for bars count
- if(rates_total<MaPeriod)
- return(0);
- //--- detect start position
- int start;
- //if(prev_calculated>1) start=prev_calculated-1;
- //else start=1;
- if(prev_calculated<0)return(-1);else start=rates_total-prev_calculated+1;
- int to_copy;
- if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
- else
- {
- to_copy=rates_total-prev_calculated;
- if(prev_calculated>0) to_copy++;
- }
- if(CopyBuffer(iMaHandle,0,0,to_copy,bMaBuffer)<=0)
- {
- Print("Getting fast SMA is failed! Error",GetLastError());
- return(0);
- }
- if(CopyBuffer(iMaHandle1,0,0,to_copy,bMaBuffer1)<=0)
- {
- Print("Getting fast SMA1 is failed! Error",GetLastError());
- return(0);
- }
- //--- main cycle
- for(int i=start;i<rates_total;i++)
- {
- if(bMaBuffer[i]>close[i-1])
- bColorBuffer[i]=1.0;
- else bColorBuffer[i]=0.0;
- if(bMaBuffer1[i]>close[i-1])
- bColorBuffer1[i]=1.0;
- else bColorBuffer1[i]=0.0;
- }
- return(rates_total);
- }
- //+------------------------------------------------------------------+
文章栽自:www.520fx.com
主站蜘蛛池模板:
狠狠综合久久av一区二区|
1000部拍拍拍18勿入免费视频下载|
欧美视频免费在线播放|
国产无遮挡又黄又爽在线视频|
丰满岳乱妇在线观看中字无码|
毛片免费视频在线观看|
国产中文字幕在线观看视频|
57pao成人国产永久免费视频|
明星xxxxhdvideos|
免费看黄的网站在线看|
黄网站在线播放|
天天干天天干天天干天天干|
久久九九久精品国产|
欧美成人免费全部观看天天性色
|
囯产精品一品二区三区|
网址在线观看你懂的|
好男人www社区|
久久国产精品免费网站|
欧美日本韩国一区二区|
再深点灬舒服灬太大|
高清国产激情视频在线观看|
国产老师的丝袜在线看|
一本大道AV伊人久久综合|
日本高清天码一区在线播放|
亚洲国产精品成人久久|
男女免费观看在线爽爽爽视频|
国产va免费精品观看精品|
黑人巨大精品欧美一区二区免费
|
丰满岳乱妇一区二区三区|
极品少妇伦理一区二区|
亚洲欧美另类国产|
用被子自w到高c方法|
啊好深好硬快点用力视频|
超污视频在线观看|
国产成人精品免费视频大全|
3d无尽3d无尽动漫同人|
在线观看视频一区二区|
xl上司带翻译无马赛樱花|
成人自拍视频网|
久久久噜噜噜久久中文福利|
曰批免费视频播放免费|