OnTick
Download scriptThis script is designed as a background utility for the MetaTrader 4 trading platform. Its primary purpose is to facilitate communication between different windows or charts on your trading workspace by triggering specific events automatically.
Core Functionality
Instead of performing direct calculations on price action (like identifying trends or moving averages), this script acts as a relay system. It monitors the flow of market data—specifically the "ticks" or updates that happen every time the price moves.
How it Works
The logic follows a straightforward sequence to ensure seamless interaction between different parts of your trading environment:
- Continuous Monitoring: The script stays active and watches for any new price movements occurring on the current chart.
- Event Triggering: Whenever new data arrives, the script identifies that a change has occurred. It then sends out a "Custom Event" signal.
- Cross-Chart Communication: This signal is specifically directed to another chart or window based on settings you provide (the Chart ID and Index).
- Dynamic Updating: By sending these signals as new data appears, it ensures that other tools or indicators on different charts can stay synchronized with the live market movements in real-time.
Summary for the User
Think of this script as a notification system. It tells other components of your trading platform, "The price has moved; you should update your information now." It allows you to link multiple charts together so that an action or piece of data on one screen can immediately influence or inform what you see on another.
//+------------------------------------------------------------------+
//| OnTick.mq4 |
//| Copyright 2018, pipPod. |
//| https://www.mql5.com/en/users/pippod |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, pipPod."
#property link "https://www.mql5.com/en/users/pippod"
#property version "1.00"
#property strict
#property indicator_chart_window
//--- input parameters
input long ChartID=0;
input ushort Index=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
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[])
{
//---
if(prev_calculated)
::EventChartCustom(ChartID,Index,Index,rates_total-prev_calculated,_Symbol);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Comments