This tool is designed to assist traders by automatically identifying and plotting specific price levels on a trading chart. Its primary purpose is to highlight "round" numbers or significant price milestones, which are often used by market participants as psychological barriers for buying or selling.
How the Logic Works
The script scans the historical price data of a currency pair and performs the following actions:
1. Price Normalization For most trading pairs, the tool looks at the current closing price and rounds it to the nearest whole number (e.g., if a price is 1.0843, it identifies 1.08 as the base level). This creates a clean "anchor" point for analysis.
2. Multi-Level Mapping Once a base price level is identified, the script automatically calculates eight distinct levels around that price point. These are distributed equally above and below the base:
- Upper Levels: It identifies points at 20, 50, 80, and 100 units above the rounded price.
- Lower Levels: It identifies points at 20, 50, 80, and 100 units below the rounded price.
3. Visual Representation The script places visual markers (arrows) on the chart at these specific coordinates. This allows a trader to see at a glance where potential support or resistance zones might exist based on standard mathematical increments rather than just looking at past price action alone.
4. Specific Currency Adjustment The logic includes a specialized rule for the EURJPY currency pair. Because this pair trades at much higher numerical values compared to most others, the script adjusts its rounding method slightly to ensure the levels remain relevant and accurate for that specific market's scale.
Summary for Traders
Instead of manually drawing lines at every whole number or increment, this script automates the process. It populates your chart with a consistent grid of "Key Levels," helping you identify where price might stall or react based on common mathematical milestones.
//+------------------------------------------------------------------+
//| # KeyLevels.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Modest"
#property link ""
#property indicator_buffers 8
#property indicator_chart_window
#property indicator_color1 Red
//---- buffers
double L20[];double L50[];double L80[];double L100[];
double L_20[];double L_50[];double L_80[]; double L_100[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(8);
SetIndexStyle(0,DRAW_ARROW); SetIndexStyle(1,DRAW_ARROW); SetIndexStyle(2,DRAW_ARROW);
SetIndexStyle(3,DRAW_ARROW); SetIndexStyle(4,DRAW_ARROW); SetIndexStyle(5,DRAW_ARROW);
SetIndexStyle(6,DRAW_ARROW); SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(0, 0x9E);SetIndexArrow(1, 0x9E);SetIndexArrow(2, 0x9E);SetIndexArrow(3, 0x9E);
SetIndexArrow(4, 0x9E);SetIndexArrow(5, 0x9E);SetIndexArrow(6, 0x9E);SetIndexArrow(7, 0x9E);
SetIndexBuffer(0,L20);SetIndexBuffer(1,L50);SetIndexBuffer(2,L80);SetIndexBuffer(3,L100);
SetIndexBuffer(4,L_20);SetIndexBuffer(5,L_50);SetIndexBuffer(6,L_80);SetIndexBuffer(7,L_100);
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double RP;
int counted_bars=IndicatorCounted();
//----
int i = Bars - counted_bars - 1;
while (i>=0)
{
RP=Close[i]; RP=RP*100; RP=MathCeil(RP); RP=RP/100;
L20[i]=RP + Point*20;
L50[i]=RP + Point*50;
L80[i]=RP + Point*80;
L100[i]=RP + Point*100;
L_20[i]=RP - Point*20;
L_50[i]=RP - Point*50;
L_80[i]=RP - Point*80;
L_100[i]=RP - Point*100;
if (Symbol()=="EURJPY")
{
RP=Close[i]; RP=MathCeil(RP);
L20[i]=RP + Point*20;
L50[i]=RP + Point*50;
L80[i]=RP + Point*80;
L100[i]=RP + Point*100;
L_20[i]=RP - Point*20;
L_50[i]=RP - Point*50;
L_80[i]=RP - Point*80;
L_100[i]=RP - Point*100;
}
//if (i==0) Alert(Symbol());
//if (i==0)
// Alert(RP," ",L20[i]," ",L50[i]," ",L80[i]," ",L100[i]," ");
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments