FXFreedomBars_v3

Author: Programmed by Eli hayun
FXFreedomBars_v3
Indicators Used
Commodity channel indexMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
FXFreedomBars_v3
//+------------------------------------------------------------------+
//|											 #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

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---