FXFreedomBars_v3
Download scriptThe FX Freedom Bars indicator is a multi-timeframe analysis tool designed to help traders identify market momentum by synchronizing data from four different timeframes simultaneously. Instead of forcing you to switch between different charts to see the "big picture," this script overlays that information directly onto your current view using a series of visual cues (arrows) and dynamic labels.
Core Functionality
Multi-Timeframe Synchronization The primary logic of the script revolves around monitoring four distinct timeframes at once (for example: 5-minute, 15-minute, 30-minute, and an additional 30-minute view). By analyzing these different intervals simultaneously, the indicator helps you see if the shorter-term price action aligns with the longer-term trends.
Automated Context Awareness The script features an "AutoDisplay" logic. This means it can intelligently detect which chart timeframe you are currently viewing and automatically select a logical set of higher timeframes to analyze for you. This ensures that no matter what period you are trading—whether it's minutes, hours, or days—the indicator always provides relevant, multi-layered context.
Dynamic Visual Signaling Rather than using complex lines or cluttered numbers, the logic translates market data into clear visual signals:
- Upward Signals: When the price action on a specific timeframe shows positive momentum (based on smoothed average calculations), an upward arrow is displayed.
- Downward Signals: Conversely, if the price action on that same timeframe indicates negative momentum, a downward arrow appears.
Comparative Analysis Logic The indicator calculates momentum by comparing current price points against Simple Moving Averages (SMA) across all four designated timeframes. It specifically looks at:
- Current Timeframe: Immediate trend validation.
- Higher Timeframes: Establishing the "flow" of the market to ensure you aren't trading against a dominant larger trend.
How it helps the trader
By viewing these four layers of data together, a trader can quickly identify "confluence." When arrows from multiple timeframes point in the same direction at once, it suggests a high-probability trend. If they point in opposite directions, it serves as a warning that while the immediate price might be moving one way, the broader market may be heading another, allowing for more informed and disciplined decision-making.
//+------------------------------------------------------------------+
//| #The Forex Freedom Bars
//|
//+------------------------------------------------------------------+
#property copyright "Programmed by Eli hayun"
#property indicator_separate_window
#property indicator_minimum 0.5
#property indicator_maximum 5
#property indicator_buffers 8
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 DodgerBlue
#property indicator_color4 Red
#property indicator_color5 DodgerBlue
#property indicator_color6 Red
#property indicator_color7 DodgerBlue
#property indicator_color8 Red
//---- buffers
double buf4_up[];
double buf4_down[];
double buf3_up[];
double buf3_down[];
double buf2_up[];
double buf2_down[];
double buf1_up[];
double buf1_down[];
extern bool AutoDisplay = false;
extern int TF1 = PERIOD_M5;//M5
extern int TF2 = PERIOD_M15;//M15
extern int TF3 = PERIOD_M30;//M30
extern int TF4 = PERIOD_M30;//M30
extern int cci_1 = 2;
extern int cci_2 = 2;
extern int cci_3 = 2;
extern int cci_4 = 2;
extern int arrowUp = 110;
extern int arrowDn = 110;
string shortname = "";
int win;
bool firsttime=true;
string objname[4];
string objtext[4];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetAutoDisplay();
shortname = "# FX Freedom("+cci_1+","+cci_2+","+cci_3+","+cci_4+")";
IndicatorShortName(shortname);
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,arrowUp);
SetIndexBuffer(0,buf4_up);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,arrowDn);
SetIndexBuffer(1,buf4_down);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,arrowUp);
SetIndexBuffer(2,buf3_up);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,arrowDn);
SetIndexBuffer(3,buf3_down);
SetIndexEmptyValue(3,0.0);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,arrowUp);
SetIndexBuffer(4,buf2_up);
SetIndexEmptyValue(4,0.0);
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,arrowDn);
SetIndexBuffer(5,buf2_down);
SetIndexEmptyValue(5,0.0);
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,arrowUp);
SetIndexBuffer(6,buf1_up);
SetIndexEmptyValue(6,0.0);
SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(7,arrowDn);
SetIndexBuffer(7,buf1_down);
SetIndexEmptyValue(7,0.0);
int i;
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
int i;
for (i=0; i<4; i++) {
ObjectDelete(objname[i]);
}//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int i;
if (counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
//----
if (firsttime) {
win=WindowFind(shortname);
for (i=0;i<4;i++) {
objname[i] = "#QuadCCI_"+win+"_"+i;
}
objtext[0] = tf2txt(TF1)+" ("+cci_1+")";
objtext[1] = tf2txt(TF2)+" ("+cci_2+")";
objtext[2] = tf2txt(TF3)+" ("+cci_3+")";
objtext[3] = tf2txt(TF4)+" ("+cci_4+")";
firsttime=false;
}
for (i=0; i<4; i++) {
if (ObjectFind(objname[i]) == -1) {
ObjectCreate(objname[i], OBJ_TEXT, win, iTime(NULL,0,0)+Period()*180, 1.2+i);
ObjectSetText(objname[i], objtext[i],8,"Arial", Silver);
} else {
ObjectMove(objname[i],0,Time[0]+Period()*180,1.2+i);
}
}
indidraw(limit, TF1, cci_1, 1, 1);
indidraw(limit, TF2, cci_2, 2, 2);
indidraw(limit, TF3, cci_3, 3, 3);
indidraw(limit, TF4, cci_4, 4, 4);
return(0);
}
//+------------------------------------------------------------------+
string tf2txt(int tf)
{
if (tf == PERIOD_M1) return("M1");
if (tf == PERIOD_M5) return("M5");
if (tf == PERIOD_M15) return("M15");
if (tf == PERIOD_M30) return("M30");
if (tf == PERIOD_H1) return("H1");
if (tf == PERIOD_H4) return("H4");
if (tf == PERIOD_D1) return("D1");
if (tf == PERIOD_W1) return("W1");
if (tf == PERIOD_MN1) return("MN1");
return("??");
}
void SetValues(int p1, int p2, int p3, int p4)
{
TF1 = p1; TF2 = p2; TF3 = p3; TF4 = p4;
}
void SetAutoDisplay()
{
if (AutoDisplay) {
switch (Period()) {
case PERIOD_M1 : SetValues(PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30); break;
case PERIOD_M5 : SetValues(PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1); break;
case PERIOD_M15 : SetValues(PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4); break;
case PERIOD_M30 : SetValues(PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1); break;
case PERIOD_H1 : SetValues(PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1); break;
case PERIOD_H4 : SetValues(PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1); break;
case PERIOD_D1 : SetValues(PERIOD_D1, PERIOD_D1, PERIOD_W1, PERIOD_MN1); break;
case PERIOD_W1 : SetValues(PERIOD_W1, PERIOD_W1, PERIOD_W1, PERIOD_MN1); break;
case PERIOD_MN1 : SetValues(PERIOD_MN1, PERIOD_MN1, PERIOD_MN1, PERIOD_MN1); break;
}
}
}
void indidraw(int limit,int tf,int period,int num, double pos)
{
int i,j,k,barmax;
double h,l,tp,tpma;
datetime TimeArray[];
if (tf == Period()) {
for (i=limit-1;i>=0;i--) {
if (iCCI(NULL,0,period,PRICE_TYPICAL,i)>0) {
switch (num) {
case 1: buf1_up[i] = pos;buf1_down[i] = 0;
case 2: buf2_up[i] = pos;buf2_down[i] = 0;
case 3: buf3_up[i] = pos;buf3_down[i] = 0;
case 4: buf4_up[i] = pos;buf4_down[i] = 0;
}
} else {
switch (num) {
case 1: buf1_up[i] = 0; buf1_down[i] = pos;
case 2: buf2_up[i] = 0; buf2_down[i] = pos;
case 3: buf3_up[i] = 0; buf3_down[i] = pos;
case 4: buf4_up[i] = 0; buf4_down[i] = pos;
}
}
}
} else if (tf>Period()) {
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),tf);
barmax=iBars(NULL,tf)-period-1;
j=0;
for (i=0;i<limit;i++) {
if (TimeArray[j]>Time[i])
j++;
if (j>=barmax) return (0);
h=High[i];
l=Low[i];
for (k=i;Time[k]>=TimeArray[j];k++) {
if (h<High[k]) h=High[k];
if (l>Low[k]) l=Low[k];
}
tp=(h+l+Close[i])/3;
tpma=iMA(NULL,tf,period-1,0,MODE_SMA,PRICE_TYPICAL,j+1);
if (tp > tpma) {
switch (num) {
case 1: buf1_up[i] = pos;buf1_down[i] = 0;
case 2: buf2_up[i] = pos;buf2_down[i] = 0;
case 3: buf3_up[i] = pos;buf3_down[i] = 0;
case 4: buf4_up[i] = pos;buf4_down[i] = 0;
}
} else {
switch (num) {
case 1: buf1_up[i] = 0; buf1_down[i] = pos;
case 2: buf2_up[i] = 0; buf2_down[i] = pos;
case 3: buf3_up[i] = 0; buf3_down[i] = pos;
case 4: buf4_up[i] = 0; buf4_down[i] = pos;
}
}
}
}
}
Comments