arrows_template
Download scriptThis script is designed as a visual trading tool for the MetaTrader 4 platform. Its primary purpose is to automatically identify and display directional movements on your price charts using visual indicators (arrows) and optional audio or pop-up notifications.
Core Functionality
The script monitors the closing prices of candles to determine the immediate trend of the market. It essentially compares the current candle's closing price against the previous candle's closing price to decide which direction to signal.
- Upward Signals: If the current candle closes at a higher price than the previous one, the script places a light blue arrow pointing upward just below the lowest point of that candle.
- Downward Signals: If the current candle closes at a lower price than the previous one, the script places a red arrow pointing downward just above the highest point of that candle.
Key Features and Logic
Visual Positioning The tool includes a specific offset setting (indent). This ensures that the arrows do not overlap directly on top of the price candles, making it easier for the trader to see the exact price action while still clearly viewing the signal.
Data Processing & Efficiency To ensure the platform remains responsive and smooth, the script follows several logic rules:
- Minimum Data Requirement: It waits until there are at least 20 bars of history available before it begins calculating signals.
- Smart Updating: Instead of recalculating every single historical point every time the price moves, the script is designed to detect new data. It updates the visuals dynamically as new bars form or as historical data is loaded.
Alert System For traders who do not want to watch the screen constantly, there is a built-in notification system. When enabled, the script will trigger an alert (a pop-up and sound) whenever a new "UP" or "DOWN" signal is confirmed on the most recently completed bar. This allows for real-time monitoring of market shifts.
Summary for the User
In simple terms, this tool acts as a visual "echo" of price momentum. It paints your chart with clear markers to show you whenever the price has successfully moved higher or lower than its previous position, helping you quickly identify the immediate direction of the market at a glance.
//+------------------------------------------------------------------+
//| arrows_template.mq4 |
//| Copyright 2015, eevviill |
//| http://alievtm.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "eevviill"
#property link "http://alievtm.blogspot.com"
#property version "1.42"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrLightBlue
#property indicator_color2 clrRed
#property indicator_width1 2
#property indicator_width2 2
extern string arr_set="Arrow settings";
extern int arrow_indent=22;
extern int up_arrow_code=233;
extern int down_arrow_code=234;
extern string emp1="///////////////////////////////////////";
extern string al_set="Alerts settings";
extern bool use_alert=false;
extern string up_alert="UP";
extern string down_alert="DOWN";
double up_arr[];
double down_arr[];
int prev_bars;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0,up_arr);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,up_arrow_code);
SetIndexLabel(0,"UP arrow");
SetIndexBuffer(1,down_arr);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,down_arrow_code);
SetIndexLabel(1,"DOWN arrow");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
/*
void OnDeinit(const int reason)
{
string name_delete;
for(int i=ObjectsTotal()-1;i>=0;i--)
{
name_delete=ObjectName(i);
if(StringFind(name_delete,identif)!=-1) ObjectDelete(name_delete);
}
}
*/
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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!=rates_total) Alert(prev_calculated," ",rates_total," M:",Period());
//no bars
if(Bars<20) return(rates_total);
//history update
int all=rates_total;
int counted=prev_calculated;
if(all-counted>1)
{
ArrayInitialize(up_arr,EMPTY_VALUE);
ArrayInitialize(down_arr,EMPTY_VALUE);
counted=0;
}
//main
for(int i=all-counted;i>=0;i--)
{
if(i>Bars-20) i=Bars-20;
if(Close[i]>Close[i+1]) up_arr[i]=Low[i]-arrow_indent*Point; //up arrow
if(Close[i]<Close[i+1]) down_arr[i]=High[i]+arrow_indent*Point; //down arrow
}
//new bar
if(Bars==prev_bars) return(rates_total);
prev_bars=Bars;
//Alerts
if(use_alert)
{
if(up_arr[1]!=EMPTY_VALUE) Alert(Symbol()," ",Period()," ",up_alert);
if(down_arr[1]!=EMPTY_VALUE) Alert(Symbol()," ",Period()," ",down_alert);
}
return(rates_total);
}
//+------------------------------------------------------------------+
Comments