DDFX BullBear89
Download scriptThis script functions as a specialized visual indicator designed to track and display market momentum, specifically categorizing price action into "Bull" (upward) and "Bear" (downward) sentiments. It operates by analyzing the relative position of current prices compared to recent historical highs and lows.
Core Analytical Logic
The tool works by looking at a specific window of time (defined by a user-set period) to determine where the current price sits within its recent range.
- Range Identification: For every point on the chart, the script identifies the highest high and the lowest low reached over the last 32 candles (by default).
- Relative Positioning: It calculates where the midpoint of the current candle falls between those extreme highs and lows. This helps the script understand if the price is currently trending toward the top of its range, the bottom, or sitting in the middle.
- Smoothing and Weighted Movement: The script applies a weighted calculation to this position. Instead of jumping erratically with every tiny price movement, it uses a recursive formula (similar to a moving average) to smooth out the data. This ensures that the indicator reflects a sustained trend rather than "noise."
- Logarithmic Scaling: To make the resulting data more readable and distinct, the script applies a mathematical transformation (logarithm). This emphasizes significant shifts in momentum while keeping the visual representation clean.
Visual Representation and Sentiment Labeling
Once the raw math is processed, the script translates these numbers into a clear visual signal for the trader:
- Trend Detection: The logic looks at the direction of the calculated values. If the trend is moving upward and remains positive, it identifies this as "Bull" sentiment. If the trend turns downward or stays negative, it labels it as "Bear" sentiment.
- Dynamic Labeling: On the chart interface, the script automatically updates a text label to announce the current state of the market (e.g., "volatile = Bull" or "volatile = Bear").
- Histogram Display: The data is plotted as a histogram in a separate window. This allows users to see the history of the momentum at a glance, observing how quickly the sentiment shifts from one extreme to the other.
Summary for the User
Essentially, this tool takes complex price fluctuations and simplifies them into a "tug-of-war" display. It filters out minor distractions to show you whether the prevailing weight of the market is currently leaning toward a bullish increase or a bearish decline, providing a clear textual and visual summary of the current trend.
/*
Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
Website: http://purebeam.biz
E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_minimum -0.0001
#property indicator_maximum 0.0001
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Blue
#property indicator_color3 Red
extern int period = 32;
double g_ibuf_80[];
double g_ibuf_84[];
double g_ibuf_88[];
string gs_92 = "";
string gs_100 = "Bull-Bear";
int init() {
SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 4);
SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 4);
SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 4);
IndicatorDigits(Digits + 1);
SetIndexBuffer(0, g_ibuf_80);
SetIndexBuffer(1, g_ibuf_84);
SetIndexBuffer(2, g_ibuf_88);
IndicatorShortName(gs_100);
SetIndexLabel(1, NULL);
SetIndexLabel(2, NULL);
StempelSEFC();
return (0);
}
int start() {
double ld_0;
double ld_8;
double ld_16;
int li_24 = IndicatorCounted();
if (li_24 < 0) return (-1);
if (li_24 > 0) li_24--;
int li_28 = Bars - li_24;
double ld_unused_32 = GetTickCount();
if (li_28 > 2500) li_28 = 2500;
double ld_unused_40 = GetTickCount();
Print("Calculation time is ", 0.9, " seconds");
double ld_48 = 0;
double ld_56 = 0;
double ld_unused_64 = 0;
double ld_unused_72 = 0;
double ld_80 = 0;
double ld_unused_88 = 0;
double l_low_96 = 0;
double l_high_104 = 0;
creataalltext();
int li_112 = 16777215;
if (li_24 > 0) li_24--;
int li_116 = Bars - li_24;
for (int li_120 = 0; li_120 < li_116; li_120++) {
l_high_104 = High[iHighest(NULL, 0, MODE_HIGH, period, li_120)];
l_low_96 = Low[iLowest(NULL, 0, MODE_LOW, period, li_120)];
ld_16 = (High[li_120] + Low[li_120]) / 2.0;
ld_48 = 0.66 * ((ld_16 - l_low_96) / (l_high_104 - l_low_96) - 0.5) + 0.67 * ld_56;
ld_48 = MathMin(MathMax(ld_48, -0.999), 0.999);
g_ibuf_80[li_120] = MathLog((ld_48 + 1.0) / (1 - ld_48)) / 2.0 + ld_80 / 2.0;
ld_56 = ld_48;
ld_80 = g_ibuf_80[li_120];
}
bool li_124 = TRUE;
for (li_120 = li_116 - 2; li_120 >= 0; li_120--) {
ld_8 = g_ibuf_80[li_120];
ld_0 = g_ibuf_80[li_120 + 1];
if ((ld_8 < 0.0 && ld_0 > 0.0) || ld_8 < 0.0) li_124 = FALSE;
if ((ld_8 > 0.0 && ld_0 < 0.0) || ld_8 > 0.0) li_124 = TRUE;
if (!li_124) {
g_ibuf_88[li_120] = ld_8;
g_ibuf_84[li_120] = 0.0;
gs_92 = "volatile = Bear";
li_112 = 65535;
} else {
g_ibuf_84[li_120] = ld_8;
g_ibuf_88[li_120] = 0.0;
gs_92 = "volatile = Bull";
li_112 = 65280;
}
}
settext("SEFC X4bd Repro", gs_92, 14, li_112, 10, 15);
return (0);
}
void creataalltext() {
createtext("SEFC x4bd Repro");
settext("SEFC x4bd Repro", "", 14, White, 10, 15);
}
void createtext(string a_name_0) {
ObjectCreate(a_name_0, OBJ_LABEL, WindowFind(gs_100), 0, 0);
}
void settext(string a_name_0, string a_text_8, int a_fontsize_16, color a_color_20, int a_x_24, int a_y_28) {
ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_24);
ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_28);
ObjectSetText(a_name_0, a_text_8, a_fontsize_16, "Arial", a_color_20);
}
void StempelSEFC() {
ObjectCreate("Bull-Bear", OBJ_LABEL, 0, 0, 0);
ObjectSetText("Bull-Bear", "http://www.metaquotes.net", 8, "Lucida Handwriting", SpringGreen);
ObjectSet("Bull-Bear", OBJPROP_CORNER, 2);
ObjectSet("Bull-Bear", OBJPROP_XDISTANCE, 5);
ObjectSet("Bull-Bear", OBJPROP_YDISTANCE, 10);
}
Comments