MBKAsctrend3times

Download script
Author: MBKAsctrend3times matt kennel
MBKAsctrend3times

This tool is designed to help traders identify significant market trend reversals by combining multiple layers of price data into a single, cohesive signal. Instead of relying on just one indicator, it looks at the "big picture" while simultaneously monitoring short-term momentum.

Here is a breakdown of how the logic works:

1. Multi-Layered Momentum Analysis

The core of this script is based on a modified version of the Williams %R (WPR) oscillator. Rather than looking at just one timeframe, the script calculates three different WPR values simultaneously using different lengths. Think of these as three different "lenses":

  • A short-term lens to catch quick moves.
  • A medium-term lens to identify the current flow.
  • A long-term lens to identify the overall market direction.

2. Weighted Averaging

Not all data is treated equally. The script applies a specific "weight" to each of the three lenses. By combining these three values into one weighted average, the tool filters out "market noise"—those small, erratic price movements that often trigger false signals in simpler indicators. This ensures that a signal is only generated when multiple time horizons agree with each other.

3. Trend Confirmation Logic

For a signal to appear on your chart, the script looks for a specific "confluence" (agreement) between the weighted average and the long-term trend:

  • To identify an Uptrend: The combined weighted value must cross above a specific high threshold, and the long-term trend must be confirming that movement.
  • To identify a Downtrend: The combined weighted value must drop below a specific low threshold, while the long-term trend confirms the downward pressure.

4. Dynamic Range Calculations

The script calculates the "Average Range" of price volatility over a set number of bars. When it detects a valid trend reversal based on the logic above, it places an arrow on your chart. The distance of that arrow from the price is automatically adjusted based on the current market volatility—meaning if the market is swinging wildly, the arrows stay out of the way; if the market is calm, they sit closer to the price.

5. Summary of Visual Output

  • Blue Arrows: Indicate a confirmed shift into an upward trend (Buy signal).
  • Red Arrows: Indicate a confirmed shift into a downward trend (Sell signal).
  • Filtering: By requiring both the weighted average and the long-term trend to align, the script aims to prevent "whipsaws," where a trader might enter a trade based on a small move that immediately reverses.
Indicators Used
Larry William percent range indicator
Miscellaneous
Implements a curve of type %1
18 Views
0 Downloads
0 Favorites
MBKAsctrend3times
//+------------------------------------------------------------------+
//| MBKAsctrend3times.mq4                                            |
//+------------------------------------------------------------------+
#property copyright "MBKAsctrend3times matt kennel"
#property link      "http://www.metatrader.org"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
// Modified by MBK:  now have three different timescales (bar lengths)
// to combine for final WPR indicator, with further long-term trend indicator.
// try on H1 chart with these parameters. 
extern int RISK=3;
//extern int CountBars=2000;
extern int NumberofAlerts=2;
extern int WPRLength1=9,WPRLength2=33, WPRLength3=77;
extern int LToffset=-5;
extern double w1=1.0, w2=3.0, w3=1.0; // relative weights
int counter=0;
//---- buffers
double val1[];
double val2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexBuffer(0,val1);
   SetIndexBuffer(1,val2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| SilverTrend_Signal                                               |
//+------------------------------------------------------------------+
  int start() 
  {
   //if (CountBars>=Bars) CountBars=Bars;
   //SetIndexDrawBegin(0,Bars-CountBars+SSP);
   //SetIndexDrawBegin(1,Bars-CountBars+SSP);
   int i1,i2,K;
   double Range,AvgRange,smin,smax,SsMax,SsMin,price;
   double wprvalue;
   static bool uptrend,old;
   bool flag1, flag2;
   int i,shift,counted_bars=IndicatorCounted();
   //if(Bars<=SSP+1) return(0);
//---- initial zero
   //if(counted_bars<SSP+1)
   // {
   //      for(i=1;i<=SSP;i++) val2[CountBars-i]=0.0;
   //  }
   ////----
   K=33-RISK;
   // wprlength = 3+RISK*2; 
   uptrend=false;
   old=false;
   double sumweights=w1+w2+w3;
   w1/=sumweights;
   w2/=sumweights;
   w3/=sumweights;
   int SSP=10;
     for(shift=Bars-SSP; shift>=0; shift--) 
     {
      Range=0;
      AvgRange=0;
      for(i1=shift; i1<=shift+SSP; i1++)
        {AvgRange=AvgRange+MathAbs(High[i1]-Low[i1]);
        }
      Range=AvgRange/(SSP+1);
      double wprval1=(100-MathAbs(iWPR(Symbol(),Period(),WPRLength1,shift)));
      double wprval2=(100-MathAbs(iWPR(Symbol(),Period(),WPRLength2,shift)));
      double wprval3=(100-MathAbs(iWPR(Symbol(),Period(),WPRLength3,shift)));
      wprvalue=w1*wprval1 + w2*wprval2 + w3*wprval3;
      //  MathPow(wprval1*wprval2*wprval3,1.0/3.0); 
      double wprlong=wprval3;
        if ((wprvalue < 33-RISK) && (wprlong < 50-LToffset)) 
        {
         uptrend=false;
        }
        if ((wprvalue > 67+RISK) && (wprlong>=50+LToffset)) 
        {
         uptrend=true;
        }
        if (uptrend!=old && uptrend==true) 
        {
         val1[shift]=Low[shift]-Range*0.8; // lower range
         counter=0;
           if (shift==0 && counter<=NumberofAlerts) 
           {
            // Alert("MBKAsctrend ",Period()," ",Symbol()," BUY");
            counter=counter+1;
           }
        }
        if (uptrend!=old && uptrend==false) 
        {
         counter=0;
         val2[shift]=High[shift]+Range*0.8;
           if (shift==0 && counter<=NumberofAlerts) 
           {
            // Alert("Silver Trend ",Period()," ",Symbol()," SELL");
            counter=counter+1;
           }
        }
      Comment(shift);
      old=uptrend;
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments