- //+------------------------------------------------------------------+
- //| 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[0];
- 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[pos+1] + haBufClose[pos+1]) / 2;
- haClose = (Open[pos] + High[pos] + Low[pos] + Close[pos]) / 4;
- haHigh = MathMax(High[pos], MathMax(haOpen, haClose));
- haLow = MathMin(Low[pos], MathMin(haOpen, haClose));
- haBufOpen[pos] = haOpen;
- haBufClose[pos] = haClose;
- haBufHigh[pos] = haHigh;
- haBufLow[pos] = haLow;
- Range = 0;
- AvgRange = 0;
- int i;
- for ( i = pos; i <= pos + 9; i++ ) {
- AvgRange = AvgRange + MathAbs(High[i] - Low[i]);
- }
- 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[i]);
- }
-
- ma = iMA(NULL, MAFilterTF, MAFilterPeriod, 0, MAFilterMethod, PRICE_CLOSE, ma_offset);
-
- signalUp[i] = 0;
- signalDn[i] = 0;
-
- if ( (stochastic1now > stochastic2now) && (stochastic1previous < stochastic2previous) && (stochastic1after > stochastic2after) ) {
- if ( !MAFilterEnable || Low[i] > ma ) {
- if ( haOpen < haClose ) {
- signalUp[i] = Low[i] - Range*1.5;
- if ( alertOn && NewBar() ) {
- alert("Swing HA/Stoch signal: Buy " + Symbol() + " [url=home.php?mod=space&uid=73392]@[/url] " + DoubleToStr(Bid, Digits));
- }
- }
- }
- }
-
- if ( (stochastic1now < stochastic2now) && (stochastic1previous > stochastic2previous) && (stochastic1after < stochastic2after) ) {
- if ( !MAFilterEnable || High[i] < ma ) {
- if ( haOpen > haClose ) {
- signalDn[i] = High[i] + Range*1.5;
- if ( alertOn && NewBar() ) {
- alert("Swing HA/Stoch signal: Sell " + Symbol() + " @ " + DoubleToStr(Bid, Digits));
- }
- }
- }
- }
-
- pos--;
- }
- }
|