Support_and_Resistance

Download script
Author: Copyright � 2006, Jason Robinson (jnrtrading)
Support_and_Resistance

This script is designed to provide visual clarity on trading charts by automatically identifying and drawing key price levels—specifically historical highs and lows—based on a set number of previous days. By visualizing these points, it helps traders identify potential areas of "Support" (where prices may stop falling) and "Resistance" (where prices may stop rising).

Core Functionality

The script automates the process of scanning past market data to highlight significant price milestones. Instead of a trader having to manually mark every peak and valley, the tool performs the following actions:

  • Historical Data Analysis: The user can specify how many days of history they want to analyze (for example, looking back at the last 10 days). The script pulls this daily data to find the highest and lowest prices reached during those periods.
  • Dynamic Line Drawing: For each day within that timeframe, the script draws two distinct lines:
    • A High Line representing the peak price for that specific day.
    • A Low Line representing the bottom price for that specific day.
  • Real-Time Tracking: The tool specifically monitors the current day’s activity. If today's price exceeds yesterday's high or falls below yesterday's low, it draws specific lines to highlight these "new" extremes on the live chart.

Visual Organization

To ensure the chart remains readable and organized, the script uses different visual styles:

  • Color Coding: High-level resistance points are typically colored in Red, while support levels are highlighted in Blue. This allows for an immediate "at-a-glance" understanding of the market's boundaries.
  • Style Differentiation: The script distinguishes between historical data and current trends by using different line styles (such as dashed or dotted lines).
  • Automatic Cleanup: To keep the interface clean, the script is programmed to automatically remove old drawings when the calculation period shifts, ensuring that only relevant, up-to-date information occupies your screen.

Summary for the User

Essentially, this tool acts as a visual map of the market's "memory." It shows you where the price has struggled to go higher or lower in the past, helping you identify significant boundaries that might influence future price movement.

10 Views
0 Downloads
0 Favorites
Support_and_Resistance
//+------------------------------------------------------+\\
//|   Support_and_Resistance.mq4 Release 20061106-rc1    |\\
//|    Copyright © 2006, jnrtrading (Jason Robinson)     |\\
//|   Contact @ http://www.spreadtrade2win.com/forum/    |\\
//+------------------------------------------------------+\\
#property copyright "Copyright © 2006, Jason Robinson (jnrtrading)"
#property link      "http://www.spreadtrade2win.com/forum/"

#property indicator_chart_window
extern int How_Many_Days_To_Calculate = 10;
extern color High_Line_Colour = Red;
extern color Low_Line_Colour = Blue;
extern color Todays_High_Line_Colour = Red;
extern color Todays_Low_Line_Colour = Blue;
extern color SR_Line_Colour = Black;
int x;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
//---- indicators
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
//----
   for (x = 0; x <=How_Many_Days_To_Calculate; x++) {
      ObjectDelete("HighLine"+x);
      ObjectDelete("LowLine"+x);
      ObjectDelete("SRa"+x);
      ObjectDelete("SRb"+x);
   }
   ObjectDelete("TodaysHighLine");
   ObjectDelete("TodaysLowLine");
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   double Rates[][6];
   int i;
   ArrayCopyRates(Rates,Symbol(),PERIOD_D1);
//----
      for (i=1; i<=How_Many_Days_To_Calculate; i++) {
         ObjectDelete("HighLine"+i);
         ObjectCreate("HighLine"+i,OBJ_TREND,0, iTime(NULL,PERIOD_D1,i)+55800, Rates[i][3], iTime(NULL,PERIOD_D1,i-1)+82800, Rates[i][3]);
         ObjectSet("HighLine"+i, OBJPROP_RAY, false);
         ObjectSet("TodaysHighLine"+i, OBJPROP_BACK, true);
         ObjectSet("HighLine"+i, OBJPROP_STYLE, STYLE_DASH);
         ObjectSet("HighLine"+i, OBJPROP_COLOR, High_Line_Colour);
      
         ObjectDelete("LowLine"+i);
         ObjectCreate("LowLine"+i,OBJ_TREND,0, iTime(NULL,PERIOD_D1,i)+55800, Rates[i][2], iTime(NULL,PERIOD_D1,i-1)+82800, Rates[i][2]);
         ObjectSet("LowLine"+i, OBJPROP_RAY, false);
         ObjectSet("LowLine"+i, OBJPROP_BACK, true);
         ObjectSet("LowLine"+i, OBJPROP_STYLE, STYLE_DASH);
         ObjectSet("LowLine"+i, OBJPROP_COLOR, Low_Line_Colour);
      }
      if (Rates[0][3] > Rates[1][3]) {
         ObjectDelete("TodaysHighLine");
         ObjectCreate("TodaysHighLine",OBJ_TREND,0, iTime(NULL,PERIOD_D1,0)+55800, Rates[0][3], iTime(NULL,PERIOD_D1,0)+82800, Rates[0][3]);
         ObjectSet("TodaysHighLine", OBJPROP_RAY, false);
         ObjectSet("TodaysHighLine", OBJPROP_BACK, true);
         ObjectSet("TodaysHighLine", OBJPROP_STYLE, STYLE_DASH);
         ObjectSet("TodaysHighLine", OBJPROP_COLOR, Todays_High_Line_Colour);      
      }
      if (Rates[0][2] < Rates[1][2]) {
         ObjectDelete("TodaysLowLine");
         ObjectCreate("TodaysLowLine",OBJ_TREND,0, iTime(NULL,PERIOD_D1,0)+55800, Rates[0][2], iTime(NULL,PERIOD_D1,0)+82800, Rates[0][2]);
         ObjectSet("TodaysLowLine", OBJPROP_RAY, false);
         ObjectSet("TodaysLowLine", OBJPROP_BACK, true);
         ObjectSet("TodaysLowLine", OBJPROP_STYLE, STYLE_DASH);
         ObjectSet("TodaysLowLine", OBJPROP_COLOR, Todays_Low_Line_Colour);      
      }
      for (i=2; i<=How_Many_Days_To_Calculate; i++) {
            ObjectDelete("SRa"+(i-2));
            ObjectCreate("SRa"+(i-2),OBJ_TREND,0, iTime(NULL,PERIOD_D1,1)+55800, Rates[i][3], iTime(NULL,PERIOD_D1,0)+82800, Rates[i][3]);
            ObjectSet("SRa"+(i-2), OBJPROP_RAY, false);
            ObjectSet("SRa"+(i-2), OBJPROP_BACK, true);
            ObjectSet("SRa"+(i-2), OBJPROP_STYLE, STYLE_DOT);
            ObjectSet("SRa"+(i-2), OBJPROP_COLOR, SR_Line_Colour);
            
            ObjectDelete("SRb"+(i-2));
            ObjectCreate("SRb"+(i-2),OBJ_TREND,0, iTime(NULL,PERIOD_D1,1)+55800, Rates[i][2], iTime(NULL,PERIOD_D1,0)+82800, Rates[i][2]);
            ObjectSet("SRb"+(i-2), OBJPROP_RAY, false);
            ObjectSet("SRb"+(i-2), OBJPROP_BACK, true);
            ObjectSet("SRb"+(i-2), OBJPROP_STYLE, STYLE_DOT);
            ObjectSet("SRb"+(i-2), OBJPROP_COLOR, SR_Line_Colour);
      }   
      ObjectsRedraw();
//----
   return(0);
}
//+------------------------------------------------------------------+

Comments