#property strict
input ENUM_TIMEFRAMES Timeframe = 60; // Timeframe for calculations
input int LookbackPeriod = 240; // Number of bars to look back
input double BullishThreshold = 0.4; // Threshold for bullish condition
input double BearishThreshold = 0.3; // Threshold for bearish condition
input double BreakoutThreshold = 0.8; // Threshold for breakout condition
input double TP1Multiplier = 1.5; // Take Profit level 1 multiplier
input double TP2Multiplier = 2.0; // Take Profit level 2 multiplier
input double TP3Multiplier = 2.5; // Take Profit level 3 multiplier
input double ConsolidationMultiplier = 1.2; // Multiplier for consolidation level
double bullishPercentage;
double bearishPercentage;
double rangingPercentage;
double breakoutLevel;
double consolidationLevel;
void CalculateIndicators(int startBar)
{
int endBar = startBar - LookbackPeriod + 1;
int bullishCount = 0;
int bearishCount = 0;
for (int i = startBar; i >= endBar; i--)
{
// Add your condition to determine bullish or bearish state
if (iClose(_Symbol, Timeframe, i) > iOpen(_Symbol, Timeframe, i))
bullishCount++;
else if (iClose(_Symbol, Timeframe, i) < iOpen(_Symbol, Timeframe, i))
bearishCount++;
}
int totalBars = startBar - endBar + 1;
bullishPercentage = (double)bullishCount / totalBars;
bearishPercentage = (double)bearishCount / totalBars;
rangingPercentage = 1.0 - (bullishPercentage + bearishPercentage);
if (bullishPercentage > BreakoutThreshold)
{
breakoutLevel = iHigh(_Symbol, Timeframe, startBar);
consolidationLevel = breakoutLevel - iATR(_Symbol, Timeframe, 14, startBar) * ConsolidationMultiplier;
}
else if (bearishPercentage > BreakoutThreshold)
{
breakoutLevel = iLow(_Symbol, Timeframe, startBar);
consolidationLevel = breakoutLevel + iATR(_Symbol, Timeframe, 14, startBar) * ConsolidationMultiplier;
}
else
{
breakoutLevel = 0.0;
consolidationLevel = 0.0;
}
}
void DrawBreakoutLevels()
{
ObjectDelete("Breakout_Level");
if (breakoutLevel != 0.0)
{
ObjectCreate(0, OBJ_TREND, 0, 0, 0, 0);
ObjectSetInteger(0, OBJPROP_RAY_RIGHT, false);
ObjectSetInteger(0, OBJPROP_COLOR, clrYellow);
ObjectSetInteger(0, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0, OBJPROP_WIDTH, 1);
ObjectSet("Breakout_Level", OBJPROP_PRICE1, breakoutLevel);
ObjectSet("Breakout_Level", OBJPROP_TIME1, 0);
ObjectSet("Breakout_Level", OBJPROP_PRICE2, breakoutLevel);
ObjectSet("Breakout_Level", OBJPROP_TIME2, 0);
}
}
void DrawConsolidationLevel()
{
ObjectDelete("Consolidation_Level");
if (consolidationLevel != 0.0)
{
ObjectCreate(0, OBJ_TREND, 0, 0, 0, 0);
ObjectSetInteger(0, OBJPROP_RAY_RIGHT, false);
ObjectSetInteger(0, OBJPROP_COLOR, clrDodgerBlue);
ObjectSetInteger(0, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0, OBJPROP_WIDTH, 1);
ObjectSet("Consolidation_Level", OBJPROP_PRICE1, consolidationLevel);
ObjectSet("Consolidation_Level", OBJPROP_TIME1, 0);
ObjectSet("Consolidation_Level", OBJPROP_PRICE2, consolidationLevel);
ObjectSet("Consolidation_Level", OBJPROP_TIME2, 0);
}
}
void DrawDashboard()
{
string dashboardText = StringFormat("Bullish: %.2f%%\nBearish: %.2f%%\nRanging: %.2f%%", bullishPercentage * 100, bearishPercentage * 100, rangingPercentage * 100);
ObjectDelete("Dashboard_Text");
ObjectCreate(0, OBJ_LABEL, 0, 0, 0, 0);
ObjectSet("Dashboard_Text", OBJPROP_COLOR, clrWhite);
ObjectSet("Dashboard_Text", OBJPROP_XDISTANCE, 10);
ObjectSet("Dashboard_Text", OBJPROP_YDISTANCE, 10);
ObjectSetText("Dashboard_Text", dashboardText, 10, "Arial");
}
void OnStart()
{
int ratesTotal = iBars(_Symbol, Timeframe);
int lookbackBars = MathMin(LookbackPeriod, ratesTotal - 1);
int startBar = ratesTotal - 1;
CalculateIndicators(startBar);
DrawBreakoutLevels();
DrawConsolidationLevel();
DrawDashboard();
}
Please help me clean this code for the indicator also share the images of the progress so I can explain to members how it works basically meant for mt5
input ENUM_TIMEFRAMES Timeframe = 60; // Timeframe for calculations
input int LookbackPeriod = 240; // Number of bars to look back
input double BullishThreshold = 0.4; // Threshold for bullish condition
input double BearishThreshold = 0.3; // Threshold for bearish condition
input double BreakoutThreshold = 0.8; // Threshold for breakout condition
input double TP1Multiplier = 1.5; // Take Profit level 1 multiplier
input double TP2Multiplier = 2.0; // Take Profit level 2 multiplier
input double TP3Multiplier = 2.5; // Take Profit level 3 multiplier
input double ConsolidationMultiplier = 1.2; // Multiplier for consolidation level
double bullishPercentage;
double bearishPercentage;
double rangingPercentage;
double breakoutLevel;
double consolidationLevel;
void CalculateIndicators(int startBar)
{
int endBar = startBar - LookbackPeriod + 1;
int bullishCount = 0;
int bearishCount = 0;
for (int i = startBar; i >= endBar; i--)
{
// Add your condition to determine bullish or bearish state
if (iClose(_Symbol, Timeframe, i) > iOpen(_Symbol, Timeframe, i))
bullishCount++;
else if (iClose(_Symbol, Timeframe, i) < iOpen(_Symbol, Timeframe, i))
bearishCount++;
}
int totalBars = startBar - endBar + 1;
bullishPercentage = (double)bullishCount / totalBars;
bearishPercentage = (double)bearishCount / totalBars;
rangingPercentage = 1.0 - (bullishPercentage + bearishPercentage);
if (bullishPercentage > BreakoutThreshold)
{
breakoutLevel = iHigh(_Symbol, Timeframe, startBar);
consolidationLevel = breakoutLevel - iATR(_Symbol, Timeframe, 14, startBar) * ConsolidationMultiplier;
}
else if (bearishPercentage > BreakoutThreshold)
{
breakoutLevel = iLow(_Symbol, Timeframe, startBar);
consolidationLevel = breakoutLevel + iATR(_Symbol, Timeframe, 14, startBar) * ConsolidationMultiplier;
}
else
{
breakoutLevel = 0.0;
consolidationLevel = 0.0;
}
}
void DrawBreakoutLevels()
{
ObjectDelete("Breakout_Level");
if (breakoutLevel != 0.0)
{
ObjectCreate(0, OBJ_TREND, 0, 0, 0, 0);
ObjectSetInteger(0, OBJPROP_RAY_RIGHT, false);
ObjectSetInteger(0, OBJPROP_COLOR, clrYellow);
ObjectSetInteger(0, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0, OBJPROP_WIDTH, 1);
ObjectSet("Breakout_Level", OBJPROP_PRICE1, breakoutLevel);
ObjectSet("Breakout_Level", OBJPROP_TIME1, 0);
ObjectSet("Breakout_Level", OBJPROP_PRICE2, breakoutLevel);
ObjectSet("Breakout_Level", OBJPROP_TIME2, 0);
}
}
void DrawConsolidationLevel()
{
ObjectDelete("Consolidation_Level");
if (consolidationLevel != 0.0)
{
ObjectCreate(0, OBJ_TREND, 0, 0, 0, 0);
ObjectSetInteger(0, OBJPROP_RAY_RIGHT, false);
ObjectSetInteger(0, OBJPROP_COLOR, clrDodgerBlue);
ObjectSetInteger(0, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0, OBJPROP_WIDTH, 1);
ObjectSet("Consolidation_Level", OBJPROP_PRICE1, consolidationLevel);
ObjectSet("Consolidation_Level", OBJPROP_TIME1, 0);
ObjectSet("Consolidation_Level", OBJPROP_PRICE2, consolidationLevel);
ObjectSet("Consolidation_Level", OBJPROP_TIME2, 0);
}
}
void DrawDashboard()
{
string dashboardText = StringFormat("Bullish: %.2f%%\nBearish: %.2f%%\nRanging: %.2f%%", bullishPercentage * 100, bearishPercentage * 100, rangingPercentage * 100);
ObjectDelete("Dashboard_Text");
ObjectCreate(0, OBJ_LABEL, 0, 0, 0, 0);
ObjectSet("Dashboard_Text", OBJPROP_COLOR, clrWhite);
ObjectSet("Dashboard_Text", OBJPROP_XDISTANCE, 10);
ObjectSet("Dashboard_Text", OBJPROP_YDISTANCE, 10);
ObjectSetText("Dashboard_Text", dashboardText, 10, "Arial");
}
void OnStart()
{
int ratesTotal = iBars(_Symbol, Timeframe);
int lookbackBars = MathMin(LookbackPeriod, ratesTotal - 1);
int startBar = ratesTotal - 1;
CalculateIndicators(startBar);
DrawBreakoutLevels();
DrawConsolidationLevel();
DrawDashboard();
}
Please help me clean this code for the indicator also share the images of the progress so I can explain to members how it works basically meant for mt5