JMA_Angle

This tool is designed to help traders visualize the strength and direction of a market trend by calculating the "angle" or slope of a specific moving average. Instead of just showing you where the price is moving, it focuses on how aggressively that movement is happening.

How It Works

The logic behind this script operates in three main stages:

1. Data Collection The tool looks at a specialized moving average (the JMA) and compares two different points in time simultaneously. It identifies a "Start" point and an "End" point based on the settings provided. By looking at these two specific coordinates, the script can determine how much the average has shifted over that specific distance.

2. Angle Calculation The script takes the difference between those two points and calculates an "angle." To ensure this angle is visible and meaningful on your trading screen, it applies a multiplier (a factor) that adjusts based on the currency pair you are trading—for example, it automatically recognizes the different decimal scales of JPY pairs versus standard currencies.

3. Visual Filtering Rather than showing every tiny wiggle in the market, the script uses a "Threshold" system to filter out noise:

  • Bullish Momentum: If the upward angle is steeper than your chosen threshold, it highlights the movement as a positive trend (UpBuffer).
  • Bearish Momentum: If the downward angle is steeper than your chosen threshold, it highlights it as a negative trend (DownBuffer).
  • Neutral Zone: If the angle is shallow (smaller than the threshold), it treats the movement as neutral or sideways.

Summary for Traders

In simple terms, this indicator acts as a momentum filter. It ignores small price fluctuations and only alerts you when the moving average starts to tilt significantly in one direction. This helps you identify clear, strong trends while potentially filtering out "choppy" market behavior where the price is moving but not with any real force.

Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
JMA_Angle
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                    JMA_Angle.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  LimeGreen
#property  indicator_color2  Yellow
#property  indicator_color3 FireBrick
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2

//---- indicator parameters
extern int JMA_Period=34;

extern double AngleTreshold=15;
extern int StartMAShift=4;
extern int EndMAShift=0;

//---- indicator buffers
double UpBuffer[];
double DownBuffer[];
double ZeroBuffer[];

   double mFactor;
   int ShiftDif;
   string Sym;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);

//---- 3 indicator buffers mapping
   if(!SetIndexBuffer(0,UpBuffer) &&
      !SetIndexBuffer(1,DownBuffer) &&
      !SetIndexBuffer(2,ZeroBuffer))
      Print("cannot set indicator buffers!");
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexDrawBegin(0,JMA_Period);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("JMA_Angle("+JMA_Period+","+AngleTreshold+","+StartMAShift+","+EndMAShift+")");
   SetIndexLabel(0,"JMA Angle");
   if(EndMAShift >= StartMAShift)
   {
      Print("Error: EndMAShift >= StartMAShift");
      StartMAShift = 6;
      EndMAShift = 0;      
   }  
   mFactor = 100000.0;
   Sym = StringSubstr(Symbol(),3,3);
   if (Sym == "JPY") mFactor = 1000.0;
   ShiftDif = StartMAShift-EndMAShift;
   mFactor /= ShiftDif;
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   double ma1, ma2;
   double fEndMA, fStartMA;
   double fAngle;
   int limit,i;
   double angle;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) 
      return(-1);
   if(counted_bars<1)
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- main loop
   for(i=0; i<limit; i++)
   {
      fEndMA=iCustom(NULL, 0, "JMA",JMA_Period,0,i+EndMAShift);
      fStartMA=iCustom(NULL, 0, "JMA",JMA_Period,0,i+StartMAShift);
      // 10000.0 : Multiply by 10000 so that the fAngle is not too small
      // for the indicator Window.
      fAngle = mFactor * (fEndMA - fStartMA)/2.0;
//Print (mFactor, fEndMA, fStartMA, fAngle);
      DownBuffer[i] = 0.0;
      UpBuffer[i] = 0.0;
      ZeroBuffer[i] = 0.0;
      
      if(fAngle > AngleTreshold)
      {
         UpBuffer[i] = fAngle;
      }
      else if (fAngle < -AngleTreshold)
      {
         DownBuffer[i] = fAngle;
      }
      else ZeroBuffer[i] = fAngle;
   }

//---- done
   return(0);
  }

//+------------------------------------------------------------------+

Comments