键盘英文切换成中文:看MT4代码,学编程 一

来源:百度文库 编辑:中财网 时间:2024/04/29 02:37:35
1。指标代码解释


  • //例1



  1. //+------------------------------------------------------------------+
  2. //双些线后是单行注释,用于注解,自用说明。/*和*/包起来实现多行注释,记录自己的说明介绍,编程使用记录等
  3. //MQL4语言基本服从C语言的规则-----------注意目前MetaEditor处理不好多字节代码,所以不要在代码中使用中文和中文空格-------------+
  4. //每个指标文件只是至少包括三个部分(1)property 和参数,数组声明,(2)初始化函数nit(), (3)主函数start()
  5. //property 是各种说明信息
  6. //最重要必须的是这三种,(1)说明指标将画在价格窗口还是独立的窗口
  7. //(2)有多少个(1~7)储存指标数据的数组,(3)说明对应将画指标的绘画颜色,编号1~7
  8. #property indicator_chart_window
  9. #property indicator_buffers 1
  10. #property indicator_color1 Red

  11. //---- 可设置的参数,可根据需要,由使用者设置
  12. extern int MA_Period=13;
  13. extern int MA_Shift=0;
  14. extern int MA_Method=2;
  15. extern int MA_Price = 6;
  16. /* MA_Method =
  17. MODE_SMA 0 Simple moving average,
  18. MODE_EMA 1 Exponential moving average,
  19. MODE_SMMA 2 Smoothed moving average,
  20. MODE_LWMA 3 Linear weighted moving average.
  21. */
  22. /* MA_Price =
  23. PRICE_CLOSE 0 Close price.
  24. PRICE_OPEN 1 Open price.
  25. PRICE_HIGH 2 High price.
  26. PRICE_LOW 3 Low price.
  27. PRICE_MEDIAN 4 Median price, (high+low)/2.
  28. PRICE_TYPICAL 5 Typical price, (high+low+close)/3.
  29. PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4.

  30. */

  31. //数组,储存指标数据
  32. double Buffer0[];
  33. //----
  34. //+------------------------------------------------------------------+
  35. //| 初始化准备函数,装入时调用一次               |
  36. //+------------------------------------------------------------------+
  37. int init()
  38. {
  39. //-设置编号为0的线的线形等参数, 0~6,对应indicator_color1~7
  40.   SetIndexStyle(0,DRAW_LINE);
  41. //---- 设置编号为0的线 与数组的对应关系, 0~6
  42.   SetIndexBuffer(0,Buffer0);
  43.   return(0);
  44. }
  45. //+------------------------------------------------------------------+
  46. //|                                             |
  47. int start()   //指标计算主函数,每次计算调用
  48. {
  49. ma();
  50.   return(0);
  51. }
  52. //+------------------------------------------------------------------+
  53. //|自定义函数,这里只是直接使用库函数实现MA, 若你自己计算,可设计任何指标                           |
  54. //+------------------------------------------------------------------+
  55. void ma()
  56. {
  57.   int pos=Bars;   //Bars = Number of bars in the current chart.当前窗口中的蜡烛数
  58.   while(pos>=0)
  59.   {
  60.     Buffer0[pos]=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,MA_Price,pos);
  61.     pos--;
  62.   }
  63. }
  64. //
  65. ///----------------------------------------------------------------------

  66.   
复制代码

  • 例2
  1.   
  2. //+------------------------------------------------------------------+
  3. //双些线后是单行注释,用于注解,自用说明。/*和*/包起来实现多行注释,记录自己的说明介绍,编程使用记录等
  4. //MQL4语言基本服从C语言的规则-----------注意目前MetaEditor处理不好多字节代码,所以不要在代码中使用中文和中文空格-------------+
  5. //每个指标文件只是至少包括三个部分(1)property 和参数,数组声明,(2)初始化函数nit(), (3)主函数start()
  6. //property 是各种说明信息
  7. //最重要必须的是这三种,(1)说明指标将画在价格窗口还是独立的窗口
  8. //(2)有多少个(1~7)储存指标数据的数组,(3)说明对应将画指标的绘画颜色,编号1~7
  9. #property indicator_separate_window
  10. #property indicator_buffers 7
  11. #property indicator_color1 Red
  12. #property indicator_color2 Yellow
  13. #property indicator_color3 Blue
  14. #property indicator_color4 Green
  15. #property indicator_color5 Gray
  16. #property indicator_color6 SkyBlue
  17. #property indicator_color7 Tan
  18. //---- 可设置的参数,可根据需要,由使用者设置
  19. extern int MA_Period=13;
  20. extern int MA_Shift=0;
  21. extern int MA_Method=2;
  22. extern int MA_Price = 6;

  23. //数组,储存指标数据
  24. double Buffer0[];
  25. double Buffer1[];
  26. double Buffer2[];
  27. double Buffer3[];
  28. double Buffer4[];
  29. double Buffer5[];
  30. double Buffer6[];
  31. //----
  32. //+------------------------------------------------------------------+
  33. //| 初始化准备函数,装入时调用一次               |
  34. //+------------------------------------------------------------------+
  35. int init()
  36. {
  37. //-设置编号为0的线的线形等参数, 0~6,对应indicator_color1~7
  38.   SetIndexStyle(0,DRAW_LINE);
  39.   SetIndexStyle(1,DRAW_LINE);
  40.   SetIndexStyle(3,DRAW_LINE);
  41.   SetIndexStyle(4,DRAW_LINE);
  42.   SetIndexStyle(5,DRAW_LINE);
  43.   SetIndexStyle(6,DRAW_LINE);
  44. //---- 设置编号为0的线 与数组的对应关系, 0~6
  45.   SetIndexBuffer(0,Buffer0);
  46.   SetIndexBuffer(1,Buffer1);
  47.   SetIndexBuffer(2,Buffer2);
  48.   SetIndexBuffer(3,Buffer3);
  49.   SetIndexBuffer(4,Buffer4);
  50.   SetIndexBuffer(5,Buffer5);
  51.   SetIndexBuffer(6,Buffer6);
  52.   return(0);
  53. }
  54. //+------------------------------------------------------------------+
  55. //|                                             |
  56. int start()   //指标计算主函数,每次计算调用
  57. {
  58. ma();
  59. ma1();
  60. return(0);
  61. }
  62. //+------------------------------------------------------------------+
  63. //|自定义函数,这里只是直接使用库函数实现MA, 若你自己计算,可设计任何指标                           |
  64. //+------------------------------------------------------------------+
  65. void ma()
  66. {
  67.   int pos=Bars;   //Bars = Number of bars in the current chart.当前窗口中的蜡烛数
  68.   while(pos>=0)
  69.   {
  70.     Buffer0[pos]=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,MA_Price,pos);
  71.     Buffer1[pos]=iMA(NULL,0,MA_Period*2,MA_Shift,MA_Method,MA_Price,pos);
  72.     Buffer2[pos]=iMA(NULL,0,MA_Period*3,MA_Shift,MA_Method,MA_Price,pos);
  73.     pos--;
  74.   }
  75. }
  76. void ma1()
  77. {
  78.   int pos=Bars;   //Bars = Number of bars in the current chart.当前窗口中的蜡烛数
  79.   while(pos>=0)
  80.   {
  81.     Buffer3[pos]=iMA(NULL,0,MA_Period*4,MA_Shift,MA_Method,MA_Price,pos);
  82.     Buffer4[pos]=iMA(NULL,0,MA_Period*5,MA_Shift,MA_Method,MA_Price,pos);
  83.     Buffer5[pos]=iMA(NULL,0,MA_Period*6,MA_Shift,MA_Method,MA_Price,pos);
  84.     Buffer6[pos]=iMA(NULL,0,MA_Period*7,MA_Shift,MA_Method,MA_Price,pos);
  85.     pos--;
  86.   }
  87. }