Code: Select all
//+------------------------------------------------------------------+
//| PreAsiaDiscipline.mq5 |
//| Pre-Asia Discipline Brake & Friday Levels |
//+------------------------------------------------------------------+
#property copyright "Pre-Asia Discipline"
#property link ""
#property version "1.00"
#property indicator_chart_window
#property indicator_plots 0
// --- Inputs ---
input string InpRiskLimit = "Zero / Micro only"; // 3. Max Risk Limit
input string InpDailyPlan = "Observe only."; // 5. One Sentence Plan
input color InpFriHighColor = clrRed; // Friday High Color
input color InpFriLowColor = clrTeal; // Friday Low Color
input int InpXOffset = 20; // Panel X Offset (Right)
input int InpYOffset = 25; // Panel Y Offset (Top)
#define PREFIX "PAD5_"
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0, PREFIX);
ChartRedraw(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
// 1. Locate Friday Bar on D1
MqlRates d1_rates[];
ArraySetAsSeries(d1_rates, true);
int copied = CopyRates(_Symbol, PERIOD_D1, 0, 10, d1_rates);
double fri_high = 0.0;
double fri_low = 0.0;
if(copied > 0)
{
for(int i = 0; i < copied; i++)
{
MqlDateTime dt;
TimeToStruct(d1_rates[i].time, dt);
if(dt.day_of_week == 5) // 5 = Friday
{
fri_high = d1_rates[i].high;
fri_low = d1_rates[i].low;
break;
}
}
}
if(fri_high > 0.0 && fri_low > 0.0)
{
UpdateLine(PREFIX + "FriHigh", fri_high, InpFriHighColor, "Friday High");
UpdateLine(PREFIX + "FriLow", fri_low, InpFriLowColor, "Friday Low");
}
// 2. Refresh Dashboard
UpdateDashboard(fri_high, fri_low);
ChartRedraw(0);
return(rates_total);
}
//+------------------------------------------------------------------+
//| Horizontal Level Helper |
//+------------------------------------------------------------------+
void UpdateLine(string name, double price, color clr, string tooltip)
{
if(ObjectFind(0, name) < 0)
{
ObjectCreate(0, name, OBJ_HLINE, 0, 0, price);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_DASH);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, name, OBJPROP_BACK, true);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
}
else
{
ObjectSetDouble(0, name, OBJPROP_PRICE, price);
}
ObjectSetString(0, name, OBJPROP_TOOLTIP, tooltip + ": " + DoubleToString(price, _Digits));
}
//+------------------------------------------------------------------+
//| Dashboard Drawing Function |
//+------------------------------------------------------------------+
void UpdateDashboard(double fri_high, double fri_low)
{
int x = InpXOffset + 240;
int y = InpYOffset;
// Background Box
string bg_name = PREFIX + "PanelBG";
if(ObjectFind(0, bg_name) < 0)
{
ObjectCreate(0, bg_name, OBJ_RECTANGLE_LABEL, 0, 0, 0);
ObjectSetInteger(0, bg_name, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
ObjectSetInteger(0, bg_name, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, bg_name, OBJPROP_YDISTANCE, y);
ObjectSetInteger(0, bg_name, OBJPROP_XSIZE, 250);
ObjectSetInteger(0, bg_name, OBJPROP_YSIZE, 145);
ObjectSetInteger(0, bg_name, OBJPROP_BGCOLOR, C'20,24,35');
ObjectSetInteger(0, bg_name, OBJPROP_BORDER_TYPE, BORDER_FLAT);
ObjectSetInteger(0, bg_name, OBJPROP_COLOR, C'50,60,80');
ObjectSetInteger(0, bg_name, OBJPROP_BACK, false);
ObjectSetInteger(0, bg_name, OBJPROP_SELECTABLE, false);
}
// Title
CreateLabel(PREFIX + "T0", "PRE-ASIA CHECKLIST", x - 10, y + 8, clrWhite, 9, true);
// Checklist Items
CreateLabel(PREFIX + "L1", "1. Calendar:", x - 10, y + 30, clrGray, 8, false);
CreateLabel(PREFIX + "V1", "Local prints or noise?", x - 85, y + 30, clrWhite, 8, false);
CreateLabel(PREFIX + "L2", "2. Friday H/L:", x - 10, y + 50, clrGray, 8, false);
string hl_str = (fri_high > 0) ? DoubleToString(fri_high, _Digits - 1) + " / " + DoubleToString(fri_low, _Digits - 1) : "Finding...";
CreateLabel(PREFIX + "V2", hl_str, x - 85, y + 50, clrAqua, 8, false);
CreateLabel(PREFIX + "L3", "3. Max Risk:", x - 10, y + 70, clrGray, 8, false);
CreateLabel(PREFIX + "V3", InpRiskLimit, x - 85, y + 70, clrOrangeRed, 8, true);
CreateLabel(PREFIX + "L4", "4. Spread:", x - 10, y + 90, clrGray, 8, false);
long current_spread = SymbolInfoInteger(_Symbol, SYMBOL_SPREAD);
string spread_str = IntegerToString(current_spread) + " pts -> Flat if silly";
CreateLabel(PREFIX + "V4", spread_str, x - 85, y + 90, (current_spread > 25 ? clrOrangeRed : clrLimeGreen), 8, false);
CreateLabel(PREFIX + "L5", "5. Plan:", x - 10, y + 115, clrGray, 8, false);
CreateLabel(PREFIX + "V5", InpDailyPlan, x - 85, y + 115, clrYellow, 8, true);
}
//+------------------------------------------------------------------+
//| Label Helper |
//+------------------------------------------------------------------+
void CreateLabel(string name, string text, int x, int y, color clr, int font_size, bool bold)
{
if(ObjectFind(0, name) < 0)
{
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetString(0, name, OBJPROP_FONT, bold ? "Arial Bold" : "Arial");
}
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, font_size);
ObjectSetString(0, name, OBJPROP_TEXT, text);
}