FXFreedomBars_v2
Download scriptOverview of the Forex Freedom Bars Logic
The "Forex Freedom Bars" is a multi-timeframe analysis tool designed to help traders identify market trends by synthesizing data from several different time periods simultaneously. Instead of forcing a trader to look at multiple separate charts, this script consolidates information into a single visual interface, using specific markers (arrows) to indicate potential upward or downward momentum.
Multi-Timeframe Synthesis
The core strength of this logic lies in its ability to "look ahead" and "look back." It monitors four different timeframes at once (e.g., 5-minute, 15-minute, 30-minute, and 1-hour charts). By analyzing these various horizons simultaneously, the tool helps users see whether the current price movement is supported by larger, long-term trends or if it is merely a temporary fluctuation on a minor chart.
Intelligent Auto-Scaling
The script features an "AutoDisplay" logic that adjusts based on your current viewing perspective. Depending on which timeframe you have currently open, the tool automatically selects a logical sequence of higher timeframes to monitor. For example, if you are viewing a 5-minute chart, it will automatically pull data from the 15-minute, 30-minute, and 1-hour marks to provide a complete picture of the market's health.
Trend Identification Logic
The tool determines "Up" or "Down" signals using two primary methods depending on the timeframe being analyzed:
- Current Timeframe Analysis: When the script evaluates the chart you are currently viewing, it uses a standard momentum oscillator logic. It looks for specific threshold breaches to determine if the price is gaining strength (upward) or losing steam (downward).
- Higher Timeframe Analysis: When the script calculates data for larger timeframes, it employs a more complex comparison. It calculates an average price point—combining the high, low, and closing prices—and compares it against a Moving Average from that specific larger timeframe. If the current price structure sits above this average, it signals upward momentum; if below, it signals downward momentum.
Visual Output
To make this data easy to read at a glance, the script translates these complex calculations into visual arrows:
- Upward Arrows: Indicate that the momentum across one or more monitored timeframes is bullish.
- Downward Arrows: Indicate that the momentum across one or more monitored timeframes is bearish.
- Dynamic Labeling: The script automatically places text labels on your chart, identifying exactly which timeframe and setting each arrow represents, ensuring you always know which "piece of the puzzle" you are looking at.
//+------------------------------------------------------------------+
//| #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 = "";
//+------------------------------------------------------------------+
//| 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);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
int win=WindowFind(shortname);
string txt;
int i;
for (i=0; i<4; i++) {
switch (i) {
case 0: txt = tf2txt(TF1)+" ("+cci_1+")"; break;
case 1: txt = tf2txt(TF2)+" ("+cci_2+")"; break;
case 2: txt = tf2txt(TF3)+" ("+cci_3+")"; break;
case 3: txt = tf2txt(TF4)+" ("+cci_4+")"; break;
}
ObjectDelete("FF_"+win+"_"+i+"_"+txt);
}//----
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;
//----
int win = WindowFind(shortname);//UniqueNum; //
for (i=0; i<4; i++) {
string txt = "??";
double gp;
switch (i) {
case 0: txt = tf2txt(TF1)+" ("+cci_1+")"; gp = 1.2 + i; break;
case 1: txt = tf2txt(TF2)+" ("+cci_2+")"; gp = 1.2 + i; break;
case 2: txt = tf2txt(TF3)+" ("+cci_3+")"; gp = 1.2 + i; break;
case 3: txt = tf2txt(TF4)+" ("+cci_4+")"; gp = 1.2 + i; break;
}
string name = "FF_"+win+"_"+i+"_"+txt;
if (ObjectFind(name) == -1) {
ObjectCreate(name, OBJ_TEXT, WindowFind(shortname), iTime(NULL,0,0)+Period()*180, gp);
ObjectSetText(name, txt,8,"Arial", Silver);
} else {
ObjectMove(name,0,Time[0]+Period()*180,gp);
}
}
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;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);
if (TimeArray[barmax-1-period]>Time[limit]) {
for (i=barmax*(tf/Period());Time[i]<TimeArray[barmax-1-period];i--) {
//;
}
limit=i;
}
j=limit;
for (i=limit;i>=0;i--) {
while (Time[i]>=TimeArray[j]+(TimeArray[0]-TimeArray[1]) && j>0) {
j--;
}
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