设为首页 收藏本站 切换语言

MT4多周期RSI指标(标准编写)

| 发表于 2022-11-25 17:31:28 | 显示全部楼层 |复制链接
  1. //+------------------------------------------------------------------+
  2. //|                                            eXclusive MTF RSI.mq4 |
  3. //|                               Copyright ?2013, mt4exclusive.com |
  4. //|                                      http://www.mt4exclusive.com |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright ?2013, mt4exclusive.com"
  7. #property link      "http://www.mt4exclusive.com"
  8. #property indicator_color1 Red//设置各个指标线的“颜色”
  9. #property indicator_color2 Lime
  10. #property indicator_color3 Orange
  11. #property indicator_color4 Blue
  12. #property indicator_color5 White
  13. #property indicator_color6 Green
  14. #property indicator_color7 Yellow
  15. #property indicator_color8 Moccasin
  16. #property indicator_separate_window//单独窗口中显示指标
  17. #property indicator_minimum 0
  18. #property indicator_maximum 100
  19. #property indicator_buffers 8//指标的“缓冲区数量”
  20. #property indicator_level1 70//指标的“水平位”
  21. #property indicator_level2 30
  22. #property indicator_level3 50
  23. //以下为指标的“输入参数”
  24. extern int RSIperiod=14;
  25. extern int RSIprice =0;
  26. extern string RSI_Price_note_1="CLOSE= 0, OPEN=1, HIGH=2, LOW=3";
  27. extern string RESI_Price_note2="MEDIAN=4, TYPICAL=5, WEIGHTED=6";
  28. extern bool ShowRSI_M1 = true;
  29. extern bool ShowRSI_M5 = true;
  30. extern bool ShowRSI_M15 = true;
  31. extern bool ShowRSI_M30 = true;
  32. extern bool ShowRSI_M60 = true;
  33. extern bool ShowRSI_M240= true;
  34. extern bool ShowRSI_M1440=true;
  35. extern bool ShowRSI_M10080=true;
  36. extern color M1_color=Red;
  37. extern color M5_color=Lime;
  38. extern color M15_color=Orange;
  39. extern color M30_color=Blue;
  40. extern color M60_color=White;
  41. extern color M240_color=Green;
  42. extern color M1440_color=Yellow;
  43. extern color M10080_color=Moccasin;
  44. double M1Buffer[];//设置双精度数组变量
  45. double M5Buffer[];
  46. double M15Buffer[];
  47. double M30Buffer[];
  48. double M60Buffer[];
  49. double M240Buffer[];
  50. double M1440Buffer[];
  51. double M10080Buffer[];
  52. int TF1=1;//设置整形变量
  53. int TF5=5;
  54. int TF15=15;
  55. int TF30=30;
  56. int TF60=60;
  57. int TF240=240;
  58. int TF1440=1440;
  59. int TF10080=10080;
  60. //+------------------------------------------------------------------+
  61. //| Custom indicator initialization function                         |
  62. //+------------------------------------------------------------------+
  63. int init()
  64.   {
  65. //---- indicators
  66. //============================================================================================
  67. //IndexBuffer为指标缓冲区(index英文有指标的意思,但也有索引的意思,即第几个指标缓冲区),指标缓冲区的个数由 IndicatorBuffers() 函数设定并且不能超过8个。
  68. //SetIndexBuffer:即将第几个自定义的指标缓冲区绑定到指定数组array[]。
  69.    SetIndexBuffer(0,M1Buffer);//将第1个指标缓冲区绑定到数组M1Buffer
  70.    SetIndexLabel(0,"M1 RSI");//设置指标标签为"M1 RSI",当光标移动到该指标线上时,显示该名称,以及对应的数值
  71.    //SetIndexStyle() – 设置指定的指标线设置新类型、样式、宽度和颜色。
  72.    //void SetIndexStyle(int index, int type, void style, void width, void clr)
  73. //index - 指标线。必须在0至7之间。
  74. //type - 形状样式,可以是 划线形状样式列表 中任意一个。
  75. //style - 线型。可以应用一个像素的粗线,可以是 划线形状样式列表 其中一个。EMPTY值表示线型不变。
  76. //width - 线宽。有效值是1,2,3,4,5。EMPTY值表示线宽不变。
  77. //clr - 线的颜色。省略本参数表示颜色将保持不变
  78.    SetIndexStyle(0,DRAW_LINE,0,1,M1_color);//第一个指标线画成红色的线型,宽度为1
  79. //============================================================================================
  80.    SetIndexBuffer(1,M5Buffer);
  81.    SetIndexLabel(1,"M5 RSI");
  82.    SetIndexStyle(1,DRAW_LINE,0,1,M5_color);
  83. //============================================================================================
  84.    SetIndexBuffer(2,M15Buffer);
  85.    SetIndexLabel(2,"M15 RSI");
  86.    SetIndexStyle(2,DRAW_LINE,0,1,M15_color);
  87. //============================================================================================
  88.    SetIndexBuffer(3,M30Buffer);
  89.    SetIndexLabel(3,"M30 RSI");
  90.    SetIndexStyle(3,DRAW_LINE,0,1,M30_color);
  91. //============================================================================================
  92.    SetIndexBuffer(4,M60Buffer);
  93.    SetIndexLabel(4,"H1 RSI");
  94.    SetIndexStyle(4,DRAW_LINE,0,1,M60_color);
  95. //============================================================================================
  96.    SetIndexBuffer(5,M240Buffer);
  97.    SetIndexLabel(5,"H4 RSI");
  98.    SetIndexStyle(5,DRAW_LINE,0,1,M240_color);
  99. //============================================================================================
  100.    SetIndexBuffer(6,M1440Buffer);
  101.    SetIndexLabel(6,"D1 RSI");
  102.    SetIndexStyle(6,DRAW_LINE,0,1,M1440_color);
  103. //============================================================================================
  104.    SetIndexBuffer(7,M10080Buffer);
  105.    SetIndexLabel(7,"W1 RSI");
  106.    SetIndexStyle(7,DRAW_LINE,0,1,M10080_color);
  107. //============================================================================================
  108.    IndicatorShortName("eXclusive MTF_RSI("+RSIperiod+")");//指标窗口左上角显示的“指标名称”
  109.    return(0);
  110.   }
  111. //+------------------------------------------------------------------+
  112. //| Custom indicator deinitialization function                       |
  113. //+------------------------------------------------------------------+
  114. int deinit()//清空内存
  115.   {
  116. //----
  117. //The function removes the object with the specified name at the specified chart. There are two variants of the function:
  118. //该函数在指定的图表中移除具有指定名称的对象。
  119.    ObjectDelete("M1RSI");//
  120.    ObjectDelete("M5RSI");
  121.    ObjectDelete("M15RSI");
  122.    ObjectDelete("M30RSI");
  123.    ObjectDelete("H1RSI");
  124.    ObjectDelete("H4RSI");
  125.    ObjectDelete("D1RSI");
  126.    ObjectDelete("W1RSI");
  127.    ObjectDelete("M1ValueRSI");
  128.    ObjectDelete("M5ValueRSI");
  129.    ObjectDelete("M15ValueRSI");
  130.    ObjectDelete("M30ValueRSI");
  131.    ObjectDelete("H1ValueRSI");
  132.    ObjectDelete("H4ValueRSI");
  133.    ObjectDelete("D1ValueRSI");
  134.    ObjectDelete("W1ValueRSI");
  135. //----
  136.    return(0);
  137.   }
  138. //============================================================================================
  139. int start()
  140.   {
  141.    if(ShowRSI_M1 && Period()<=1) {start1();CreateLabel("M1_RSI",10,30,2,M1_color,"M1",10);CreateLabel("M1Value_RSI",10,10,2,M1_color,DoubleToStr(NormalizeDouble(iRSI(NULL,TF1,RSIperiod,0,0),1),1),10);}
  142.    if(ShowRSI_M5 && Period()<=5) {start2();CreateLabel("M5_RSI",50,30,2,M5_color,"M5",10);CreateLabel("M5Value_RSI",50,10,2,M5_color,DoubleToStr(NormalizeDouble(iRSI(NULL,TF5,RSIperiod,0,0),1),1),10);}
  143.    if(ShowRSI_M15 && Period()<=15) {start3();CreateLabel("M15_RSI",90,30,2,M15_color,"M15",10);CreateLabel("M15Value_RSI",90,10,2,M15_color,DoubleToStr(NormalizeDouble(iRSI(NULL,TF15,RSIperiod,0,0),1),1),10);}
  144.    if(ShowRSI_M30 && Period()<=30) {start4();CreateLabel("M30_RSI",130,30,2,M30_color,"M30",10);CreateLabel("M30Value_RSI",130,10,2,M30_color,DoubleToStr(NormalizeDouble(iRSI(NULL,TF30,RSIperiod,0,0),1),1),10);}
  145.    if(ShowRSI_M60 && Period()<=60) {start5();CreateLabel("H1_RSI",170,30,2,M60_color,"H1",10);CreateLabel("H1Value_RSI",170,10,2,M60_color,DoubleToStr(NormalizeDouble(iRSI(NULL,TF60,RSIperiod,0,0),1),1),10);}
  146.    if(ShowRSI_M240  &&  Period()<=240) {start6();CreateLabel("H4_RSI",210,30,2,M240_color,"H4",10);CreateLabel("H4Value_RSI",210,10,2,M240_color,DoubleToStr(NormalizeDouble(iRSI(NULL,TF240,RSIperiod,0,0),1),1),10);}
  147.    if(ShowRSI_M1440 && Period()<=1440) {start7();CreateLabel("D1_RSI",250,30,2,M1440_color,"D1",10);CreateLabel("D1Value_RSI",250,10,2,M1440_color,DoubleToStr(NormalizeDouble(iRSI(NULL,TF1440,RSIperiod,0,0),1),1),10);}
  148.    if(ShowRSI_M10080 && Period()<=10080) {start8();CreateLabel("W1_RSI",290,30,2,M10080_color,"W1",10);CreateLabel("W1Value_RSI",290,10,2,M10080_color,DoubleToStr(NormalizeDouble(iRSI(NULL,TF10080,RSIperiod,0,0),1),1),10);}
  149.    return(0);
  150.   }
  151. //============================================================================================
  152. //============================================================================================
  153. int start1()
  154.   {
  155.    datetime TimeArray1[];
  156.    int    i,limit,y=0,counted_bars=IndicatorCounted();
  157.    ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),1);
  158.    limit=Bars-counted_bars;
  159.    for(i=0,y=0;i<limit;i++)
  160.      {
  161.       if (y<ArraySize(TimeArray1)) {if(Time<TimeArray1[y]) y++;}
  162.       M1Buffer=iRSI(NULL,1,RSIperiod,RSIprice,y);
  163.      }
  164.    return(0);  
  165.   }
  166. //============================================================================================
  167. int start2()
  168.   {
  169.    datetime TimeArray2[];
  170.    int    i,limit,y=0,counted_bars=IndicatorCounted();
  171.    ArrayCopySeries(TimeArray2,MODE_TIME,Symbol(),TF5);
  172.    limit=Bars-counted_bars;
  173.    for(i=0,y=0;i<limit;i++)
  174.      {
  175.       if (y<ArraySize(TimeArray2)) {if(Time<TimeArray2[y]) y++;}
  176.       M5Buffer=iRSI(NULL,TF5,RSIperiod,RSIprice,y);
  177.      }
  178.    return(0);  
  179.   }
  180. //============================================================================================
  181. int start3()
  182.   {
  183.    datetime TimeArray3[];
  184.    int    i,limit,y=0,counted_bars=IndicatorCounted();
  185.    ArrayCopySeries(TimeArray3,MODE_TIME,Symbol(),TF15);
  186.    limit=Bars-counted_bars;
  187.    for(i=0,y=0;i<limit;i++)
  188.      {
  189.       if (y<ArraySize(TimeArray3)) {if(Time<TimeArray3[y]) y++;}
  190.       M15Buffer=iRSI(NULL,TF15,RSIperiod,RSIprice,y);
  191.      }
  192.    return(0);  
  193.   }
  194. //============================================================================================
  195. int start4()
  196.   {
  197.    datetime TimeArray4[];
  198.    int    i,limit,y=0,counted_bars=IndicatorCounted();
  199.    ArrayCopySeries(TimeArray4,MODE_TIME,Symbol(),TF30);
  200.    limit=Bars-counted_bars;
  201.    for(i=0,y=0;i<limit;i++)
  202.      {
  203.       if (y<ArraySize(TimeArray4)) {if(Time<TimeArray4[y]) y++;}
  204.       M30Buffer=iRSI(NULL,TF30,RSIperiod,RSIprice,y);
  205.      }
  206.    return(0);  
  207.   }
  208. //============================================================================================
  209. int start5()
  210.   {
  211.    datetime TimeArray5[];
  212.    int    i,limit,y=0,counted_bars=IndicatorCounted();
  213.    ArrayCopySeries(TimeArray5,MODE_TIME,Symbol(),TF60);
  214.    limit=Bars-counted_bars;
  215.    for(i=0,y=0;i<limit;i++)
  216.      {
  217.       if (y<ArraySize(TimeArray5)) {if(Time<TimeArray5[y]) y++;}
  218.       M60Buffer=iRSI(NULL,TF60,RSIperiod,RSIprice,y);
  219.      }
  220.    return(0);  
  221.   }
  222. //============================================================================================
  223. int start6()
  224.   {
  225.    datetime TimeArray6[];
  226.    int    i,limit,y=0,counted_bars=IndicatorCounted();
  227.    ArrayCopySeries(TimeArray6,MODE_TIME,Symbol(),TF240);
  228.    limit=Bars-counted_bars;
  229.    for(i=0,y=0;i<limit;i++)
  230.      {
  231.       if (y<ArraySize(TimeArray6)) {if(Time<TimeArray6[y]) y++;}
  232.       M240Buffer=iRSI(NULL,TF240,RSIperiod,RSIprice,y);
  233.      }
  234.    return(0);  
  235.   }
  236. //============================================================================================
  237. int start7()
  238.   {
  239.    datetime TimeArray7[];
  240.    int    i,limit,y=0,counted_bars=IndicatorCounted();
  241.    ArrayCopySeries(TimeArray7,MODE_TIME,Symbol(),TF1440);
  242.    limit=Bars-counted_bars;
  243.    for(i=0,y=0;i<limit;i++)
  244.      {
  245.       if (y<ArraySize(TimeArray7)) {if(Time<TimeArray7[y]) y++;}
  246.       M1440Buffer=iRSI(NULL,TF1440,RSIperiod,RSIprice,y);
  247.      }
  248.    return(0);  
  249.   }
  250. //============================================================================================
  251. int start8()
  252.   {
  253.    datetime TimeArray8[];
  254.    int    i,limit,y=0,counted_bars=IndicatorCounted();
  255.    ArrayCopySeries(TimeArray8,MODE_TIME,Symbol(),TF10080);
  256.    limit=Bars-counted_bars;
  257.    for(i=0,y=0;i<limit;i++)
  258.      {
  259.       if (y<ArraySize(TimeArray8)) {if(Time<TimeArray8[y]) y++;}
  260.       M10080Buffer=iRSI(NULL,TF10080,RSIperiod,RSIprice,y);
  261.      }
  262.    return(0);  
  263.   }
  264. //============================================================================================
  265. //============================================================================================
  266. void CreateLabel(string name,int x,int y,int corner,int z,string text,int size,
  267.                  string font="Arial")
  268.   {
  269.    ObjectCreate(name,OBJ_LABEL,WindowFind("eXclusive MTF_RSI("+RSIperiod+")"),0,0);
  270.    ObjectSet(name,OBJPROP_CORNER,corner);
  271.    ObjectSet(name,OBJPROP_COLOR,z);
  272.    ObjectSet(name,OBJPROP_XDISTANCE,x);
  273.    ObjectSet(name,OBJPROP_YDISTANCE,y);
  274.    ObjectSetText(name,text,size,font,z);
  275.   }
  276. //============================================================================================
复制代码
如果有帮助,就支持一下我呗
举报

评论 使用道具

精彩评论6

rhinegold
D
| 发表于 2022-11-25 19:07:39 | 显示全部楼层
举报

点赞 评论 使用道具

daerwushen
DD
| 发表于 2022-11-25 19:48:32 | 显示全部楼层
多周期RSI
举报

点赞 评论 使用道具

13637743644
D
| 发表于 2022-11-25 20:21:12 | 显示全部楼层
感谢分享,非常实用
举报

点赞 评论 使用道具

mathewbe
CC
| 发表于 2022-11-25 22:24:42 | 显示全部楼层
Good source code
举报

点赞 评论 使用道具

qwe11
CCC
| 发表于 2022-11-26 13:57:00 | 显示全部楼层
很适用的样子
举报

点赞 评论 使用道具

dongxu64
DDD
| 发表于 2022-11-28 11:13:12 | 显示全部楼层
谢谢分享,楼主辛苦
举报

点赞 评论 使用道具

发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册

简体中文
繁體中文
English(英语)
日本語(日语)
Deutsch(德语)
Русский язык(俄语)
بالعربية(阿拉伯语)
Türkçe(土耳其语)
Português(葡萄牙语)
ภาษาไทย(泰国语)
한어(朝鲜语/韩语)
Français(法语)