JJN-Promise

Download script
Author: Copyright � 2010, JJ Newark
JJN-Promise

Overview

The JJN-Promise is a technical analysis tool designed for the MetaTrader 4 platform. It serves as a momentum and trend oscillator, providing traders with visual cues to identify potential shifts in market direction and price volatility. By analyzing moving averages across multiple time offsets, it creates a unique signal that helps smooth out "market noise" to reveal underlying trends.

How the Logic Works

The indicator operates through a multi-step mathematical process to generate its signals:

1. Multi-Layered Average Analysis Instead of relying on a single price point, the script calculates several Exponential Moving Averages (EMA) simultaneously. It looks at various "shifts" (time offsets) in the market data. By calculating the difference between these shifted averages and a primary base average, the script identifies how much the price is deviating from its recent historical path at different intervals.

2. Momentum Calculation The core logic aggregates all these individual differences into a single "Main Value." This value represents the cumulative momentum of the market across various timeframes. It essentially tells you if the current price movement is accelerating, decelerating, or remaining stable relative to its recent history.

3. The Signal and Tolerance To make the data actionable for a trader, the script creates a "Signal Value." This is derived from the Main Value but shifted forward by a specific tolerance level (user-adjustable). By comparing the current Main Value against this signaled value, the indicator highlights when the market is entering a state of transition.

4. Deviation Tracking (The "Diff" Value) The script also calculates a "Difference" value, which measures the distance between the main trend and its signal. This is crucial for identifying:

  • Strength: How far the price is stretching away from its average.
  • Volatility: Significant jumps in the difference can indicate high-energy moves or potential reversals.

Visual Interpretation

The indicator provides three distinct layers of information on your chart:

  • Main Line: Represents the primary calculated momentum.
  • Dotted Signal Line: Represents the projected trend based on the specified tolerance.
  • On-Screen Data Label: The script dynamically displays a text label on your chart showing the current "Diff" (Difference). Depending on your settings, this can show the raw numerical difference or the percentage of deviation compared to the average.

Summary for the Trader

The logic is built to help you see "where the price wants to go" by measuring the pressure between various time-shifted averages. When the Main Value and the Signal Value move in tandem, it suggests a healthy trend; when they diverge significantly, it may indicate an overextended market or an impending change in direction.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
JJN-Promise
//+------------------------------------------------------------------+
//|                                                   GG-Promise.mq4 |
//|                                      Copyright © 2010, JJ Newark |
//|                                            http:/jjnewark.atw.hu |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, JJ Newark"
#property link      "http:/jjnewark.atw.hu"


//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers      2
#property  indicator_color1       Maroon
#property  indicator_color2       Chocolate
#property  indicator_width1       1
#property  indicator_width2       1
#property  indicator_level1       0.0
#property  indicator_levelcolor   Silver


//---- indicator parameters
extern string   __Copyright__          = "http://jjnewark.atw.hu";


//int shift[]={0,3,5,8,13,21,34,55,89};
//int shift[]={0,2,3,5,8,13,21,34,55};
int shift[]={0,1,2,3,5,8,13,21,34};


extern int      Ma_Period                   = 12;
extern string   Help_for_Signal_Tolerance   = "Min: 1 (the smaller the faster)";
extern int      Signal_Tolerance            = 2;
extern int      Ma_Price                    = PRICE_TYPICAL;
extern int      DiffAvg_Period              = 12;
extern color    DiffColor                   = Maroon;
extern string   Help_for_DiffType           = "0: Value; 1: Percent";
extern int      DiffType                    = 0;


/*
PRICE_CLOSE 0 Close price. 
PRICE_OPEN 1 Open price. 
PRICE_HIGH 2 High price. 
PRICE_LOW 3 Low price. 
PRICE_MEDIAN 4 Median price, (high+low)/2. 
PRICE_TYPICAL 5 Typical price, (high+low+close)/3. 
PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4. 


MODE_SMA 0 Simple moving average, 
MODE_EMA 1 Exponential moving average, 
MODE_SMMA 2 Smoothed moving average, 
MODE_LWMA 3 Linear weighted moving average. 
*/

//---- indicator buffers
double     MainVal[];
double     SignalVal[];
double     DiffValue[];

double val_0,val_1,val_2,val_3,val_4,val_5,val_6,val_7,val_8;
double DiffAvg;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MainVal);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(1,SignalVal);
   SetIndexBuffer(2,DiffValue);
      
   SetIndexLabel(0,"MainVal");
   SetIndexLabel(1,"SignalVal");

   
   
//---- indicator buffers mapping
      
   
//---- 
   IndicatorShortName("JJN-Promise ("+Ma_Period+","+Signal_Tolerance+" - "+Ma_Price+") * http://jjnewark.atw.hu * ");
   
   
//---- initialization done
   return(0);
  }

int deinit()
  {
//----

   ObjectDelete("_DiffValue");
      
//----
   return(0);
  }

int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- 

   for(int i=0; i<limit; i++)
   {
   val_0=iMA(NULL,0,Ma_Period,shift[0],MODE_EMA,Ma_Price,i);
   val_1=iMA(NULL,0,Ma_Period,shift[1],MODE_EMA,Ma_Price,i)-val_0;
   val_2=iMA(NULL,0,Ma_Period,shift[2],MODE_EMA,Ma_Price,i)-val_0;
   val_3=iMA(NULL,0,Ma_Period,shift[3],MODE_EMA,Ma_Price,i)-val_0;
   val_4=iMA(NULL,0,Ma_Period,shift[4],MODE_EMA,Ma_Price,i)-val_0;
   val_5=iMA(NULL,0,Ma_Period,shift[5],MODE_EMA,Ma_Price,i)-val_0;
   val_6=iMA(NULL,0,Ma_Period,shift[6],MODE_EMA,Ma_Price,i)-val_0;
   val_7=iMA(NULL,0,Ma_Period,shift[7],MODE_EMA,Ma_Price,i)-val_0;
   val_8=iMA(NULL,0,Ma_Period,shift[8],MODE_EMA,Ma_Price,i)-val_0;
      
   MainVal[i]=0-(val_1+val_2+val_3+val_4+val_5+val_6+val_7+val_8);
   }
   
   
   
   for(i=0; i<limit; i++)
   {
   SignalVal[i]=MainVal[i+Signal_Tolerance];
   }
   
   
   for(i=0; i<limit; i++)
   {
   DiffValue[i]=MathAbs(MainVal[i]-SignalVal[i]);
   }
   
   
   DiffAvg=iMAOnArray(DiffValue,Bars,DiffAvg_Period,0,MODE_EMA,0);
   double Percent=(MathAbs(DiffValue[0])/DiffAvg)*100;

   
   
   DiffValue[0]=MainVal[0]-SignalVal[0];
   ObjectCreate("_DiffValue", OBJ_LABEL, WindowFind("JJN-Promise ("+Ma_Period+","+Signal_Tolerance+" - "+Ma_Price+") * http://jjnewark.atw.hu * "), 0, 0);
   ObjectSet("_DiffValue", OBJPROP_XDISTANCE, 3); 
   ObjectSet("_DiffValue", OBJPROP_YDISTANCE, 15);
   if(DiffType==0)   
   ObjectSetText("_DiffValue",StringConcatenate("Diff: ",DoubleToStr(DiffValue[0],4)," (",DoubleToStr(DiffAvg,4),")"),10,"Tahoma",DiffColor);
   else if(DiffType==1)   
   ObjectSetText("_DiffValue",StringConcatenate("Diff: ",DoubleToStr(DiffValue[0],4)," (",DoubleToStr(Percent,0),"%)"),10,"Tahoma",DiffColor);
   
         
   
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments