TTMStoch
Download scriptThis script is designed to create a specialized technical analysis tool for trading platforms, specifically modeled after the "TTM Stoch" (Time Too Much Stochastic) indicator. Its primary purpose is to help traders visualize price momentum and identify potential overbought or oversold conditions by transforming standard price data into a smoothed visual format.
Core Logic Overview
The script functions by breaking down the market data into three distinct layers of processing:
1. Primary Price Positioning (Raw Stochastic) The tool first looks at recent price action to determine where the current price sits relative to its recent highs and lows. It calculates a percentage value based on how close the current closing price is to the bottom of that range. This tells the user if the market is currently "stretched" toward the top or bottom of its recent volatility.
2. The "Smoothing" Layer (Trend Filtering) To prevent the indicator from being too erratic or "noisy," the script applies a smoothing calculation. Instead of showing raw, jagged movements, it compares the current price position to the previous one and averages them. This results in a smoother line that highlights the underlying trend of the momentum rather than every minor price fluctuation.
3. Range Analysis and Signal Generation The logic then performs a secondary pass to identify the highest and lowest points within a specific window of time (determined by user settings). It creates a second, refined measurement that tracks how the smoothed momentum moves within these highs and lows. Finally, it applies an additional smoothing filter to this data to create a "signal" line.
Visual Output
The script produces two main lines on a separate window below the price chart:
- The Main Momentum Line: This shows the primary movement of the price relative to its recent range.
- The Signal Line: This follows the momentum line but moves more slowly, acting as a guide to confirm shifts in direction.
Practical Use for Traders
By interpreting these lines together, a user can look for specific patterns:
- Overextended Markets: When the lines reach the extreme top or bottom of the indicator window, it suggests the market may be overbought or oversold.
- Trend Confirmation: When the main momentum line crosses above or below the signal line, it can serve as a visual cue that the strength of the move is changing, potentially indicating a reversal or a continuation of a trend.
In summary, this script simplifies complex price volatility into two smoothed lines, allowing traders to focus on the "flow" of the market rather than getting distracted by individual price spikes.
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| TTM Stoch.mq4 |
//| |
//| Converted by Mql2Mq4 v0.7 |
//| http://yousky.free.fr |
//| Copyright © 2006, Yousky Soft |
//+------------------------------------------------------------------+
#property copyright " Scott Black"
#property link " http://www.tradethemajors.com"
#property indicator_separate_window
#property indicator_minimum 0.00
#property indicator_maximum 100.00
#property indicator_color1 Blue
#property indicator_buffers 2
#property indicator_color2 Magenta
//+------------------------------------------------------------------+
//| Common External variables |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| External variables |
//+------------------------------------------------------------------+
extern double Slw = 5;
extern double Pds = 5;
extern double Slwsignal = 3;
//+------------------------------------------------------------------+
//| Special Convertion Functions |
//+------------------------------------------------------------------+
int LastTradeTime;
double ExtHistoBuffer[];
double ExtHistoBuffer2[];
void SetLoopCount(int loops)
{
}
void SetIndexValue(int shift, double value)
{
ExtHistoBuffer[shift] = value;
}
void SetIndexValue2(int shift, double value)
{
ExtHistoBuffer2[shift] = value;
}
double GetIndexValue(int shift)
{
return(ExtHistoBuffer[shift]);
}
double GetIndexValue2(int shift)
{
return(ExtHistoBuffer2[shift]);
}
//+------------------------------------------------------------------+
//| End |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Initialization |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
SetIndexBuffer(0, ExtHistoBuffer);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);
SetIndexBuffer(1, ExtHistoBuffer2);
return(0);
}
int start()
{
//+------------------------------------------------------------------+
//| Local variables |
//+------------------------------------------------------------------+
double AA = 0;
double bb = 0;
double aa1 = 0;
double cnt1 = 0;
int shift = 0;
double cnt = 0;
double loopbegin = 0;
double loopbegin2 = 0;
double loopbegin3 = 0;
bool first = True;
double prevbars = 0;
double sum = 0;
double smconst = 0;
double smconst1 = 0;
double prev = 0;
double prev1 = 0;
double prev2 = 0;
double prev3 = 0;
double weight = 0;
double linear = 0;
double MAValue = 0;
double MAValue2 = 0;
double mavalue3 = 0;
string MAstring = "";
double MyHigh = 0;
double MyLow = 0;
int counter = 0;
double Price = 0;
double Price1 = 0;
double tmpDevAA = 0;
SetLoopCount(0);
smconst = 2 / (1+Slw);
smconst1 = 2 / (1+Slwsignal);
loopbegin = loopbegin+1;
for(shift =2000;shift >=0 ;shift --)
{
prev = GetIndexValue2(shift+1);
// Yousky 15/05/2006 - Change to avoid Zero divide exception.
AA = 0;
tmpDevAA = (High[Highest(NULL, 0, MODE_HIGH,shift+Pds,Pds)] - Low[Lowest(NULL, 0, MODE_LOW,shift+Pds,Pds)]);
if (tmpDevAA != 0)
AA = 100* ((Close[shift] - Low[Lowest(NULL, 0, MODE_LOW,shift+Pds,Pds)]) / tmpDevAA);
// ---
MAValue2 = smconst * (AA-prev) + prev;
SetIndexValue2(shift,MAValue2);
loopbegin = loopbegin-1;
}
loopbegin2 = loopbegin2+1;
for(shift =2000-Pds;shift >=0 ;shift --){
MyHigh = -999999;
MyLow = 99999999;
for(counter =shift;counter <=Pds + shift ;counter ++){
Price= GetIndexValue2(counter);
if( Price > MyHigh )
MyHigh = Price;
if( Pds <= 0 )
MyHigh = Price;
if( Price < MyLow )
MyLow = Price;
if( Pds <= 0 )
MyLow = Price;
}
prev1 = GetIndexValue(shift+1);
aa1=GetIndexValue2(shift);
// Yousky 15/05/2006 - Change to avoid Zero divide exception.
bb= 0;
if ((MyHigh-MyLow) != 0)
bb=100*(aa1-MyLow)/(MyHigh-MyLow);
// ---
MAValue = smconst * (bb-prev1) + prev1;
SetIndexValue(shift,MAValue);
loopbegin2 = loopbegin2-1;
}
loopbegin3 = loopbegin3+1;
for(shift =2000;shift >=0 ;shift --){
prev2=GetIndexValue2(shift+1);
prev3=GetIndexValue(shift);
mavalue3= smconst1 * (prev3-prev2) +prev2;
SetIndexValue2(shift,mavalue3);
loopbegin3 = loopbegin3-1;
}
}
Comments