- MT5 Zoom
- Errors, bugs, questions
- MT5 Strategy Tester, possible to switch between multiple timeframes ?
I attached an indicator I made which will print the prices on the right of the grid anywhere you press (left click) on the chart.
There isn't a simple function that can obtain these prices on the Y-Axis so you have to create the formula. so this works:
// Calculate the Y-axis value (price level) from the mouse click position 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 mouseYValue = ChartGetDouble(0, CHART_PRICE_MAX) - dparam / pixelsPerPrice;
Click around on the chart and look at the "Experts" tab to see the print.
I attached an indicator I made which will print the prices on the right of the grid anywhere you press (left click) on the chart.
There isn't a simple function that can obtain these prices on the Y-Axis so you have to create the formula. so this works:
Click around on the chart and look at the "Experts" tab to see the print.
If you just wanted to get the open price or the close price of the candle in the current bar, you could use iOpen or iClose function:
void PrintCurrentCandleOpen() { double openPrice = iOpen(Symbol(), Period(), 0); Print("Open price of the current candle: ", openPrice); }
hello, excuse my delay; I tested the indicator but it does not work; nothing appears on the graph when i press left click
as an example.. this will alert on the daily highs of the market
#property copyright "Copyright 2023, YourNameHere" #property link "https://www.example.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_type1 DRAW_ARROW #property indicator_color1 clrRed #property indicator_width1 2 #property indicator_label1 "DailyHighAlert" input int alert_frequency_in_minutes = 15; // Adjust this to control how frequently the alerts are triggered //--- Indicator buffers double dailyHighBuffer[]; int bars_per_day = 1; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0, dailyHighBuffer, INDICATOR_DATA); //--- set the initial value for the indicator buffer ArrayInitialize(dailyHighBuffer, 0); PlotIndexSetInteger(0, PLOT_ARROW, 233); PlotIndexSetInteger(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."); return 0; } // 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 zero if (bars_per_day == 0) { Print("Error: Invalid period specified for the indicator."); return 0; } 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[]) { //--- Check for invalid inputs if (rates_total <= 0 || prev_calculated < 0) return 0; //--- Calculate the current bar's index in the rates array int current_bar_index = rates_total - 1; //--- Calculate the current day's starting index and ending index int current_day_index = current_bar_index / bars_per_day; int day_start_index = current_day_index * bars_per_day; int day_end_index = day_start_index + bars_per_day - 1; //--- Find the highest high of the current day double daily_high = high[day_start_index]; for (int i = day_start_index + 1; i <= day_end_index; i++) { if (high[i] > daily_high) daily_high = high[i]; } //--- Store the daily high in the indicator buffer dailyHighBuffer[current_day_index] = daily_high; //--- Check if the current price reaches the daily high if (close[0] >= daily_high) { //--- Trigger an alert static datetime last_alert_time = TimeCurrent(); datetime current_time = TimeCurrent(); if ((int(current_time) - int(last_alert_time)) >= alert_frequency_in_minutes * 60) { Alert("Price has reached the daily high: ", DoubleToString(daily_high, _Digits)); last_alert_time = current_time; } } return rates_total; }
I suggest studying the high[], low[], and close[] buffers in the OnCalculate function, as these buffers relate to the price of the candles on the chart.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use