Simply rectangle:
//+------------------------------------------------------------------+
//| IND_RECTANGLE_RP.mq5 |
//+------------------------------------------------------------------+
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
string strObjName = "Rectangle";
ObjectDelete(0, strObjName);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 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[])
{
string strObjName = "Rectangle";
// Vertex 1
datetime dt_1 = time[rates_total - 1];
double pr_1 = high[rates_total - 1];
// Vertex 2
datetime dt_2 = time[rates_total - 4];
double pr_2 = low[rates_total - 4];
ObjectCreate(0, strObjName, OBJ_RECTANGLE, 0, dt_1, pr_1, dt_2, pr_2);
ObjectSetInteger(0, strObjName, OBJPROP_FILL, true);
ObjectSetInteger(0, strObjName, OBJPROP_COLOR, clrLightGreen);
return(rates_total);
}
//+------------------------------------------------------------------+
Determining the specific corners of the rectangle:
//+------------------------------------------------------------------+ //| IND_RECTANGLE_RP.mq5 | //+------------------------------------------------------------------+ #property version "1.00" #property indicator_chart_window #property indicator_buffers 0 #property indicator_plots 0 //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { string strObjName = "Rectangle"; ObjectDelete(0, strObjName); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { string strObjName = "Rectangle"; int i_Bars = 10; datetime dt_1 = time[rates_total - i_Bars]; datetime dt_2 = time[rates_total - 1]; // Min, Max int i_Count = i_Bars; int i_Start = 0; int i_Min = iLowest(Symbol(), PERIOD_CURRENT, MODE_LOW, i_Count, i_Start); int i_Max = iHighest(Symbol(), PERIOD_CURRENT, MODE_HIGH, i_Count, i_Start); double pr_1 = low[rates_total - 1 - i_Min]; double pr_2 = high[rates_total - 1 - i_Max]; ObjectCreate(0, strObjName, OBJ_RECTANGLE, 0, dt_1, pr_1, dt_2, pr_2); ObjectSetInteger(0, strObjName, OBJPROP_FILL, true); ObjectSetInteger(0, strObjName, OBJPROP_COLOR, clrLightGreen); return(rates_total); } //+------------------------------------------------------------------+https://ibb.co/LQzLMgw

pebs85:
double CLow = PRICE_LOW; double CHigh = PRICE_HIGH; double COpen = PRICE_OPEN; double CClose = PRICE_CLOSE; //define Bull and Bear Candles double Bull = PRICE_OPEN<PRICE_CLOSE; double Bear = PRICE_OPEN>PRICE_CLOSE;
Those tokens in red are constants not values. Either:
-
Perhaps you should read the manual.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up. - Or Stop using ChatGPT.
Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum #2 (2023)

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I feel like this shouldnt be this hard, but i am just learning in my journey and trying to work out how to draw a rectangle when there is imbalance there.
I know i could just use an indicator already in the market but then i don't learn anything.
I have gone through the forums and tried to understand but i am just not getting it.
Once i understand this concept, it will help with drawing rectangles around all sorts of boxes.. but i just need that leg up now on how to find the coordinates and then to translate that to what i need specifically
I understand the first time and price is the starting place of the rectangle and the second time and price is the end...
But how would i use those in this case?
Price 1 and Time 1 are candle [3] and Price 2 and Time 2 are current candle and time [0]
But i also need to add in... If Low[4]>High[2] then draw the rectangle from Low[4] and High[2] starting at candle 3 until we delete the rectangle
No where can i find something that is simple and says... here do this
my brain is literally going to fall out....
Here is what i have
and my errors
where i want the rectangle to draw
I tried to follow this script...https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_rectangle
I also followed the below YT and tried to adapt it..
where it is collecting the High and Low for the last 30 candles, sorting the arrays from highest to lowest and storing the highest and lowest prices of the last 30 candles in the array
Then when its actually drawing the box its using time1 as 10 candles back, price1 as the highest price from 30 candles back, time2 as candle 0 (now) and price2 as the lowest price from the last 30 candles