#property indicator_chart_window
#property copyright "sakisf"
#property link "https://www.forexfactory.com/sakisf"

#property strict
#define Name WindowExpertName()

extern color col1 = clrYellow; //Top Row
extern color col2 = clrRed; // Bottom Row
extern int periods = 0; // Previous bars to calculate (0 = all)
input bool useR = false; // Use range of previous bar as filter
input color FibCol = clrWhite; // Fib lines color
input bool filterpast = true; // Filter based on similar previous bars

double shown[13], showp[13];

bool nodata = false;

//+INIT FUNCTION-----------------------------------------------------+
int OnInit()
{
	//Static builds
	{
		string obname;
		string PercsP[13] = { "-50/-20", "-20/0", "0/20", "20/40", "40/60", "60/80", "80/100", "100/120", "120/140", "140/160", "160/180", "180/200", "200+" };
		string PercsN[13] = { "50/20", "20/0", "0/-20", "-20/-40", "-40/-60", "-60/-80", "-80/-100", "-100/-120", "-120/-140", "-140/-160", "-160/-180", "-180/-200", "-200-" };
		for (int x = 0; x <= 12; x++) {
			obname = Name + "PercsP" + IntegerToString(x); LabelMake(obname, 2, 300 + 85 * x, 60, PercsP[x], 8, "Arial", col1);
			obname = Name + "PercsN" + IntegerToString(x); LabelMake(obname, 2, 300 + 85 * x, 30, PercsN[x], 8, "Arial", col2);
		}
	}

	freq();
	if (ObjectFind(Name + "Fib") == 0) ObjectDelete(Name + "Fib");
	build();
	return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+

//+CALCULATE---------------------------------------------------------+
int OnCalculate(const int rates_total,
	const int prev_calculated,
	const datetime &time[],
	const double &open[],
	const double &high[],
	const double &low[],
	const double &close[],
	const long &tick_volume[],
	const long &volume[],
	const int &spread[])
{
	bool new_1m_check = false;
	static datetime start_1m_time = 0;
	if (start_1m_time < iTime(NULL, ChartPeriod(), 0) && (TimeCurrent() >= (iTime(NULL, ChartPeriod(), 0) + 35) && TimeCurrent() <= (iTime(NULL, ChartPeriod(), 0) + 210)))
	{
		new_1m_check = true;
		start_1m_time = iTime(NULL, ChartPeriod(), 0);
	}
	if (new_1m_check)
	{
		freq();
		ObjectDelete(Name + "Fib");
		build();
		new_1m_check = false;
	}

	bool new_m_check = false;
	static datetime start_m_time = 0;
	if (start_m_time < iTime(NULL, PERIOD_M1, 0))
	{
		new_m_check = true;
		start_m_time = iTime(NULL, PERIOD_M1, 0);
	}
	if (new_m_check)
	{
		checker();
		new_m_check = false;
	}

	if (TimeCurrent() >= ObjectGetInteger(0, Name + "Fib", OBJPROP_TIME1) - 9 * (Period() * 60)) {
		ObjectDelete(Name + "Fib");
		build();
	}

	return(rates_total);
}
//+------------------------------------------------------------------+

//+DEINIT------------------------------------------------------------+
void OnDeinit(const int reason)
{
	ObjectsDeleteAll(0, Name);
	return;
}
//+------------------------------------------------------------------+

//+ChartEvent function-----------------------------------------------+
void OnChartEvent(const int id,
	const long &lparam,
	const double &dparam,
	const string &sparam)
{
	{//Force redraw
		if (id == CHARTEVENT_OBJECT_CLICK)
		{
			if (sparam == StringConcatenate(Name + "PercsP" + IntegerToString(0))) {
				ObjectDelete(Name + "Fib"); build();
			}
		}
	}
}
//+------------------------------------------------------------------+

//+MAIN CALCS--------------------------------------------------------+
void freq() {
	if (Bars < periods || periods == 0) periods = Bars - 1;

	double closep[], closen[];
	ArrayResize(closep, periods); ArrayResize(closen, periods);
	double ranger[];
	ArrayResize(ranger, periods + 1);

	double Pip = (_Point * MathPow(10, MathMod(_Digits, 2)));

	double medR = 0, R1 = 0, R2 = 0, R3 = 0, R4 = 0, RP = 0;
	bool Rb1 = false, Rb2 = false, Rb3 = false, Rb4 = false, Rb5 = false;

	double pasth[], pastl[], pastch, pastcl;
	ArrayResize(pasth, periods + 1); ArrayResize(pastl, periods + 1);

	double pastlfinder[];
	ArrayResize(pastlfinder, periods + 1);
	ArrayInitialize(pastlfinder, 0);
	double pasthfinder[];
	ArrayResize(pasthfinder, periods + 1);
	ArrayInitialize(pasthfinder, 0);
	int both = 0, botl = 0;

	if (filterpast) {
		for (int x = periods - 1; x > 0; x--) {
			if ((iHigh(_Symbol, PERIOD_CURRENT, x + 2) - iLow(_Symbol, PERIOD_CURRENT, x + 2)) != 0) pasth[x] = ((iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 2)) / (iHigh(_Symbol, PERIOD_CURRENT, x + 2) - iLow(_Symbol, PERIOD_CURRENT, x + 2))) - 0.5;
			if ((iHigh(_Symbol, PERIOD_CURRENT, x + 2) - iLow(_Symbol, PERIOD_CURRENT, x + 2)) != 0) pastl[x] = ((iLow(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 2)) / (iHigh(_Symbol, PERIOD_CURRENT, x + 2) - iLow(_Symbol, PERIOD_CURRENT, x + 2))) - 0.5;
		}
		pastch = ((iHigh(_Symbol, PERIOD_CURRENT, 1) - iLow(_Symbol, PERIOD_CURRENT, 2)) / (iHigh(_Symbol, PERIOD_CURRENT, 2) - iLow(_Symbol, PERIOD_CURRENT, 2))) - 0.5;
		pastcl = ((iLow(_Symbol, PERIOD_CURRENT, 1) - iLow(_Symbol, PERIOD_CURRENT, 2)) / (iHigh(_Symbol, PERIOD_CURRENT, 2) - iLow(_Symbol, PERIOD_CURRENT, 2))) - 0.5;

		//Categorize past lows
		for (int x = periods; x > 0; x--) {
			if (pastl[x] < -2) pastlfinder[x] = 1;
			if (pastl[x] > -2 && pastl[x] < -1.8) pastlfinder[x] = 2;
			if (pastl[x] > -1.8 && pastl[x] < -1.6) pastlfinder[x] = 3;
			if (pastl[x] > -1.6 && pastl[x] < -1.4) pastlfinder[x] = 4;
			if (pastl[x] > -1.4 && pastl[x] < -1.2) pastlfinder[x] = 5;
			if (pastl[x] > -1.2 && pastl[x] < -1.0) pastlfinder[x] = 6;
			if (pastl[x] > -1.0 && pastl[x] < -0.8) pastlfinder[x] = 7;
			if (pastl[x] > -0.8 && pastl[x] < -0.6) pastlfinder[x] = 8;
			if (pastl[x] > -0.6 && pastl[x] < -0.4) pastlfinder[x] = 9;
			if (pastl[x] > -0.4 && pastl[x] < -0.2) pastlfinder[x] = 10;
			if (pastl[x] > -0.2 && pastl[x] < 0.0) pastlfinder[x] = 11;
			if (pastl[x] > 0.0 && pastl[x] < 0.2) pastlfinder[x] = 12;
			if (pastl[x] > 0.2 && pastl[x] < 0.5) pastlfinder[x] = 13;
		}

		//Categorize past highs
		for (int x = periods; x > 0; x--) {
			if (pasth[x] > -0.5 && pasth[x] < -0.2) pasthfinder[x] = 14;
			if (pasth[x] > -0.2 && pasth[x] < 0.0) pasthfinder[x] = 15;
			if (pasth[x] > 0.0 && pasth[x] < 0.2) pasthfinder[x] = 16;
			if (pasth[x] > 0.2 && pasth[x] < 0.4) pasthfinder[x] = 17;
			if (pasth[x] > 0.4 && pasth[x] < 0.6) pasthfinder[x] = 18;
			if (pasth[x] > 0.6 && pasth[x] < 0.8) pasthfinder[x] = 19;
			if (pasth[x] > 0.8 && pasth[x] < 1) pasthfinder[x] = 20;
			if (pasth[x] > 1.0 && pasth[x] < 1.2) pasthfinder[x] = 21;
			if (pasth[x] > 1.2 && pasth[x] < 1.4) pasthfinder[x] = 22;
			if (pasth[x] > 1.4 && pasth[x] < 1.6) pasthfinder[x] = 23;
			if (pasth[x] > 1.6 && pasth[x] < 1.8) pasthfinder[x] = 24;
			if (pasth[x] > 1.8 && pasth[x] < 2) pasthfinder[x] = 25;
			if (pasth[x] > 2) pasthfinder[x] = 26;
		}

		//Categorize low
		if (pastcl < -2) botl = 1;
		if (pastcl > -2 && pastcl < -1.8) botl = 2;
		if (pastcl > -1.8 && pastcl < -1.6) botl = 3;
		if (pastcl > -1.6 && pastcl < -1.4) botl = 4;
		if (pastcl > -1.4 && pastcl < -1.2) botl = 5;
		if (pastcl > -1.2 && pastcl < -1.0) botl = 6;
		if (pastcl > -1.0 && pastcl < -0.8) botl = 7;
		if (pastcl > -0.8 && pastcl < -0.6) botl = 8;
		if (pastcl > -0.6 && pastcl < -0.4) botl = 9;
		if (pastcl > -0.4 && pastcl < -0.2) botl = 10;
		if (pastcl > -0.2 && pastcl < 0.0) botl = 11;
		if (pastcl > 0.0 && pastcl < 0.2) botl = 12;
		if (pastcl > 0.2 && pastcl < 0.5) botl = 13;

		//Categorize high
		if (pastch > -0.5 && pastch < -0.2) both = 14;
		if (pastch > -0.2 && pastch < 0.0) both = 15;
		if (pastch > 0.0 && pastch < 0.2) both = 16;
		if (pastch > 0.2 && pastch < 0.4) both = 17;
		if (pastch > 0.4 && pastch < 0.6) both = 18;
		if (pastch > 0.6 && pastch < 0.8) both = 19;
		if (pastch > 0.8 && pastch < 1) both = 20;
		if (pastch > 1.0 && pastch < 1.2) both = 21;
		if (pastch > 1.2 && pastch < 1.4) both = 22;
		if (pastch > 1.4 && pastch < 1.6) both = 23;
		if (pastch > 1.6 && pastch < 1.8) both = 24;
		if (pastch > 1.8 && pastch < 2) both = 25;
		if (pastch > 2) both = 26;
	}

	if (useR) {
		for (int x = periods; x > 0; x--) {
			ranger[x] = (High[x] - Low[x]) / Pip;
		}
		medR = ranger[ArrayMaximum(ranger, 0, 0)] / 5;
		R1 = medR; R2 = 2 * medR; R3 = 3 * medR; R4 = 4 * medR;
		RP = (High[1] - Low[1]) / Pip;
		if (RP > 0 && RP < R1) Rb1 = true;
		if (RP > R1 && RP < R2) Rb2 = true;
		if (RP > R2 && RP < R3) Rb3 = true;
		if (RP > R3 && RP < R4) Rb4 = true;
		if (RP > R4) Rb5 = true;
	}

	bool mode1 = false;
	if (Close[1] > Open[1]) mode1 = true; else mode1 = false;

	if (!useR) {
		for (int x = periods - 1; x > 0; x--) {
			if (mode1) { if (Close[x] > Open[x] && Close[x + 1] > Open[x + 1] && (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) != 0 && pasthfinder[x] == both) closep[x] = ((iHigh(_Symbol, PERIOD_CURRENT, x) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) / (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1))) - 0.5; else closep[x] = -1; }

			if (!mode1) { if (Close[x] > Open[x] && (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) != 0 && pasthfinder[x] == both) closep[x] = ((iHigh(_Symbol, PERIOD_CURRENT, x) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) / (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1))) - 0.5; else closep[x] = -1; }

			if (mode1) { if (Close[x] < Open[x] && (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) != 0 && pastlfinder[x] == botl) closen[x] = ((iLow(_Symbol, PERIOD_CURRENT, x) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) / (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1))) - 0.5; else closen[x] = 1; }

			if (!mode1) { if (Close[x] < Open[x] && Close[x + 1] < Open[x + 1] && (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) != 0 && pastlfinder[x] == botl) closen[x] = ((iLow(_Symbol, PERIOD_CURRENT, x) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) / (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1))) - 0.5; else closen[x] = 1; }
		}
	}

	if (useR) {
		double upl = 0, lol = 0;
		if (Rb1) { lol = 0; upl = R1; }
		if (Rb2) { lol = R1; upl = R2; }
		if (Rb3) { lol = R2; upl = R3; }
		if (Rb4) { lol = R3; upl = R4; }
		if (Rb5) { lol = R4; upl = 5 * medR; }

		for (int x = periods - 1; x > 0; x--) {
			if (mode1) { if ((Close[x] > Open[x]) && (Close[x + 1] > Open[x + 1]) && (ranger[x + 1] > lol && ranger[x + 1] < upl) && (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) != 0 && pasthfinder[x] == both) closep[x] = ((iHigh(_Symbol, PERIOD_CURRENT, x) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) / (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1))) - 0.5; else closep[x] = -1; }

			if (!mode1) { if ((Close[x] > Open[x]) && (ranger[x + 1] > lol && ranger[x + 1] < upl) && (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) != 0 && pasthfinder[x] == both) closep[x] = ((iHigh(_Symbol, PERIOD_CURRENT, x) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) / (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1))) - 0.5; else closep[x] = -1; }

			if (mode1) { if ((Close[x] < Open[x]) && (ranger[x + 1] > lol && ranger[x + 1] < upl) && (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) != 0 && pastlfinder[x] == botl) closen[x] = ((iLow(_Symbol, PERIOD_CURRENT, x) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) / (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1))) - 0.5; else closen[x] = 1; }

			if (!mode1) { if ((Close[x] < Open[x]) && (Close[x + 1] < Open[x + 1]) && (ranger[x + 1] > lol && ranger[x + 1] < upl) && (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) != 0 && pastlfinder[x] == botl) closen[x] = ((iLow(_Symbol, PERIOD_CURRENT, x) - iLow(_Symbol, PERIOD_CURRENT, x + 1)) / (iHigh(_Symbol, PERIOD_CURRENT, x + 1) - iLow(_Symbol, PERIOD_CURRENT, x + 1))) - 0.5; else closen[x] = 1; }
		}
	}

	double postot = 0, negtot = 0;

	for (int x = periods - 1; x > 0; x--) {
		if (closep[x] > -0.5) postot++;
		if (closen[x] < 0.5) negtot++;
	}

	double countp[13];
	ArrayInitialize(countp, 0);
	double countn[13];
	ArrayInitialize(countn, 0);

	for (int x = periods - 1; x > 0; x--) {
		if (closep[x] > -0.5 && closep[x] <= -0.2) countp[0]++;
		if (closep[x] > -0.2 && closep[x] <= 0) countp[1]++;
		if (closep[x] > 0 && closep[x] <= 0.2) countp[2]++;
		if (closep[x] > 0.2 && closep[x] <= 0.4) countp[3]++;
		if (closep[x] > 0.4 && closep[x] <= 0.6) countp[4]++;
		if (closep[x] > 0.6 && closep[x] <= 0.8) countp[5]++;
		if (closep[x] > 0.8 && closep[x] <= 1.0) countp[6]++;
		if (closep[x] > 1 && closep[x] <= 1.2) countp[7]++;
		if (closep[x] > 1.2 && closep[x] <= 1.4) countp[8]++;
		if (closep[x] > 1.4 && closep[x] <= 1.6) countp[9]++;
		if (closep[x] > 1.6 && closep[x] <= 1.8) countp[10]++;
		if (closep[x] > 1.8 && closep[x] <= 2.0) countp[11]++;
		if (closep[x] > 2) countp[12]++;

		if (closen[x] < 0.5 && closen[x] >= 0.2) countn[0]++;
		if (closen[x] < 0.2 && closen[x] >= 0) countn[1]++;
		if (closen[x] < 0 && closen[x] >= -0.2) countn[2]++;
		if (closen[x] < -0.2 && closen[x] >= -0.4) countn[3]++;
		if (closen[x] < -0.4 && closen[x] >= -0.6) countn[4]++;
		if (closen[x] < -0.6 && closen[x] >= -0.8) countn[5]++;
		if (closen[x] < -0.8 && closen[x] >= -1.0) countn[6]++;
		if (closen[x] < -1 && closen[x] >= -1.2) countn[7]++;
		if (closen[x] < -1.2 && closen[x] >= -1.4) countn[8]++;
		if (closen[x] < -1.4 && closen[x] >= -1.6) countn[9]++;
		if (closen[x] < -1.6 && closen[x] >= -1.8) countn[10]++;
		if (closen[x] < -1.8 && closen[x] >= -2.0) countn[11]++;
		if (closen[x] < -2) countn[12]++;
	}

	double statp[13];
	ArrayInitialize(statp, 0);
	double statn[13];
	ArrayInitialize(statn, 0);

	if (postot != 0 && negtot != 0) {
		nodata = false;
		for (int x = 12; x >= 0; x--) {
			statp[x] = (countp[x] / postot) * 100;
			statn[x] = (countn[x] / negtot) * 100;
		}
	}

	if (postot == 0 || negtot == 0) nodata = true;

	ArrayCopy(showp, statp, 0, 0, 0);
	ArrayCopy(shown, statn, 0, 0, 0);
}
//+------------------------------------------------------------------+

//+PRINT PERCENTAGES-------------------------------------------------+
void build() {
	string obname;

	double shownc[13], showpc[13];
	ArrayInitialize(shownc, 0); ArrayInitialize(showpc, 13);

	shownc[12] = shown[12];
	for (int x = 11; x >= 0; x--) {
		shownc[x] = shownc[x + 1] + shown[x];
	}
	showpc[12] = showp[12];
	for (int x = 11; x >= 0; x--) {
		showpc[x] = showpc[x + 1] + showp[x];
	}

	for (int x = 0; x <= 12; x++) {
		if (!nodata) {
			obname = Name + "PcsP" + IntegerToString(x); LabelMake(obname, 2, 300 + 85 * x, 45, DoubleToStr(showp[x], 2) + " / " + DoubleToStr(showpc[x], 2) + "%", 8, "Arial", clrYellow);
			obname = Name + "PcsN" + IntegerToString(x); LabelMake(obname, 2, 300 + 85 * x, 15, DoubleToStr(shown[x], 2) + " / " + DoubleToStr(shownc[x], 2) + "%", 8, "Arial", clrBlack);
		}
	}

	if (nodata) { obname = Name + "PcsP" + "0"; LabelMake(obname, 2, 300, 45, "No Data!", 8, "Arial", col1); obname = Name + "PcsN" + "0"; LabelMake(obname, 2, 300, 15, "No Data!", 8, "Arial", col2); }

	obname = Name + "Fib"; FibMake(obname, Time[0] + 10 * Period() * 60, High[1], Time[0] + 10 * Period() * 60, Low[1], FibCol);
}
//+------------------------------------------------------------------+

//+COLOR CHECKER-----------------------------------------------------+
void checker() {
	double levelprice[23];
	ArrayInitialize(levelprice, 0);

	for (int x = 22; x >= 0; x--) {
		levelprice[x] = ObjectGetDouble(0, Name + "Fib", OBJPROP_LEVELVALUE, x) - 0.5;
	}

	double level0[23];
	ArrayInitialize(level0, 0);

	for (int x = 22; x >= 0; x--) {
		level0[x] = ((High[1] + Low[1]) / 2) + (levelprice[x] * (High[1] - Low[1]));
	}

	int levelslow[13] = { 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 14 };
	int levelshigh[13] = { 22, 21, 20, 19, 18, 17, 16, 15, 13, 12, 11, 10, 8 };

	//CurL & LL
	if (Bid < level0[0]) { ObjectSet(Name + "PercsN" + IntegerToString(12), OBJPROP_COLOR, clrBlack); ObjectSetString(0, Name + "PercsN" + IntegerToString(12), OBJPROP_FONT, "Arial Black"); }
	else { ObjectSet(Name + "PercsN" + IntegerToString(12), OBJPROP_COLOR, col2); ObjectSetString(0, Name + "PercsN" + IntegerToString(12), OBJPROP_FONT, "Arial"); }
	for (int x = 0, i = 11; x <= 11; x++, i--) {
		if (Bid > level0[levelslow[x]] && Bid < level0[levelslow[x + 1]]) { ObjectSet(Name + "PercsN" + IntegerToString(i), OBJPROP_COLOR, clrBlack); ObjectSetString(0, Name + "PercsN" + IntegerToString(i), OBJPROP_FONT, "Arial Black"); }
		else { ObjectSet(Name + "PercsN" + IntegerToString(i), OBJPROP_COLOR, col2); ObjectSetString(0, Name + "PercsN" + IntegerToString(i), OBJPROP_FONT, "Arial"); }
	}

	if (Low[0] < level0[0]) { ObjectSet(Name + "PercsN" + IntegerToString(12), OBJPROP_COLOR, clrDarkViolet); ObjectSetString(0, Name + "PercsN" + IntegerToString(12), OBJPROP_FONT, "Arial Black"); }
	for (int x = 0, i = 11; x <= 11; x++, i--) {
		if (Low[0] > level0[levelslow[x]] && Low[0] < level0[levelslow[x + 1]]) { ObjectSet(Name + "PercsN" + IntegerToString(i), OBJPROP_COLOR, clrDarkViolet); ObjectSetString(0, Name + "PercsN" + IntegerToString(i), OBJPROP_FONT, "Arial Black"); }
	}

	//CurH & HH
	if (Bid > level0[22]) { ObjectSet(Name + "PercsP" + IntegerToString(12), OBJPROP_COLOR, clrBlack); ObjectSetString(0, Name + "PercsP" + IntegerToString(12), OBJPROP_FONT, "Arial Black"); }
	else { ObjectSet(Name + "PercsP" + IntegerToString(12), OBJPROP_COLOR, col1); ObjectSetString(0, Name + "PercsP" + IntegerToString(12), OBJPROP_FONT, "Arial"); }
	for (int x = 0, i = 11; x <= 11; x++, i--) {
		if (Bid > level0[levelshigh[x + 1]] && Bid < level0[levelshigh[x]]) { ObjectSet(Name + "PercsP" + IntegerToString(i), OBJPROP_COLOR, clrBlack); ObjectSetString(0, Name + "PercsP" + IntegerToString(i), OBJPROP_FONT, "Arial Black"); }
		else { ObjectSet(Name + "PercsP" + IntegerToString(i), OBJPROP_COLOR, col1); ObjectSetString(0, Name + "PercsP" + IntegerToString(i), OBJPROP_FONT, "Arial"); }
	}

	if (High[0] > level0[22]) { ObjectSet(Name + "PercsP" + IntegerToString(12), OBJPROP_COLOR, clrDarkGreen); ObjectSetString(0, Name + "PercsP" + IntegerToString(12), OBJPROP_FONT, "Arial Black"); }
	for (int x = 0, i = 11; x <= 11; x++, i--) {
		if (High[0] > level0[levelshigh[x + 1]] && High[0] < level0[levelshigh[x]]) { ObjectSet(Name + "PercsP" + IntegerToString(i), OBJPROP_COLOR, clrDarkGreen); ObjectSetString(0, Name + "PercsP" + IntegerToString(i), OBJPROP_FONT, "Arial Black"); }
	}
}
//+------------------------------------------------------------------+

//+LABELMAKE FUNCTION------------------------------------------------+
void LabelMake(const string name,
	const int corner,
	const int x,
	const int y,
	const string label,
	const int FSize,
	const string Font,
	const color FCol)
{
	if (ObjectFind(0, name) < 0)
		if (!ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0))
		{
			Print("error: can't create label_object! code #", GetLastError());
		}
	ObjectSetInteger(0, name, OBJPROP_CORNER, corner);
	ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
	ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
	ObjectSetText(name, label, FSize, Font, FCol);
	ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
	ObjectSetInteger(0, name, OBJPROP_READONLY, true);
	ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
	ObjectSetString(0, name, OBJPROP_TOOLTIP, "\n");
}
//+------------------------------------------------------------------+

//+FIBMAKE-----------------------------------------------------------+
bool FibMake(const string name,
	datetime time1,
	double price1,
	datetime time2,
	double price2,
	const color clrFib)
{
	if (ObjectFind(0, name) < 0)
		if (!ObjectCreate(0, name, OBJ_FIBO, 0, time1, price1, time2, price2))
		{
			Print(__FUNCTION__,
				": failed to create \"Fibonacci Retracement\"! Error code = ", GetLastError());
			return (false);
		}
	ObjectSetInteger(0, name, OBJPROP_LEVELS, 23);
	ObjectSetInteger(0, name, OBJPROP_COLOR, clrNONE);
	ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_DOT);
	ObjectSetInteger(0, name, OBJPROP_LEVELCOLOR, clrFib);
	ObjectSetInteger(0, name, OBJPROP_LEVELSTYLE, STYLE_DOT);
	ObjectSetInteger(0, name, OBJPROP_WIDTH, 0);
	ObjectSetInteger(0, name, OBJPROP_BACK, true);
	ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
	ObjectSetInteger(0, name, OBJPROP_SELECTED, false);
	ObjectSetInteger(0, name, OBJPROP_RAY_RIGHT, true);
	ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
	ObjectSetInteger(0, name, OBJPROP_ZORDER, 0);

	double levels[23] = { -1.5, -1.3, -1.1, -0.9, -0.7, -0.5, -0.3, -0.1, 0, 0.1, 0.3, 0.5, 0.7, 0.9, 1, 1.1, 1.3, 1.5, 1.7, 1.9, 2.1, 2.3, 2.5 };
	string levell[23] = { "-2 - %$", "-1.8 - %$", "-1.6 - %$", "-1.4 - %$", "-1.2 - %$", "-1 - %$", "-0.8 - %$", "-0.6 - %$", "-50", "-0.4 - %$", "-0.2 - %$", "0 - %$", "0.2 - %$", "0.4 - %$", "50", "0.6 - %$", "0.8 - %$", "1 - %$", "1.2 - %$", "1.4 - %$", "1.6 - %$", "1.8 - %$", "2 - %$" };

	for (int x = 0; x <= 22; x++) {
		ObjectSetDouble(0, name, OBJPROP_LEVELVALUE, x, levels[x]);
		ObjectSetString(0, name, OBJPROP_LEVELTEXT, x, levell[x]);
	}
	return(true);
}
//+------------------------------------------------------------------+