Support and Resistance WITH FIBONACCI LA _001

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
Support and Resistance WITH FIBONACCI  LA    _001

This script is designed to automatically identify and visualize key price levels—specifically Support and Resistance—directly on your trading chart. It simplifies the process of identifying where the market might encounter "floors" (support) or "ceilings" (resistance) by scanning historical price action and plotting these zones dynamically.

Core Logic and Functionality

The script operates based on three primary logical stages:

1. Trend Reversal Detection

The tool constantly monitors the relationship between the current market price and a Simple Moving Average (SMA). It looks for specific "crossovers":

  • Resistance Identification: When the price moves from being above the moving average to falling below it, the script flags this as a potential shift in momentum and identifies the highest point reached over the preceding 20 bars. This peak is designated as a Resistance level.
  • Support Identification: Conversely, when the price moves from below the moving average to climbing above it, the script identifies the lowest point reached over the preceding 20 bars. This valley is designated as a Support level.

2. Data Processing and Storage

As the script scans through the history of the chart (from oldest to newest), it stores these identified high and low points into two separate data streams. This allows the tool to maintain a continuous memory of significant price levels even as new candles form, ensuring that historical "peaks" and "valleys" remain visible.

3. Dynamic Visual Mapping

The most interactive part of the script is how it handles the visual display:

  • Automated Drawing: Instead of just showing static lines, the script uses a special function to create or move a "Fibonacci" object on your chart.
  • Contextual Positioning: The tool evaluates the current price relative to the identified Support and Resistance levels. Depending on where the price is currently trading (either above resistance, below support, or trapped in the middle), the script automatically adjusts the position of the visual marker.
  • Visual Feedback: It uses a dashed green line to connect these key points, helping you see the "range" or the "zone" between the current floor and ceiling. This provides a clear visual representation of the price corridor where the market is currently oscillating.

Summary for the User

In plain terms, this script acts as an automated "map maker." It looks at past price movements to find significant turning points (highs and lows) and draws a dynamic line on your chart that connects those points. This helps you quickly see the boundaries of the current market range without having to manually calculate peaks and valleys yourself.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
Support and Resistance WITH FIBONACCI LA _001
//+------------------------------------------------------------------+
//|                                      Support and Resistance .mq4 |
//|                                                                  |
//|                                                                  |
//|                                    Conversion: Dr_Richard_Gaines |
//|                                      dr_richard_gaines@yahoo.com |
//+------------------------------------------------------------------+

#property copyright " Copyright © 2004, MetaQuotes Software Corp."
#property link      " http://www.metaquotes.net/"
#include <stdlib.mqh>
#property indicator_chart_window
#property indicator_color1 Black
#property indicator_buffers 2
#property indicator_color2 Red

#property indicator_width1 3
#property indicator_width2 3

//+------------------------------------------------------------------+
//| Common External variables                                        |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| External variables                                               |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Special Convertion Functions                                     |
//+------------------------------------------------------------------+

int LastTradeTime;
double ExtHistoBuffer[];
double ExtHistoBuffer2[];

void SetLoopCount(int loops)
{
}

void SetIndexValue(int shift, double value)
{
  ExtHistoBuffer[shift] = value;
}

void SetIndexValue2(int shift, double value)
{
  ExtHistoBuffer2[shift] = value;
}

bool MoveObject(string name, int type, datetime Atime, double Aprice, datetime Atime2 = 0, double Aprice2 = 0, color Acolor = CLR_NONE, int Aweight = 0, int Astyle = 0)
{
    if (ObjectFind(name) != -1)
    {
      int OType = ObjectType(name);

      if ((OType == OBJ_VLINE) ||
         (OType == OBJ_HLINE) ||
         (OType == OBJ_TRENDBYANGLE) ||
         (OType == OBJ_TEXT) ||
         (OType == OBJ_ARROW) ||
         (OType == OBJ_LABEL))
      {
        return(ObjectMove(name, 0, Atime, Aprice));
      }

      if ((OType == OBJ_GANNLINE) ||
         (OType == OBJ_GANNFAN) ||
         (OType == OBJ_GANNGRID) ||
         (OType == OBJ_FIBO) ||
         (OType == OBJ_FIBOTIMES) ||
         (OType == OBJ_FIBOFAN) ||
         (OType == OBJ_FIBOARC) ||
         (OType == OBJ_RECTANGLE) ||
         (OType == OBJ_ELLIPSE) ||
         (OType == OBJ_CYCLES) ||
         (OType == OBJ_TREND) ||
         (OType == OBJ_STDDEVCHANNEL) ||
         (OType == OBJ_REGRESSION))
      {
        return(ObjectMove(name, 0, Atime, Aprice) && ObjectMove(name, 1, Atime2, Aprice2));
      }

/*
          OBJ_CHANNEL,
          OBJ_EXPANSION,
          OBJ_FIBOCHANNEL,
          OBJ_TRIANGLE,
          OBJ_PITCHFORK
*/
    }
    else
    {
      return(ObjectCreate(name, type, 0, Atime, Aprice, Atime2, Aprice2, 0, 0) && ObjectSet(name, OBJPROP_COLOR, Acolor));
    }
}

//+------------------------------------------------------------------+
//| End                                                              |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+

int init()
{
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
   SetIndexBuffer(0, ExtHistoBuffer);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);
   SetIndexBuffer(1, ExtHistoBuffer2);
   return(0);
}
int start()
{
//+------------------------------------------------------------------+
//| Local variables                                                  |
//+------------------------------------------------------------------+
int shift = 0;
double res = 0;
double sup = 0;

/*[[
	Name := sup_res
	Author := Copyright © 2004, MetaQuotes Software Corp.
	Link := http://www.metaquotes.net/
	Separate Window := No
	First Color := Blue
	First Draw Type := Symbol
	First Symbol := 119
	Use Second Data := Yes
	Second Color := Red
	Second Draw Type := Symbol
	Second Symbol := 119
]]*/


SetLoopCount(0);
// loop from first bar to current bar (with shift=0)
for(shift=Bars-1;shift>=0 ;shift--){ 
if( Close[shift+2]>= iMA(NULL, 0, 10, 0, MODE_SMA, PRICE_CLOSE, shift+2)&&
 Close[shift+1]< iMA(NULL, 0, 10, 0, MODE_SMA, PRICE_CLOSE, shift+1)) 
res=High[Highest(NULL, 0, MODE_HIGH,shift+20,20)];
if( Close[shift+2]<= iMA(NULL, 0, 10, 0, MODE_SMA, PRICE_CLOSE, shift+2)&&
Close[shift+1]> iMA(NULL, 0, 10, 0, MODE_SMA, PRICE_CLOSE, shift+1)) 
sup=Low[Lowest(NULL, 0, MODE_LOW,shift+20,20)];
	SetIndexValue(shift, res);
	SetIndexValue2(shift, sup);
	if( Close[shift+1]<sup ) 
	MoveObject("trade",OBJ_FIBO,Time[shift+1],sup,Time[shift+1],res,Green,1,STYLE_DASH); else 
if( Close[shift+1]>res ) 
	MoveObject("trade",OBJ_FIBO,Time[shift+1],res,Time[shift+1],sup,Green,1,STYLE_DASH); else 
if( Close[shift+1]<res && Close[shift+1]>sup   ) 
	MoveObject("trade",OBJ_FIBO,Time[shift+1],res,Time[shift+1],sup,Green,1,STYLE_DASH);
} 


  return(0);
}

Comments