FX_FISH_2MA_v1
Download scriptThis script is a technical analysis tool designed to help traders identify momentum shifts and potential entry or exit points in the financial markets. It uses a sophisticated mathematical approach to smooth out market "noise" and visualize price trends through both visual signals and calculated averages.
Core Logic and Mechanics
1. Price Positioning and Normalization The tool begins by evaluating where the current price sits relative to the recent price extremes (the highest highs and lowest lows) over a specific period. Instead of just looking at the raw price, it calculates a percentage-based value to determine if the market is leaning toward the top or bottom of its recent range. This helps normalize different types of assets into a consistent scale.
2. Momentum Tracking (The "Fish" Calculation) The script employs a recursive formula to track momentum. It takes the price positioning mentioned above and applies a logarithmic transformation.
- Smoothing: By incorporating previous values into the current calculation, the tool prevents the data from jumping erratically, providing a fluid "flow" of momentum.
- Polarity: The resulting data oscillates between positive and negative values, representing the strength and direction of the trend.
3. Visual Representation The script renders this momentum as a histogram in a separate window:
- When the momentum is positive, it appears in one color (SteelBlue).
- When the momentum is negative, it appears in another (Orange).
- A center line acts as the zero-axis, allowing traders to see exactly when the trend flips from bearish to bullish or vice versa.
4. Trend Averages Beyond the raw momentum, the script calculates two distinct Moving Averages (MA1 and MA2) based on the smoothed momentum data. These lines act as a secondary layer of confirmation:
- MA1: Provides a shorter-term trend view.
- MA2: Provides a longer-term trend view. By observing how these two lines interact with each other and the main momentum histogram, traders can identify broader market structures.
5. Automated Signal Generation The script is designed to provide actionable visual cues on the main chart based on specific mathematical thresholds:
- Buy Signals: Triggered when momentum reaches a high positive threshold and shows a specific "turning" pattern relative to its previous values. These are marked with Lime labels.
- Sell Signals: Triggered when momentum drops below a significant negative threshold and exhibits a corresponding turning pattern. These are marked with Red labels.
- Exit Signals: The tool also identifies points where the momentum flips polarity (e.g., moving from positive to negative), suggesting that a trend may be exhausting and it might be time to close an existing position.
Summary for the User
In simple terms, this tool filters out the "jitter" of the market to show you the underlying strength of a move. It tells you not just where the price is now, but how fast it is moving in a specific direction. It uses a "double-check" system: it looks for high-momentum peaks/valleys to suggest trades, while simultaneously plotting smooth trend lines to help you stay aligned with the overall market direction.
// FX_FISH_2MA
#property copyright "Copyright © 2005, Kiko Segui"
#property link "webtecnic@terra.es"
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 SteelBlue
#property indicator_color2 Orange
#property indicator_color3 Black
#property indicator_color4 Blue
#property indicator_color5 Red
double buffer1[];
double buffer2[];
double buffer3[];
double MA1buffer[];
double MA2buffer[];
extern int period=10;
extern int price=0; // 0 or other = (H+L)/2
// 1 = Open
// 2 = Close
// 3 = High
// 4 = Low
// 5 = (H+L+C)/3
// 6 = (O+C+H+L)/4
// 7 = (O+C)/2
extern bool Mode_Fast= False;
extern bool Signals= False;
extern int MA1period=9, MA2period=45;
extern string TypeHelp = "SMA- 0, EMA - 1, SMMA - 2, LWMA- 3";
extern string TypeHelp2 = "John Hyden settings TypeMA1=0, TypeMA2=3";
extern int TypeMA1=0;
extern int TypeMA2=3;
int init()
{
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,1,SteelBlue);
SetIndexBuffer(0,buffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1,Orange);
SetIndexBuffer(1,buffer2);
SetIndexStyle(2,DRAW_LINE);
SetIndexLabel(2,"line");
SetIndexBuffer(2,buffer3);
SetIndexStyle(3,DRAW_LINE);
SetIndexLabel(3,"MA1 "+MA1period);
SetIndexStyle(4,DRAW_LINE);
SetIndexLabel(4,"MA2 "+MA2period);
SetIndexBuffer(3,MA1buffer);
SetIndexBuffer(4,MA2buffer);
return(0);
}
int deinit()
{
int i;
double tmp;
for (i=0;i<Bars;i++)
{
ObjectDelete("SELL SIGNAL: "+DoubleToStr(i,0));
ObjectDelete("BUY SIGNAL: "+DoubleToStr(i,0));
ObjectDelete("EXIT: "+DoubleToStr(i,0));
}
return(0);
}
double Value=0,Value1=0,Value2=0,Fish=0,Fish1=0,Fish2=0;
int buy=0,sell=0;
int start()
{
int counted_bars=IndicatorCounted();
int i;
int barras;
double _price;
double tmp;
double MinL=0;
double MaxH=0;
double Threshold=1.2;
if(counted_bars>0) counted_bars--;
//barras = Bars;ç
barras = Bars-counted_bars;
if (Mode_Fast)
barras = 100;
i = 0;
while(i<barras)
{
MaxH = High[Highest(NULL,0,MODE_HIGH,period,i)];
MinL = Low[Lowest(NULL,0,MODE_LOW,period,i)];
switch (price)
{
case 1: _price = Open[i]; break;
case 2: _price = Close[i]; break;
case 3: _price = High[i]; break;
case 4: _price = Low[i]; break;
case 5: _price = (High[i]+Low[i]+Close[i])/3; break;
case 6: _price = (Open[i]+High[i]+Low[i]+Close[i])/4; break;
case 7: _price = (Open[i]+Close[i])/2; break;
default: _price = (High[i]+Low[i])/2; break;
}
Value = 0.33*2*((_price-MinL)/(MaxH-MinL)-0.5) + 0.67*Value1;
Value=MathMin(MathMax(Value,-0.999),0.999);
Fish = 0.5*MathLog((1+Value)/(1-Value))+0.5*Fish1;
buffer1[i]= 0;
buffer2[i]= 0;
if ( (Fish<0) && (Fish1>0))
{
if (Signals)
{
ObjectCreate("EXIT: "+DoubleToStr(i,0),OBJ_TEXT,0,Time[i],_price);
ObjectSetText("EXIT: "+DoubleToStr(i,0),"EXIT AT "+DoubleToStr(_price,4),7,"Arial",White);
}
buy = 0;
}
if ((Fish>0) && (Fish1<0))
{
if (Signals)
{
ObjectCreate("EXIT: "+DoubleToStr(i,0),OBJ_TEXT,0,Time[i],_price);
ObjectSetText("EXIT: "+DoubleToStr(i,0),"EXIT AT "+DoubleToStr(_price,4),7,"Arial",White);
}
sell = 0;
}
if (Fish>=0)
{
buffer1[i] = Fish;
buffer3[i]= Fish;
}
else
{
buffer2[i] = Fish;
buffer3[i]= Fish;
}
tmp = i;
if ((Fish<-Threshold) &&
(Fish>Fish1) &&
(Fish1<=Fish2))
{
if (Signals)
{
ObjectCreate("SELL SIGNAL: "+DoubleToStr(i,0),OBJ_TEXT,0,Time[i],_price);
ObjectSetText("SELL SIGNAL: "+DoubleToStr(i,0),"SELL AT "+DoubleToStr(_price,4),7,"Arial",Red);
}
sell = 1;
}
if ((Fish>Threshold) &&
(Fish<Fish1) &&
(Fish1>=Fish2))
{
if (Signals)
{
ObjectCreate("BUY SIGNAL: "+DoubleToStr(i,0),OBJ_TEXT,0,Time[i],_price);
ObjectSetText("BUY SIGNAL: "+DoubleToStr(i,0),"BUY AT "+DoubleToStr(_price,4),7,"Arial",Lime);
}
buy=1;
}
Value1 = Value;
Fish2 = Fish1;
Fish1 = Fish;
i++;
}
for(i=0; i<barras; i++)
MA1buffer[i]=iMAOnArray(buffer3,Bars,MA1period,0,TypeMA1,i);
for(i=0; i<barras; i++)
MA2buffer[i]=iMAOnArray(MA1buffer,Bars,MA2period,0,TypeMA2,i);
return(0);
}
//+------------------------------------------------------------------+
Comments