人人爽天天爽夜夜爽qc-人人爽天天爽夜夜爽曰-人人天天爱天天做天天摸-人人天天夜夜-色网站在线-色网站在线看

您現(xiàn)在的位置:程序化交易>> 外匯現(xiàn)貨>> MT5>> MT5知識(shí)>>正文內(nèi)容

MQL5變色線畫(huà)法(比MQL4更簡(jiǎn)單) [MT4]

  • MQL5里有一種特殊指標(biāo)數(shù)組“顏色數(shù)組”,他是和畫(huà)線的指標(biāo)數(shù)組配合使用的。通過(guò)對(duì)他的簡(jiǎn)單賦值可以使畫(huà)出的線變色。
    首先要在指標(biāo)頭部定義里指定一條線對(duì)應(yīng)的數(shù)組是要使用變色畫(huà)線方式,指定方法是:
    #property indicator_typeX DRAW_COLOR_LINE
    這里X代表畫(huà)線的數(shù)組序號(hào)
    DRAW_COLOR_LINE代表畫(huà)線,此外還可以有如下畫(huà)線方式:
    復(fù)制代碼
    1. DRAW_COLOR_LINE
    2. Colorful Line彩色線
    3. DRAW_COLOR_SECTION
    4. Multicolored section彩色塊
    5. DRAW_COLOR_HISTOGRAM
    6. Multicolored histogram from the zero line彩色柱狀圖
    7. DRAW_COLOR_HISTOGRAM2
    8. Multicolored histogram of the two indicator buffers彩色柱狀圖2
    9. DRAW_COLOR_ARROW
    10. Drawing colored arrows彩色箭頭
    11. DRAW_COLOR_ZIGZAG
    12. Colorful ZigZag彩色ZigZag
    13. DRAW_COLOR_BARS
    14. Multi-colored bars彩色竹線圖
    15. DRAW_COLOR_CANDLES
    16. Multi-colored candles彩色蠟燭圖

    然后緊跟一個(gè)顏色的定義語(yǔ)句:
    #property indicator_colorX Red,Green
    兩個(gè)顏色之間用逗號(hào)分隔
    ============================================
    針對(duì)上面程序頭部的定義,之后要開(kāi)始全局?jǐn)?shù)組的定義。
    這里要注意實(shí)現(xiàn)變色需要針對(duì)一條線使用兩個(gè)數(shù)組,
    例如:
    double bMaBuffer[],bColorBuffer[];
    然后進(jìn)入OnInit事件進(jìn)行兩個(gè)數(shù)組的分別設(shè)定:
    SetIndexBuffer(0,bMaBuffer,INDICATOR_DATA);//INDICATOR_DATA表示是用于畫(huà)線的數(shù)組
    SetIndexBuffer(1,bColorBuffer,INDICATOR_COLOR_INDEX);//INDICATOR_COLOR_INDEX表示是用于變色的顏色數(shù)組
    注意:
    如果這里要畫(huà)多條彩色線,則畫(huà)線數(shù)組和顏色數(shù)組的序號(hào)要緊鄰。
    ============================================
    下一步就是在OnCaculate事件里進(jìn)行畫(huà)線數(shù)組的計(jì)算,同時(shí)根據(jù)自定義的條件對(duì)顏色數(shù)組進(jìn)行賦值。
    賦值規(guī)則是:
    當(dāng)對(duì)應(yīng)K線序號(hào)的顏色數(shù)組被賦值1.0時(shí),對(duì)應(yīng)畫(huà)線數(shù)組的顏色為 第一個(gè)顏色
    當(dāng)對(duì)應(yīng)K線序號(hào)的顏色數(shù)組被賦值0.0時(shí),對(duì)應(yīng)畫(huà)線數(shù)組的顏色為 第二個(gè)顏色
    完。
    程序舉例源碼如下:【畫(huà)出兩個(gè)變色線】
    復(fù)制代碼
    1. //+------------------------------------------------------------------+
    2. //| Test.mq5 |
    3. //| Copyright 2009, MetaQuotes Software Corp. |
    4. //| http://bbs.520fx.com |
    5. //+------------------------------------------------------------------+
    6. #property copyright "2009, 520FX"
    7. #property link "http://www.mql5.com"
    8. #property version "1.00"
    9. #property indicator_chart_window
    10. #property indicator_buffers 4
    11. #property indicator_plots 2
    12. #property indicator_color1 Red,Green
    13. #property indicator_type1 DRAW_COLOR_LINE
    14. #property indicator_style1 STYLE_SOLID
    15. #property indicator_width1 2
    16. #property indicator_color2 Yellow,Blue
    17. #property indicator_type2 DRAW_COLOR_LINE
    18. #property indicator_style2 STYLE_SOLID
    19. #property indicator_width2 2
    20. input int MaPeriod=13;
    21. double bMaBuffer[],bMaBuffer1[],bColorBuffer[],bColorBuffer1[];
    22. int iMaHandle,iMaHandle1;
    23. //+------------------------------------------------------------------+
    24. //| Custom indicator initialization function |
    25. //+------------------------------------------------------------------+
    26. int OnInit()
    27. {
    28. //--- indicator buffers mapping
    29. SetIndexBuffer(0,bMaBuffer,INDICATOR_DATA);
    30. SetIndexBuffer(1,bColorBuffer,INDICATOR_COLOR_INDEX);
    31. SetIndexBuffer(2,bMaBuffer1,INDICATOR_DATA);
    32. SetIndexBuffer(3,bColorBuffer1,INDICATOR_COLOR_INDEX);
    33. IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
    34. iMaHandle=iMA(NULL,0,MaPeriod,0,MODE_SMA,PRICE_CLOSE);
    35. iMaHandle1=iMA(NULL,0,MaPeriod+50,0,MODE_SMA,PRICE_CLOSE);
    36. //---
    37. return(0);
    38. }
    39. //+------------------------------------------------------------------+
    40. //| Custom indicator iteration function |
    41. //+------------------------------------------------------------------+
    42. int OnCalculate(const int rates_total,
    43. const int prev_calculated,
    44. const datetime& time[],
    45. const double& open[],
    46. const double& high[],
    47. const double& low[],
    48. const double& close[],
    49. const long& tick_volume[],
    50. const long& volume[],
    51. const int& spread[])
    52. {
    53. //--- return value of prev_calculated for next call
    54. //--- checking for bars count
    55. if(rates_total<MaPeriod)
    56. return(0);
    57. //--- detect start position
    58. int start;
    59. //if(prev_calculated>1) start=prev_calculated-1;
    60. //else start=1;
    61. if(prev_calculated<0)return(-1);else start=rates_total-prev_calculated+1;
    62. int to_copy;
    63. if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
    64. else
    65. {
    66. to_copy=rates_total-prev_calculated;
    67. if(prev_calculated>0) to_copy++;
    68. }
    69. if(CopyBuffer(iMaHandle,0,0,to_copy,bMaBuffer)<=0)
    70. {
    71. Print("Getting fast SMA is failed! Error",GetLastError());
    72. return(0);
    73. }
    74. if(CopyBuffer(iMaHandle1,0,0,to_copy,bMaBuffer1)<=0)
    75. {
    76. Print("Getting fast SMA1 is failed! Error",GetLastError());
    77. return(0);
    78. }
    79. //--- main cycle
    80. for(int i=start;i<rates_total;i++)
    81. {
    82. if(bMaBuffer[i]>close[i-1])
    83. bColorBuffer[i]=1.0;
    84. else bColorBuffer[i]=0.0;
    85. if(bMaBuffer1[i]>close[i-1])
    86. bColorBuffer1[i]=1.0;
    87. else bColorBuffer1[i]=0.0;
    88. }
    89. return(rates_total);
    90. }
    91. //+------------------------------------------------------------------+

    文章栽自:www.520fx.com

【字體: 】【打印文章】【查看評(píng)論

相關(guān)文章

    沒(méi)有相關(guān)內(nèi)容
主站蜘蛛池模板: 国产网站91| 曰韩三级| 九九九九九九伊人 | 色综合色狠狠天天久久婷婷基地 | 欧美三级欧美一级 | 在线欧美日韩 | 日韩中文字幕视频在线观看 | 欧美日韩国产另类一区二区三区 | 国产成人综合亚洲一区 | 男人把女人下面桶爽的视频 | 一个人在线观看的免费视频www | 台湾乱xxxxxxxxx | 天天爽夜夜爽每晚高澡 | 狠狠婷| 最近的2019中文字幕4 | 二区中文字幕 | 日韩一区二区三区视频 | 中文字幕亚洲欧美日韩高清 | 动漫成年美女黄漫网站在线看 | 美女视频黄的全免费网站 | 欧美日日夜夜 | 午夜无码国产理论在线 | 毛片xxxx| 国产欧美国日产网站 | 成人欲涩漫h漫免费动漫 | 成人a视频高清在线观看 | 国产精品一区在线免费观看 | 国产高清网站 | 黄色短视频免费看 | 欧美一区二区不卡视频 | 亚洲人成网站在线观看青青 | 精品国产欧美 | 欧美一区二区三区不卡免费 | 日韩久久一级毛片 | 日韩欧美亚洲中字幕在线播放 | 久久这里有精品视频任我鲁 | 最近2019中文字幕 | 久久国产欧美日韩精品免费 | 久久久99视频 | 777kkk亚洲综合欧美色老头 | 欧美视频一区二区专区 |