admin 发表于 2018-3-2 11:49:34

HeikenAshi_with_Stoch_Crossing



//+------------------------------------------------------------------+
//|                      HeikenAshi_with_Stoch_Crossing_Complete.mq4 |
//|                                                         Feanor |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Feanor"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Red
#property indicator_color5 Red
#property indicator_color6 Red

extern string note1 = "Stochastic settings";
extern string note2 = "default = Stoch(30,10,10)";
extern int       KPeriod1   =8;
extern int       DPeriod1   =3;
extern int       Slowing1   =3;
extern string note3 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int       MAMethod1    =   0;
extern string note4 = "0=high/low, 1=close/close";
extern int       PriceField1=   0;
extern string note4a = "--------------------------------------------";
extern string note4b = "MA Filter";
extern bool   MAFilterEnable    = true;
extern string note4c = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int    MAFilterMethod    =0;
extern int    MAFilterPeriod    = 50;
extern string note4d = "0=current tf, 5 = M5, 15 = M15, 60=H1, 240=H4, 1440=D1, 10080=W1";
extern int    MAFilterTF      =0;
extern string note11 = "--------------------------------------------";
extern string note12 = "turn on Alert = true; turn off = false";
extern bool AlertOn = true;
extern string note13 = "--------------------------------------------";
extern string note14 = "send Email Alert = true; turn off = false";
extern bool SendAnEmail=false;

//--- buffers
double signalUp[];
double signalDn[];
double haBufOpen[];
double haBufClose[];
double haBufLow[];
double haBufHigh[];

int ExtCountedBars = 0;

void init()
{
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 217);
   SetIndexBuffer(0, signalUp);
   SetIndexEmptyValue(0, 0.0);
   SetIndexLabel(0, "Buy Signal");
   
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 218);
   SetIndexBuffer(1, signalDn);
   SetIndexEmptyValue(1, 0.0);
   SetIndexLabel(1, "Sell Signal");
   
   SetIndexStyle(2, DRAW_NONE);
   SetIndexBuffer(2, haBufOpen);
   SetIndexLabel(2, "HA Open");
   SetIndexStyle(3, DRAW_NONE);
   SetIndexBuffer(3, haBufClose);
   SetIndexLabel(3, "HA Close");
   SetIndexStyle(4, DRAW_NONE);
   SetIndexBuffer(4, haBufLow);
   SetIndexLabel(4, "HA Low");
   SetIndexStyle(5, DRAW_NONE);
   SetIndexBuffer(5, haBufHigh);
   SetIndexLabel(5, "HA High");
}

bool NewBar()
{
   static datetime lastbar;
   datetime curbar = Time;
   if ( lastbar == curbar)
      return(false);

   lastbar = curbar;
   return(true);
}   

void start()
{
   if ( Bars <= 10 )
       return;
      
   double haOpen, haHigh, haLow, haClose;
   double stochastic1now, stochastic2now, stochastic1previous, stochastic2previous, stochastic1after, stochastic2after;
   double Range, AvgRange;
   double ma;

   ExtCountedBars = IndicatorCounted();

   if ( ExtCountedBars < 0 )
      return;
      
   if ( ExtCountedBars > 0 )
      ExtCountedBars--;
   int pos = Bars - ExtCountedBars - 1;
      
   while ( pos >= 0 ) {
      haOpen = (haBufOpen + haBufClose) / 2;
      haClose = (Open + High + Low + Close) / 4;      
      haHigh = MathMax(High, MathMax(haOpen, haClose));
      haLow = MathMin(Low, MathMin(haOpen, haClose));

      haBufOpen = haOpen;
      haBufClose = haClose;
      haBufHigh = haHigh;
      haBufLow = haLow;

      Range = 0;
      AvgRange = 0;
      int i;
      for ( i = pos; i <= pos + 9; i++ ) {
         AvgRange = AvgRange + MathAbs(High - Low);
      }
      Range = AvgRange / 10;
      
      i = pos;
      stochastic1now = iStochastic(NULL, 0, KPeriod1, DPeriod1, Slowing1, MAMethod1, PriceField1, 0, i);
      stochastic1previous = iStochastic(NULL, 0, KPeriod1, DPeriod1, Slowing1, MAMethod1, PriceField1, 0, i + 1);
      stochastic1after = iStochastic(NULL, 0, KPeriod1, DPeriod1, Slowing1, MAMethod1, PriceField1, 0, i - 1);
      stochastic2now = iStochastic(NULL, 0, KPeriod1, DPeriod1, Slowing1, MAMethod1, PriceField1, 1, i);
      stochastic2previous = iStochastic(NULL, 0, KPeriod1, DPeriod1, Slowing1, MAMethod1, PriceField1, 1, i + 1);
      stochastic2after = iStochastic(NULL, 0, KPeriod1, DPeriod1, Slowing1, MAMethod1, PriceField1, 1, i - 1);
      
      int ma_offset = i;
      if ( MAFilterTF != 0 ) {
         ma_offset = iBarShift(NULL, MAFilterTF, Time);
      }
      
      ma = iMA(NULL, MAFilterTF, MAFilterPeriod, 0, MAFilterMethod, PRICE_CLOSE, ma_offset);
      
      signalUp = 0;
      signalDn = 0;
      
      if ( (stochastic1now > stochastic2now) && (stochastic1previous < stochastic2previous) && (stochastic1after > stochastic2after) ) {
         if ( !MAFilterEnable || Low > ma ) {
            if ( haOpen < haClose ) {
               signalUp = Low - Range*1.5;
               if ( AlertOn && NewBar() ) {
                  Alert("Swing HA/Stoch signal: Buy " + Symbol() + " @ " + DoubleToStr(Bid, Digits));
               }   
                 }
         }
      }
         
      if ( (stochastic1now < stochastic2now) && (stochastic1previous > stochastic2previous) && (stochastic1after < stochastic2after) ) {
         if ( !MAFilterEnable || High < ma ) {
            if ( haOpen > haClose ) {
               signalDn = High + Range*1.5;
               if ( AlertOn && NewBar() ) {
                  Alert("Swing HA/Stoch signal: Sell " + Symbol() + " @ " + DoubleToStr(Bid, Digits));
               }
            }
         }
      }
            
           pos--;
   }
}


随遇而安 发表于 2018-9-14 10:25:20

好帖,来顶下

flying5960 发表于 2020-7-7 10:06:03

谢谢楼主分享

等你两世 发表于 2020-7-9 19:48:31

谢谢楼主分享

Iris-chen 发表于 2020-7-10 10:52:25

帮你顶下哈!!

鄙视诋毁 发表于 2020-7-13 17:57:14

谢谢楼主分享

ttvggeyhygj 发表于 2020-7-22 21:10:21

学习了,不错

何止一句在乎 发表于 2020-7-23 20:21:35

谢谢楼主分享

白雪王子 发表于 2020-7-27 15:50:07

学习了,不错

skehi8923 发表于 2020-8-17 14:45:07

谢谢楼主分享
页: [1] 2
查看完整版本: HeikenAshi_with_Stoch_Crossing