admin 发表于 2018-1-19 14:59:03

PSAR_2B



/*------------------------------------------------------------------+
|                                              Nik_PSAR_2B.mq4.mq4 |
|                                                 Copyright ?2010 |
|                                             basisforex@gmail.com |
+------------------------------------------------------------------*/
#property copyright "Copyright ?2010, basisforex@gmail.com"
#property link      "basisforex@gmail.com"
//-----
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Yellow
#property indicator_color2 RoyalBlue
#property indicator_color3 Blue
#property indicator_color4 Black
#property indicator_color5 Lime
#property indicator_color6 Red
//-----
extern bool       AlertsEnabled= true;
extern bool       TF4            = false;
extern bool       TF3            = false;
extern bool       TF2            = true;
//-----
extern double   Step         = 0.02;
extern double   Maximum      = 0.2;
//-----
double s1[];
double s2[];
double s3[];
double s4[];
double bullish[];
double bearish[];
double sarUp[];
double sarDn[];
double alertBar;
bool sar4, sar3, sar2;
//+------------------------------------------------------------------+
int init()
{
   SetIndexBuffer(0, s1);
   SetIndexBuffer(1, s2);
   SetIndexBuffer(2, s3);
   SetIndexBuffer(3, s4);
   //-----
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 159);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 159);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, 159);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, 159);
   //------
   SetIndexStyle(4, DRAW_ARROW,OBJPROP_WIDTH,2);// UP___UP___UP
   SetIndexArrow(4, 233);
   SetIndexBuffer(4, bullish);
   //-----
   SetIndexStyle(5, DRAW_ARROW,OBJPROP_WIDTH,2);// DOWN____DOWN
   SetIndexArrow(5, 234);      
   SetIndexBuffer(5, bearish);
   //-----
   return(0);
}
//+------------------------------------------------------------------+
void GetBool()
{
   if(TF4 == true)
    {
      sar4 = true; sar3 = true; sar2 = true;
    }
   else if(TF3 == true && TF4 == false)
    {
      sar4 = false; sar3 = true; sar2 = true;
    }
   else if(TF2 == true && TF4 == false && TF3 == false)
    {
      sar4 = false; sar3 = false; sar2 = true;
    }
   else if(TF2 == false && TF4 == false && TF3 == false)
    {
      sar4 = false; sar3 = false; sar2 = false;
    }
}
//+------------------------------------------------------------------+
string GetNextTF(int curTF)
{
   switch(curTF)
    {
      case 1:
      return("5=15#30");
      break;
      case 5:
      return("15=30#60");
      break;
      case 15:
      return("30=60#240");
      break;
      case 30:
      return("60=240#1440");
      break;
      case 60:
      return("240=1440#10080");
      break;
      case 240:
      return("1440=10080#43200");
      break;      
    }
}
//+------------------------------------------------------------------+
void AlertDn(double sar)
{
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars < 0) counted_bars = 0;
   if(counted_bars > 0) counted_bars--;
   limit = Bars - counted_bars;
   //----
   for(int i = 0; i < limit ;i++)
    {
      if(sar >= iHigh(Symbol(),0,i))
       {
         if(AlertsEnabled == true && sarUp == 0 && Bars > alertBar)
          {
            Alert("PSAR Going Down on ", Symbol(), " - ", Period(), " min");
            alertBar = Bars;
          }
         sarUp = sar;
         sarDn = 0;
       }
    }
}
//+------------------------------------------------------------------+
void AlertUp(double sar)
{
   int limit;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) counted_bars = 0;
   if(counted_bars > 0) counted_bars--;
   limit = Bars - counted_bars;
   //----
   for(int i = 0; i<limit ;i++)
    {
      if(sar <= iLow(Symbol(), 0, i))
       {
         if(AlertsEnabled == true && sarDn == 0 && Bars > alertBar)
          {
            Alert("PSAR Going Up on ",Symbol(), " - ", Period(), " min");
            alertBar = Bars;
          }
         sarUp = 0;
         sarDn = sar;
       }
    }
}
//+------------------------------------------------------------------+
int start()
{
   int limit;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
   limit = Bars - counted_bars;
   //-----
   string T = GetNextTF(Period());
   int tf1 = StrToDouble(StringSubstr(T, 0, StringFind(T, "=", 0)));
   int tf2 = StrToDouble(StringSubstr(T, StringFind(T, "=", 0) + 1, StringFind(T, "#", 0)));
   int tf3 = StrToDouble(StringSubstr(T, StringFind(T, "#", 0) + 1, StringLen(T)));
   //-----
   GetBool();
   //-----
   for(int i = limit - 1; i >= 0; i--)
    {
         //===============================================         __________________________________________________   sar1&sar2&sar3& sar4
         if(sar2 == true && sar3 == true && sar4 == true)
          {
            Comment(Period(), " White", "\n", tf1, " Yellow", "\n", tf2, " Blue", "\n", tf3, " Black");
            s1= iSAR(NULL, Period(), Step, Maximum, i);
            s2= iSAR(NULL, tf1, Step, Maximum, i / (tf1 / Period()));
            s3= iSAR(NULL, tf2, Step, Maximum, i / (tf2 / Period()));
            s4= iSAR(NULL, tf3, Step, Maximum, i / (tf3 / Period()));
            //============================================================
            if((s1 > High && s2 > High && s3 > High && s4 < Low && s4 > High) ||
               (s1 > High && s2 > High && s3 < Low && s3 > High && s4 > High) ||
               (s1 > High && s2 < Low && s2 > High && s3 > High && s4 > High) ||
               (s1 < Low && s1 > High && s2 > High && s3 > High && s4 > High))
             {
                bearish = s1 + 5 * Point;//       SELL__SELL__SELL
                AlertDn(s1);
             }
            //-----
            if((s1 < Low && s2 < Low && s3 < Low && s4 > High && s4 < Low) ||
               (s1 < Low && s2 < Low && s3 > High && s3 < Low && s4 < Low) ||
               (s1 < Low && s2 > High && s2 < Low && s3 < Low && s4 < Low) ||
               (s1 > High && s1 < Low && s2 < Low && s3 < Low && s4 < Low))
             {
               bullish =s1 - 5 * Point;//      BUY___BUY___BUY
               AlertUp(s1);
             }
          }
          //===============================================         __________________________________________________   sar1&sar2&sar3
         else if(sar2 == true && sar3 == true && sar4 == false)
          {   
            Comment(Period(), " White", "\n", tf1, " Yellow", "\n", tf2, " Blue");
            s1= iSAR(NULL, Period(), Step, Maximum, i);
            s2= iSAR(NULL, tf1, Step, Maximum, i / (tf1 / Period()));
            s3= iSAR(NULL, tf2, Step, Maximum, i / (tf2 / Period()));
            //============================================================
            if((s1 > High && s2 > High && s3 < Low && s3 > High) ||
               (s1 > High && s2 < Low && s2 > High && s3 > High) ||
               (s1 < Low && s1 > High && s2 > High && s3 > High))
             {
               bearish = s1 + 5 * Point;//       SELL__SELL__SELL
               AlertDn(s1);
             }
            //-----
            if((s1 < Low && s2 < Low && s3 > High && s3 < Low) ||
               (s1 < Low && s2 > High && s2 < Low && s3 < Low) ||
               (s1 > High && s1 < Low && s2 < Low && s3 < Low))
             {
               bullish =s1 - 5 * Point;//      BUY___BUY___BUY
               AlertUp(s1);
             }
          }
         //===============================================          __________________________________________________   sar1&sar2
         else if(sar2 == true && sar3 == false && sar4 == false)
          {   
            Comment(Period(), " White", "\n", tf1, " Yellow");
            s1= iSAR(NULL, Period(), Step, Maximum, i);
            s2= iSAR(NULL, tf1, Step, Maximum, i / (tf1 / Period()));
            //============================================================
            if((s1 > High && s2 < Low && s2 > High) ||
               (s1 < Low && s1 > High && s2 > High))
             {
               bearish = s1 + 5 * Point;//       SELL__SELL__SELL
               AlertDn(s1);
             }
            //-----
            if((s1 < Low && s2 > High && s2 < Low) ||
               (s1 > High && s1 < Low && s2 < Low))
             {
               bullish =s1 - 5 * Point;//      BUY___BUY___BUY
               AlertUp(s1);
             }
          }
         //===============================================          __________________________________________________   sar1
         else if(sar2 == false && sar3 == false && sar4 == false)
          {
            Comment(Period(), " White");
            s1= iSAR(NULL, Period(), Step, Maximum, i);
            //============================================================
            if(s1 < Low && s1 > High)
             {
               bearish = s1 + 5 * Point;//       SELL__SELL__SELL
               AlertDn(s1);
             }
            //-----
            if(s1 > High && s1 < Low)
             {
               bullish =s1 - 5 * Point;//      BUY___BUY___BUY
               AlertUp(s1);
             }
          }      
    }
   //==============================================================================================================================================
   return(0);
}


蒲公英的约定 发表于 2020-7-29 10:06:19

帮你顶下哈!!

乱枪打鸟 发表于 2020-8-23 16:33:01

学习了,不错
页: [1]
查看完整版本: PSAR_2B