XFisher_org_v2_Candle
Download scriptThis script is designed to provide a visual representation of price action and trend dynamics on a trading chart. Rather than displaying a standard moving average or simple line, it creates custom "virtual" candles that represent smoothed market data, helping traders identify the underlying flow of price movement while filtering out minor market noise.
Core Logic and Functionality
1. Dynamic Data Smoothing The script uses a sophisticated mathematical approach to process four specific price points: the Open, High, Low, and Close. For each point, it calculates its relative position within a defined lookback window (the "Flare Length"). This allows the tool to understand where the current price sits in relation to recent highs and lows.
2. Trend Analysis Engine The heart of the script lies in its calculation of "Fisher" values. It takes the relative price positions, applies logarithmic transformations, and passes them through a secondary smoothing algorithm (user-selectable, such as JJMA). This process results in four distinct smoothed components:
- Open Value: Represents the smoothed starting point of the trend.
- High Value: Tracks the smoothed upper boundary.
- Low Value: Tracks the smoothed lower boundary.
- Close Value: Tracks the smoothed ending point of the current movement.
3. Visual Candle Construction Instead of plotting these as simple lines, the script synthesizes them into a visual "candle" structure. It identifies the maximum and minimum values among these four smoothed components to determine the "wick" and "body" limits. These are then drawn on the chart as custom objects.
4. Intelligent Coloring System The script features an automated coloring logic that changes the appearance of the candles based on two main factors:
- Trend Direction: It compares the final smoothed Close against the smoothed Open to determine if the move is bullish or bearish.
- Momentum Intensity: It uses "Level" thresholds (High and Low levels). If the price moves significantly beyond these boundaries, the color shifts to signal a stronger trend momentum; otherwise, it uses more neutral colors to indicate a stabilizing or weaker market phase.
5. Continuity and Gap Handling To ensure the visual representation remains fluid, the script includes logic to handle price "gaps." If a gap between candles is too small (based on a user-defined setting), the script bridges the data points so that the visual trend appears continuous rather than broken.
ÿþ//+---------------------------------------------------------------------+
//| XFisher_org_v2_Candle.mq5 |
//| Copyright © 2006, TrendLaboratory Ltd. |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//| E-mail: igorad2004@list.ru |
//+---------------------------------------------------------------------+
//| ;O @01>BK 8=48:0B>@0 A;54C5B ?>;>68BL D09; SmoothAlgorithms.mqh |
//| 2 ?0?:C (48@5:B>@8N): :0B0;>3_40==KE_B5@<8=0;0\\MQL5\Include |
//+---------------------------------------------------------------------+
//---- 02B>@AB2> 8=48:0B>@0
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
//---- 02B>@AB2> 8=48:0B>@0
#property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
//---- =><5@ 25@A88 8=48:0B>@0
#property version "1.00"
//---- >B@8A>2:0 8=48:0B>@0 2 >B45;L=>< >:=5
#property indicator_separate_window
//---- 4;O @0AG5B0 8 >B@8A>2:8 8=48:0B>@0 8A?>;L7>20=> ?OBL 1CD5@>2
#property indicator_buffers 5
//---- 8A?>;L7>20=> 2A53> >4=> 3@0D8G5A:>5 ?>AB@>5=85
#property indicator_plots 1
//+----------------------------------------------+
//| 0@0<5B@K >B@8A>2:8 8=48:0B>@0 Fisher_org_v2 |
//+----------------------------------------------+
//---- 2 :0G5AB25 8=48:0B>@0 8A?>;L7>20=K F25B=K5 A25G8
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 clrMagenta,clrPlum,clrGray,clrLightSkyBlue,clrBlue
//---- >B>1@065=85 <5B:8 8=48:0B>@0
#property indicator_label1 "XFisher_org_v2 Open;XFisher_org_v2 High;XFisher_org_v2 Low;XFisher_org_v2 Close"
//+----------------------------------------------+
//| 1JO2;5=85 :>=AB0=B |
//+----------------------------------------------+
#define RESET 0 // :>=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AG5B 8=48:0B>@0
//+----------------------------------------------+
//| ?8A0=85 :;0AA0 CXMA |
//+----------------------------------------------+
#include <SmoothAlgorithms.mqh>
//+----------------------------------------------+
//---- >1JO2;5=85 ?5@5<5==KE :;0AA0 CXMA 87 D09;0 SmoothAlgorithms.mqh
CXMA oXMA,hXMA,lXMA,cXMA;
//+----------------------------------------------+
//| >1JO2;5=85 ?5@5G8A;5=89 |
//+----------------------------------------------+
/*enum Smooth_Method - ?5@5G8A;5=85 >1JO2;5=> 2 D09;5 SmoothAlgorithms.mqh
{
MODE_SMA_, // SMA
MODE_EMA_, // EMA
MODE_SMMA_, // SMMA
MODE_LWMA_, // LWMA
MODE_JJMA, // JJMA
MODE_JurX, // JurX
MODE_ParMA, // ParMA
MODE_T3, // T3
MODE_VIDYA, // VIDYA
MODE_AMA, // AMA
}; */
//+----------------------------------------------+
//| E>4=K5 ?0@0<5B@K 8=48:0B>@0 |
//+----------------------------------------------+
input uint FLength=14; // 3;C18=0 CA@54=5=8O
input Smooth_Method MA_SMethod=MODE_JJMA; // 5B>4 A3;06820=8O
input uint MA_Length=5; // ;C18=0 A3;06820=8O
input int MA_Phase=15; // ?0@0<5B@ A3;06820=8O,
//---- 4;O JJMA 87<5=ONI89AO 2 ?@545;0E -100 ... +100, 2;8O5B =0 :0G5AB2> ?5@5E>4=>3> ?@>F5AA0;
//---- ;O VIDIA MB> ?5@8>4 CMO, 4;O AMA MB> ?5@8>4 <54;5==>9 A:>;L7OI59
input uint Gap=10; // @07<5@ =5CG8BK205<>3> 3M?0 2 ?C=:B0E
input double HighLevel=+0.6; // C@>25=L ?5@570:C?0
input double LowLevel=-0.6; // C@>25=L ?5@5?@>40==>AB8
input int Shift=0; // !4283 8=48:0B>@0 ?> 3>@87>=B0;8 2 10@0E
//+----------------------------------------------+
//---- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 1C4CB 2 40;L=59H5< 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2
double ExtOpenBuffer[];
double ExtHighBuffer[];
double ExtLowBuffer[];
double ExtCloseBuffer[];
double ExtColorBuffer[];
//---- >1JO2;5=85 F5;>G8A;5==KE ?5@5<5==KE =0G0;0 >BAG5B0 40==KE
int min_rates_total,min_rates_1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- 8=8F80;870F8O ?5@5<5==KE =0G0;0 >BAG5B0 40==KE
min_rates_1=int(FLength)+1;
min_rates_total=min_rates_1+GetStartBars(MA_SMethod,MA_Length,MA_Phase);
//---- ?@52@0I5=85 48=0<8G5A:8E <0AA82>2 2 8=48:0B>@=K5 1CD5@K
SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 F25B>2>9, 8=45:A=K9 1CD5@
SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 1 ?> 3>@87>=B0;8 =0 Shift
PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0 =0 min_rates_total
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- 70?@5B =0 >B>1@065=85 7=0G5=89 8=48:0B>@0 2 ;52>< 25@E=5< C3;C >:=0 8=48:0B>@0
PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
//---- 8=8F80;870F88 ?5@5<5==>9 4;O :>@>B:>3> 8<5=8 8=48:0B>@0
string shortname;
StringConcatenate(shortname,"XFisher_org_v2_Candle(",FLength,")");
//---- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5
IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//---- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0
IndicatorSetInteger(INDICATOR_DIGITS,4);
//---- :>;8G5AB2> 3>@87>=B0;L=KE C@>2=59 8=48:0B>@0 3
IndicatorSetInteger(INDICATOR_LEVELS,3);
//---- 7=0G5=8O 3>@87>=B0;L=KE C@>2=59 8=48:0B>@0
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,HighLevel);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,50);
IndicatorSetDouble(INDICATOR_LEVELVALUE,2,LowLevel);
//---- 2 :0G5AB25 F25B>2 ;8=89 3>@87>=B0;L=KE C@>2=59 8A?>;L7>20=K
IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrTeal);
IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrGray);
IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,clrMagenta);
//---- 2 ;8=88 3>@87>=B0;L=>3> C@>2=O 8A?>;L7>20= :>@>B:89 HB@8E-?C=:B8@
IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_DASHDOTDOT);
IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,STYLE_DASHDOTDOT);
IndicatorSetInteger(INDICATOR_LEVELSTYLE,2,STYLE_DASHDOTDOT);
//---- 7025@H5=85 8=8F80;870F88
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5
const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5
const datetime &time[],
const double &open[],
const double& high[], // F5=>2>9 <0AA82 <0:A8<C<>2 F5=K 4;O @0AG5B0 8=48:0B>@0
const double& low[], // F5=>2>9 <0AA82 <8=8<C<>2 F5=K 4;O @0AG5B0 8=48:0B>@0
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AG5B0
if(rates_total<min_rates_total) return(RESET);
//---- >1JO2;5=8O ;>:0;L=KE ?5@5<5==KE
int first,bar;
double smax,smin,price,wpr,ovalue,hvalue,lvalue,cvalue,res1,res2,ofish,hfish,lfish,cfish,O,H,L,C;
static double ovalue_prev,ofish_prev,hvalue_prev,hfish_prev,lvalue_prev,lfish_prev,cvalue_prev,cfish_prev;
//---- @0AG5B AB0@B>2>3> =><5@0 first 4;O F8:;0 ?5@5AG5B0 10@>2
if(prev_calculated>rates_total || prev_calculated<=0) // ?@>25@:0 =0 ?5@2K9 AB0@B @0AG5B0 8=48:0B>@0
{
first=min_rates_1; // AB0@B>2K9 =><5@ 4;O @0AG5B0 2A5E 10@>2
ovalue_prev=hvalue_prev=lvalue_prev=cvalue_prev=NULL;
ofish_prev=hfish_prev=lfish_prev=cfish_prev=0.0;
}
else first=prev_calculated-1; // AB0@B>2K9 =><5@ 4;O @0AG5B0 =>2KE 10@>2
//---- >A=>2=>9 F8:; @0AG5B0 8=48:0B>@0
for(bar=first; bar<rates_total && !IsStopped(); bar++)
{
smax=DBL_MIN;
smin=DBL_MAX;
//----
for(int iii=0; iii<int(FLength); iii++)
{
int barx=bar-iii;
smax=MathMax(smax,high[barx]);
smin=MathMin(smin,low[barx]);
}
if(smax==smin) smax+=_Point;
//----
price=open[bar];
wpr=(price-smin)/(smax-smin);
ovalue=(wpr-0.5)+0.67*ovalue_prev;
ovalue=MathMin(ovalue,+DBL_MAX);
ovalue=MathMax(ovalue,-DBL_MAX);
res1=1.0-ovalue;
if(!res1) res1=1.0;
res2=(1.0+ovalue)/(1.0-ovalue);
if(res2<0.0000001) res2=1.0;
ofish=0.5*MathLog(res2)+0.5*ofish_prev;
O=oXMA.XMASeries(min_rates_1,prev_calculated,rates_total,MA_SMethod,MA_Phase,MA_Length,ofish,bar,false);
//----
price=high[bar];
wpr=(price-smin)/(smax-smin);
hvalue=(wpr-0.5)+0.67*hvalue_prev;
hvalue=MathMin(hvalue,+DBL_MAX);
hvalue=MathMax(hvalue,-DBL_MAX);
res1=1.0-hvalue;
if(!res1) res1=1.0;
res2=(1.0+hvalue)/(1.0-hvalue);
if(res2<0.0000001) res2=1.0;
hfish=0.5*MathLog(res2)+0.5*hfish_prev;
H=hXMA.XMASeries(min_rates_1,prev_calculated,rates_total,MA_SMethod,MA_Phase,MA_Length,hfish,bar,false);
//----
price=low[bar];
wpr=(price-smin)/(smax-smin);
lvalue=(wpr-0.5)+0.67*lvalue_prev;
lvalue=MathMin(lvalue,+DBL_MAX);
lvalue=MathMax(lvalue,-DBL_MAX);
res1=1.0-lvalue;
if(!res1) res1=1.0;
res2=(1.0+lvalue)/(1.0-lvalue);
if(res2<0.0000001) res2=1.0;
lfish=0.5*MathLog(res2)+0.5*lfish_prev;
L=lXMA.XMASeries(min_rates_1,prev_calculated,rates_total,MA_SMethod,MA_Phase,MA_Length,lfish,bar,false);
//----
price=close[bar];
wpr=(price-smin)/(smax-smin);
cvalue=(wpr-0.5)+0.67*cvalue_prev;
cvalue=MathMin(cvalue,+DBL_MAX);
cvalue=MathMax(cvalue,-DBL_MAX);
res1=1.0-cvalue;
if(!res1) res1=1.0;
res2=(1.0+cvalue)/(1.0-cvalue);
if(res2<0.0000001) res2=1.0;
cfish=0.5*MathLog(res2)+0.5*cfish_prev;
C=cXMA.XMASeries(min_rates_1,prev_calculated,rates_total,MA_SMethod,MA_Phase,MA_Length,cfish,bar,false);
//---- 8A?@02;O5< 7=0G5=8O ?>;CG5==KE A25G5:
double Max=MathMax(O,C);
Max=MathMax(Max,L);
Max=MathMax(Max,H);
double Min=MathMin(O,C);
Min=MathMin(Min,L);
Min=MathMin(Min,H);
ExtOpenBuffer[bar]=O;
ExtHighBuffer[bar]=Max;
ExtLowBuffer[bar]=Min;
ExtCloseBuffer[bar]=C;
//---- C40;O5< =5ACI5AB2CNI85 35?K
if(MathAbs(open[bar]-close[bar])<=Gap) ExtOpenBuffer[bar]=ExtCloseBuffer[MathMax(bar-1,0)];
//---- :@0A8< A25G8
int clr=2;
double trend=ExtCloseBuffer[bar]-ExtOpenBuffer[bar];
if(ExtCloseBuffer[bar]>HighLevel || ExtCloseBuffer[bar]<LowLevel)
{
if(trend>0) clr=4.0;
else if(trend<0) clr=0.0;
}
else
{
if(trend>0) clr=3.0;
else if(trend<0) clr=1.0;
}
ExtColorBuffer[bar]=clr;
if(bar<rates_total-1)
{
ovalue_prev=ovalue;
ofish_prev=ofish;
hvalue_prev=hvalue;
hfish_prev=hfish;
lvalue_prev=lvalue;
lfish_prev=lfish;
cvalue_prev=cvalue;
cfish_prev=cfish;
}
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
Comments