2评论

3收藏

PSAR_2B

avatar admin | 1489 人阅读 | 2 人评论 | 2018-01-19

GBPUSDH1.png

  1. /*------------------------------------------------------------------+
  2. |                                              Nik_PSAR_2B.mq4.mq4 |
  3. |                                                 Copyright ?2010 |
  4. |                                             basisforex@gmail.com |
  5. +------------------------------------------------------------------*/
  6. #property copyright "Copyright ?2010, basisforex@gmail.com"
  7. #property link      "basisforex@gmail.com"
  8. //-----
  9. #property indicator_chart_window
  10. #property indicator_buffers 6
  11. #property indicator_color1 Yellow
  12. #property indicator_color2 RoyalBlue
  13. #property indicator_color3 Blue
  14. #property indicator_color4 Black
  15. #property indicator_color5 Lime
  16. #property indicator_color6 Red
  17. //-----
  18. extern bool       AlertsEnabled  = true;
  19. extern bool       TF4            = false;
  20. extern bool       TF3            = false;
  21. extern bool       TF2            = true;
  22. //-----
  23. extern double     Step           = 0.02;
  24. extern double     Maximum        = 0.2;
  25. //-----
  26. double s1[];
  27. double s2[];
  28. double s3[];
  29. double s4[];
  30. double bullish[];
  31. double bearish[];
  32. double sarUp[];
  33. double sarDn[];
  34. double alertBar;
  35. bool sar4, sar3, sar2;
  36. //+------------------------------------------------------------------+
  37. int init()
  38. {
  39.    SetIndexBuffer(0, s1);
  40.    SetIndexBuffer(1, s2);
  41.    SetIndexBuffer(2, s3);
  42.    SetIndexBuffer(3, s4);
  43.    //-----
  44.    SetIndexStyle(0, DRAW_ARROW);
  45.    SetIndexArrow(0, 159);
  46.    SetIndexStyle(1, DRAW_ARROW);
  47.    SetIndexArrow(1, 159);
  48.    SetIndexStyle(2, DRAW_ARROW);
  49.    SetIndexArrow(2, 159);
  50.    SetIndexStyle(3, DRAW_ARROW);
  51.    SetIndexArrow(3, 159);
  52.    //------
  53.    SetIndexStyle(4, DRAW_ARROW,OBJPROP_WIDTH,2);// UP___UP___UP
  54.    SetIndexArrow(4, 233);
  55.    SetIndexBuffer(4, bullish);
  56.    //-----
  57.    SetIndexStyle(5, DRAW_ARROW,OBJPROP_WIDTH,2);// DOWN____DOWN
  58.    SetIndexArrow(5, 234);      
  59.    SetIndexBuffer(5, bearish);
  60.    //-----
  61.    return(0);
  62. }
  63. //+------------------------------------------------------------------+
  64. void GetBool()
  65. {
  66.    if(TF4 == true)
  67.     {
  68.       sar4 = true; sar3 = true; sar2 = true;
  69.     }
  70.    else if(TF3 == true && TF4 == false)
  71.     {
  72.       sar4 = false; sar3 = true; sar2 = true;
  73.     }
  74.    else if(TF2 == true && TF4 == false && TF3 == false)
  75.     {
  76.       sar4 = false; sar3 = false; sar2 = true;
  77.     }
  78.    else if(TF2 == false && TF4 == false && TF3 == false)
  79.     {
  80.       sar4 = false; sar3 = false; sar2 = false;
  81.     }
  82. }
  83. //+------------------------------------------------------------------+
  84. string GetNextTF(int curTF)
  85. {
  86.    switch(curTF)
  87.     {
  88.       case 1:
  89.         return("5=15#30");
  90.         break;
  91.       case 5:
  92.         return("15=30#60");
  93.         break;
  94.       case 15:
  95.         return("30=60#240");
  96.         break;
  97.       case 30:
  98.         return("60=240#1440");
  99.         break;
  100.       case 60:
  101.         return("240=1440#10080");
  102.         break;
  103.       case 240:
  104.         return("1440=10080#43200");
  105.         break;        
  106.     }
  107. }
  108. //+------------------------------------------------------------------+
  109. void AlertDn(double sar)
  110. {
  111.    int limit;
  112.    int counted_bars=IndicatorCounted();
  113.    if(counted_bars < 0) counted_bars = 0;
  114.    if(counted_bars > 0) counted_bars--;
  115.    limit = Bars - counted_bars;
  116.    //----
  117.    for(int i = 0; i < limit ;i++)
  118.     {
  119.       if(sar >= iHigh(Symbol(),0,i))
  120.        {
  121.          if(AlertsEnabled == true && sarUp[i] == 0 && Bars > alertBar)
  122.           {
  123.             Alert("PSAR Going Down on ", Symbol(), " - ", Period(), " min");
  124.             alertBar = Bars;
  125.           }
  126.          sarUp[i] = sar;  
  127.          sarDn[i] = 0;
  128.        }
  129.     }
  130. }
  131. //+------------------------------------------------------------------+
  132. void AlertUp(double sar)
  133. {
  134.    int limit;
  135.    int counted_bars = IndicatorCounted();
  136.    if(counted_bars < 0) counted_bars = 0;
  137.    if(counted_bars > 0) counted_bars--;
  138.    limit = Bars - counted_bars;
  139.    //----
  140.    for(int i = 0; i<limit ;i++)
  141.     {
  142.       if(sar <= iLow(Symbol(), 0, i))
  143.        {
  144.          if(AlertsEnabled == true && sarDn[i] == 0 && Bars > alertBar)
  145.           {
  146.             Alert("PSAR Going Up on ",Symbol(), " - ", Period(), " min");
  147.             alertBar = Bars;
  148.           }
  149.          sarUp[i] = 0;
  150.          sarDn[i] = sar;
  151.        }
  152.     }
  153. }
  154. //+------------------------------------------------------------------+
  155. int start()
  156. {
  157.    int limit;
  158.    int counted_bars = IndicatorCounted();
  159.    if(counted_bars < 0) return(-1);
  160.    if(counted_bars > 0) counted_bars--;
  161.    limit = Bars - counted_bars;
  162.    //-----
  163.    string T = GetNextTF(Period());
  164.    int tf1 = StrToDouble(StringSubstr(T, 0, StringFind(T, "=", 0)));
  165.    int tf2 = StrToDouble(StringSubstr(T, StringFind(T, "=", 0) + 1, StringFind(T, "#", 0)));
  166.    int tf3 = StrToDouble(StringSubstr(T, StringFind(T, "#", 0) + 1, StringLen(T)));
  167.    //-----
  168.    GetBool();
  169.    //-----
  170.    for(int i = limit - 1; i >= 0; i--)
  171.     {
  172.          //===============================================         __________________________________________________   sar1  &  sar2  &  sar3  & sar4
  173.          if(sar2 == true && sar3 == true && sar4 == true)
  174.           {
  175.             Comment(Period(), " White", "\n", tf1, " Yellow", "\n", tf2, " Blue", "\n", tf3, " Black");
  176.             s1[i]  = iSAR(NULL, Period(), Step, Maximum, i);
  177.             s2[i]  = iSAR(NULL, tf1, Step, Maximum, i / (tf1 / Period()));
  178.             s3[i]  = iSAR(NULL, tf2, Step, Maximum, i / (tf2 / Period()));
  179.             s4[i]  = iSAR(NULL, tf3, Step, Maximum, i / (tf3 / Period()));
  180.             //============================================================
  181.             if((s1[i] > High[i] && s2[i] > High[i] && s3[i] > High[i] && s4[i + 1] < Low[i + 1] && s4[i] > High[i]) ||
  182.                (s1[i] > High[i] && s2[i] > High[i] && s3[i + 1] < Low[i + 1] && s3[i] > High[i] && s4[i] > High[i]) ||
  183.                (s1[i] > High[i] && s2[i + 1] < Low[i + 1] && s2[i] > High[i] && s3[i] > High[i] && s4[i] > High[i]) ||
  184.                (s1[i + 1] < Low[i + 1] && s1[i] > High[i] && s2[i] > High[i] && s3[i] > High[i] && s4[i] > High[i]))
  185.              {
  186.                 bearish[i] = s1[i] + 5 * Point;//       SELL__SELL__SELL
  187.                 AlertDn(s1[i]);
  188.              }
  189.             //-----
  190.             if((s1[i] < Low[i] && s2[i] < Low[i] && s3[i] < Low[i] && s4[i + 1] > High[i + 1] && s4[i] < Low[i]) ||
  191.                (s1[i] < Low[i] && s2[i] < Low[i] && s3[i + 1] > High[i + 1] && s3[i] < Low[i] && s4[i] < Low[i]) ||
  192.                (s1[i] < Low[i] && s2[i + 1] > High[i + 1] && s2[i] < Low[i] && s3[i] < Low[i] && s4[i] < Low[i]) ||
  193.                (s1[i + 1] > High[i + 1] && s1[i] < Low[i] && s2[i] < Low[i] && s3[i] < Low[i] && s4[i] < Low[i]))
  194.              {
  195.                bullish[i] =  s1[i] - 5 * Point;//      BUY___BUY___BUY
  196.                AlertUp(s1[i]);
  197.              }
  198.           }
  199.           //===============================================         __________________________________________________   sar1  &  sar2  &  sar3
  200.          else if(sar2 == true && sar3 == true && sar4 == false)
  201.           {     
  202.             Comment(Period(), " White", "\n", tf1, " Yellow  ", "\n", tf2, " Blue");
  203.             s1[i]  = iSAR(NULL, Period(), Step, Maximum, i);
  204.             s2[i]  = iSAR(NULL, tf1, Step, Maximum, i / (tf1 / Period()));
  205.             s3[i]  = iSAR(NULL, tf2, Step, Maximum, i / (tf2 / Period()));
  206.             //============================================================
  207.             if((s1[i] > High[i] && s2[i] > High[i] && s3[i + 1] < Low[i + 1] && s3[i] > High[i]) ||
  208.                (s1[i] > High[i] && s2[i + 1] < Low[i + 1] && s2[i] > High[i] && s3[i] > High[i]) ||
  209.                (s1[i + 1] < Low[i + 1] && s1[i] > High[i] && s2[i] > High[i] && s3[i] > High[i]))
  210.              {
  211.                bearish[i] = s1[i] + 5 * Point;//       SELL__SELL__SELL
  212.                AlertDn(s1[i]);
  213.              }
  214.             //-----
  215.             if((s1[i] < Low[i] && s2[i] < Low[i] && s3[i + 1] > High[i + 1] && s3[i] < Low[i]) ||
  216.                (s1[i] < Low[i] && s2[i + 1] > High[i + 1] && s2[i] < Low[i] && s3[i] < Low[i]) ||
  217.                (s1[i + 1] > High[i + 1] && s1[i] < Low[i] && s2[i] < Low[i] && s3[i] < Low[i]))
  218.              {
  219.                bullish[i] =  s1[i] - 5 * Point;//      BUY___BUY___BUY
  220.                AlertUp(s1[i]);
  221.              }
  222.           }
  223.          //===============================================          __________________________________________________   sar1  &  sar2
  224.          else if(sar2 == true && sar3 == false && sar4 == false)
  225.           {     
  226.             Comment(Period(), " White", "\n", tf1, " Yellow");
  227.             s1[i]  = iSAR(NULL, Period(), Step, Maximum, i);
  228.             s2[i]  = iSAR(NULL, tf1, Step, Maximum, i / (tf1 / Period()));
  229.             //============================================================
  230.             if((s1[i] > High[i] && s2[i + 1] < Low[i + 1] && s2[i] > High[i]) ||
  231.                (s1[i + 1] < Low[i + 1] && s1[i] > High[i] && s2[i] > High[i]))
  232.              {
  233.                bearish[i] = s1[i] + 5 * Point;//       SELL__SELL__SELL
  234.                AlertDn(s1[i]);
  235.              }
  236.             //-----
  237.             if((s1[i] < Low[i] && s2[i + 1] > High[i + 1] && s2[i] < Low[i]) ||
  238.                (s1[i + 1] > High[i + 1] && s1[i] < Low[i] && s2[i] < Low[i]))
  239.              {
  240.                bullish[i] =  s1[i] - 5 * Point;//      BUY___BUY___BUY
  241.                AlertUp(s1[i]);
  242.              }
  243.           }
  244.          //===============================================          __________________________________________________   sar1
  245.          else if(sar2 == false && sar3 == false && sar4 == false)
  246.           {
  247.             Comment(Period(), " White");
  248.             s1[i]  = iSAR(NULL, Period(), Step, Maximum, i);
  249.             //============================================================
  250.             if(s1[i + 1] < Low[i + 1] && s1[i] > High[i])
  251.              {
  252.                bearish[i] = s1[i] + 5 * Point;//       SELL__SELL__SELL
  253.                AlertDn(s1[i]);
  254.              }
  255.             //-----
  256.             if(s1[i + 1] > High[i + 1] && s1[i] < Low[i])
  257.              {
  258.                bullish[i] =  s1[i] - 5 * Point;//      BUY___BUY___BUY
  259.                AlertUp(s1[i]);
  260.              }
  261.           }        
  262.     }  
  263.    //==============================================================================================================================================
  264.    return(0);
  265. }

复制代码
PSAR_2B.mq4
""
还没有人打赏,支持一下

评论|共 2 个

蒲公英的约定

发表于 2020-7-29 10:06:19 | 显示全部楼层

帮你顶下哈!!

乱枪打鸟

发表于 2020-8-23 16:33:01 | 显示全部楼层

学习了,不错

您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则