the strategy consists in identifying the first price of the grid on the y axis at the top of the graph, note that this price must correspond to the price which is displayed after 3 zooming of the graph.
in real time, after some movements of the chart this price changes, either up or down; I would like to make sure that there is an alert if there is a difference of 0.5 when changing this price.
the price in x3 zoom must always be the starting price on which the difference in variations must be based.
I tried to do it with some personal codes but I quickly realized that it was really not that; it blocks me.
here is what i wrote as code :
/ inputinputdouble AlertThreshold = 0.5;
int previousTickCount;
double previousValue;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
previousTickCount = 0;
previousValue = 0.0;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
// Oactual ticks (new zoom)int currentTickCount = ChartGetInteger(0, CHART_VISIBLE_BARS);
// check if it is zoom x3if(currentTickCount != previousTickCount)
{
// first visible value on the graphdouble firstVisibleValue = iClose(Symbol(), 0, ChartGetInteger(0, CHART_FIRST_VISIBLE_BAR));
// check variationif(MathAbs(firstVisibleValue - previousValue) >= AlertThreshold)
{
if(firstVisibleValue > previousValue)
{
Alert("positive Variation from ", DoubleToString(firstVisibleValue - previousValue, _Digits));
}
else
{
Alert("negative Variation from ", DoubleToString(previousValue - firstVisibleValue, _Digits));
}
}
previousTickCount = currentTickCount;
previousValue = firstVisibleValue;
}
}
//+------------------------------------------------------------------+
here is an image where i circled the seed value as an example
The way I would think about this is to calculate the highest highs from the beginning of the current month to now, since the top candle wick of the highest price corresponds to the highest value on the graph.
When you say 0.5, you could say 500 points, but the value of 1 point differs between different symbols.
The way I would think about this is to calculate the highest highs from the beginning of the current month to now, since the top candle wick of the highest price corresponds to the highest value on the graph.
When you say 0.5, you could say 500 points, but the value of 1 point differs between different instruments.
so if you want to find a 0.5 rate different in the price you should change the "required_distance" variable to this:
double required_difference = 50000 * point_size;
Test:
Print("50000 points means ", required_difference);
//+------------------------------------------------------------------+//| HighestPriceAlerter.mq5 |//| Copyright 2023, YourNameHere |//| https://www.example.com |//+------------------------------------------------------------------+#property copyright"Copyright 2023, YourNameHere"#property link"https://www.example.com"#property version"1.00"#property indicator_chart_window#property indicator_buffers1#property indicator_plots1#property indicator_type1DRAW_ARROW#property indicator_color1clrRed#property indicator_width12#property indicator_label1"DailyHighAlert"inputint alert_frequency_in_minutes = 15; // Adjust this to control how frequently the alerts are triggered//--- Indicator buffersdouble dailyHighBuffer[];
int bars_per_day = 1;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- indicator buffers mappingSetIndexBuffer(0, dailyHighBuffer, INDICATOR_DATA);
//--- set the initial value for the indicator bufferArrayInitialize(dailyHighBuffer, 0);
PlotIndexSetInteger(0, PLOT_ARROW, 233); //shift the arrow verticallyPlotIndexSetInteger(0, PLOT_ARROW_SHIFT, 50); //shift the arrow vertically//--- Calculate the number of bars in a day (assuming a 24-hour forex market)int period_seconds = PeriodSeconds(PERIOD_M15); // use 15 minute intervals for judgement (must use a time-based period)if (period_seconds == 0)
{
Print("Error: Invalid period specified for the indicator.");
return0;
}
// Calculate bars_per_day only for time-based periods (greater than 0)if (period_seconds >= 60) // Period is 1 minute or higher
{
bars_per_day = 24 * 60 / period_seconds;
}
// Make sure bars_per_day is not zeroif (bars_per_day == 0)
{
Print("Error: Invalid period specified for the indicator.");
return0;
}
returnINIT_SUCCEEDED;
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+// ...intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
//--- Check for invalid inputsif (rates_total <= 0 || prev_calculated < 0)
return0;
//--- Calculate the current bar's index in the rates arrayint current_bar_index = rates_total - 1;
//--- Calculate the current month's starting index and ending indexMqlDateTime mqlTime;
MqlDateTime bar_mqlTime;
datetime current_time = time[current_bar_index];
TimeToStruct(current_time, mqlTime);
int month_start_index = 0;
while (month_start_index < rates_total)
{
datetime bar_time = time[month_start_index];
TimeToStruct(bar_time, bar_mqlTime);
if (bar_mqlTime.year == mqlTime.year && bar_mqlTime.mon == mqlTime.mon)
break;
month_start_index++;
}
int month_end_index = rates_total - 1;
//--- Find the highest high of the current monthdouble monthly_high = high[month_start_index];
for (int i = month_start_index + 1; i <= month_end_index; i++)
{
if (high[i] > monthly_high)
monthly_high = high[i];
}
//--- Store the monthly high in the indicator buffer
dailyHighBuffer[0] = monthly_high;
/*** Don't need to make this alert
Test the alert to get the monthly high value
--- Check if the current price reaches the monthly high
if (close[0] >= monthly_high)
{
//--- Trigger an alert
static datetime last_alert_time = TimeCurrent();
datetime current_time = TimeCurrent();
if (int(current_time - last_alert_time) >= alert_frequency_in_minutes * 60)
{
Alert("Price has reached the monthly high: ", DoubleToString(monthly_high, _Digits));
last_alert_time = current_time;
}
}
***///--- Check if the current price reaches the monthly high with a difference of 0.5 (50,000 points) and then make an alertdouble current_price = close[current_bar_index];
double price_difference = MathAbs(current_price - monthly_high);
double point_size = SymbolInfoDouble(Symbol(), SYMBOL_POINT);
double required_difference = 50000 * point_size;
if (price_difference >= required_difference)
{
//--- Trigger an alertstaticdatetime last_alert_time = TimeCurrent(); // static variable to hold the timestamp when condition occurred
datetime current_time = TimeCurrent(); // time constantly changing (non static)
if (int(current_time - last_alert_time) >= alert_frequency_in_minutes * 60)
{
Alert("Price has reached a difference of 0.5 to the months highs: ", DoubleToString(monthly_high, _Digits));
last_alert_time = current_time;
}
}
return rates_total;
}
voidOnDeinit(constint reason)
{
// Clear the buffer and reset the alertArrayInitialize(dailyHighBuffer, 0);
// Reset any previous alertsResetLastError();
MessageBox("Indicator unloaded. Previous alerts have been cleared.", "Indicator Unloaded", MB_ICONINFORMATION);
}
I would like to know if it is possible to calculate the gap between MT5 grids
I don't know if there is an existing function to do so. I found through my own indicator which uses OnChartEvent that y = 9 at the highest grid line value. Then y seems to increase as you move down to the next subsequent horizontal line on the grid (which is a bit strange...but that's the way the software works). Each grid box is a gap of roughly 32 pixels.
Now without using OnChartEvent you can do something like this to do things based on the grid line price values:
intOnInit(){
double chartHeightInPixels = ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS);
double priceRange = ChartGetDouble(0, CHART_PRICE_MAX) - ChartGetDouble(0, CHART_PRICE_MIN);
double pixelsPerPrice = chartHeightInPixels / priceRange;
double pixelY = 9; // the highest horizontal line on the griddouble priceAtPixel = ChartGetDouble(0, CHART_PRICE_MAX) - (pixelY / pixelsPerPrice);
Print("Price at this y-val: ", priceAtPixel);
return(INIT_SUCCEEDED);
}
It's hacky and complicated, and maybe there is something I don't know about, but perhaps this can work for your use case (if you just keep adding 32 to the pixelY variable, and start at value of 9)
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I tried to do it with some personal codes but I quickly realized that it was really not that; it blocks me.
here is what i wrote as code :
here is an image where i circled the seed value as an example
The way I would think about this is to calculate the highest highs from the beginning of the current month to now, since the top candle wick of the highest price corresponds to the highest value on the graph.
When you say 0.5, you could say 500 points, but the value of 1 point differs between different symbols.
The way I would think about this is to calculate the highest highs from the beginning of the current month to now, since the top candle wick of the highest price corresponds to the highest value on the graph.
When you say 0.5, you could say 500 points, but the value of 1 point differs between different instruments.
I attached a script
I admit it's a great idea.
I made a mistake saying 500*_Point would be 0.5
You can find out through a print.
so if you want to find a 0.5 rate different in the price you should change the "required_distance" variable to this:
Test:
I don't know if there is an existing function to do so. I found through my own indicator which uses OnChartEvent that y = 9 at the highest grid line value. Then y seems to increase as you move down to the next subsequent horizontal line on the grid (which is a bit strange...but that's the way the software works). Each grid box is a gap of roughly 32 pixels.
Now without using OnChartEvent you can do something like this to do things based on the grid line price values:
It's hacky and complicated, and maybe there is something I don't know about, but perhaps this can work for your use case (if you just keep adding 32 to the pixelY variable, and start at value of 9)