Trendlinesday_v1

Download script
Author: nsi2000
Trendlinesday_v1

This script is designed to work as a visual technical analysis tool on your trading charts. Its primary purpose is to automatically identify and display significant price trends by recognizing key "swing" points—specifically the highest peaks and lowest valleys in the market over a set timeframe.

How the Logic Works

The script scans historical price data to find specific structural landmarks. Instead of just looking at every single candle, it uses a moving window (defined by the period setting) to analyze which price points stand out as significant highs or lows.

1. Identifying Key Market Points The tool searches backwards through your chart history to locate:

  • Support Levels: It looks for the lowest price points reached during specific intervals. These represent "bottoms" where the price has historically found a floor.
  • Resistance Levels: It simultaneously looks for the highest price points reached during those same intervals, representing "ceilings" where the price has faced selling pressure.

2. Trendline Visualization Once the script identifies these significant highs and lows, it dynamically draws trendlines on your chart:

  • Downward Trends: It connects identified low points to visualize a descending price path.
  • Upward Trends: It connects identified high points to visualize an ascending price path.

3. Real-Time Updates As new market data arrives, the script constantly recalculates these positions. It automatically moves and updates the coordinates of the trendlines so that they stay aligned with the most recent relevant market structure. This allows you to see evolving trends in real-time without having to manually draw lines every time the price shifts.

Summary for Traders

Essentially, this tool acts as an automated "trend spotter." It filters out the minor noise of the market to highlight the larger price movements. By automatically plotting these upward and downward paths, it helps you visualize the current direction of the market and identify potential areas of support and resistance based on historical peaks and valleys.

8 Views
0 Downloads
0 Favorites
Trendlinesday_v1
//+------------------------------------------------------------------+
//|                                                trendlinesDay.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "nsi2000"
#property link      "http://www.expert-mt4.nm.ru"
//----
#property indicator_chart_window
//---- input parameters
extern int nPeriod=10;
extern int Limit=350;
///---- int Widners Oscilator
int cnt,nCurBar=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- Output in Char
   for(cnt=0; cnt<=5; cnt++)
     {
      ObjectCreate("WSO-"+cnt,OBJ_HLINE,0,0,0);
      ObjectSet("WSO-"+cnt,OBJPROP_COLOR,Red);
      if(cnt<5)
        {
         ObjectCreate("Trend DN-"+cnt,OBJ_TREND,0,0,0,0,0);
         ObjectSet("Trend DN-"+cnt,OBJPROP_COLOR,FireBrick);
        }
      //----
      ObjectCreate("WRO-"+cnt,OBJ_HLINE,0,0,0);
      ObjectSet("WRO-"+cnt,OBJPROP_COLOR,FireBrick);
      if(cnt<5)
        {
         ObjectCreate("Trend UP-"+cnt,OBJ_TREND,0,0,0,0,0);
         ObjectSet("Trend Up-"+cnt,OBJPROP_COLOR,DarkGreen);
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   for(cnt=0; cnt<=5; cnt++)
     {
      ObjectDelete("Trend UP-"+cnt);
      ObjectDelete("Trend DN-"+cnt);
      ObjectDelete("WSO-"+cnt);
      ObjectDelete("WRO-"+cnt);
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//---- TODO: add your code here
   double r1,r2,r3,r4,r5,r6;
   int rt1,rt2,rt3,rt4,rt5,rt6;
   double s1,s2,s3,s4,s5,s6;
   int st1,st2,st3,st4,st5,st6;
//---- Ëèíèè ñîïðîòèâëåíèÿ è ïîääåðæêè
   if(Bars<Limit) Limit=Bars-nPeriod;
   for(nCurBar=Limit; nCurBar>0; nCurBar--)
     {
      if(Low[nCurBar+(nPeriod-1)/2]==Low[Lowest(NULL,0,MODE_LOW,nPeriod,nCurBar)])
        {
         s6=s5; s5=s4; s4=s3; s3=s2; s2=s1; s1=Low[nCurBar+(nPeriod-1)/2];
         st6=st5; st5=st4; st4=st3; st3=st2; st2=st1; st1=nCurBar+(nPeriod-1)/2;
        }
      if(High[nCurBar+(nPeriod-1)/2]==High[Highest(NULL,0,MODE_HIGH,nPeriod,nCurBar)])
        {
         r6=r5; r5=r4; r4=r3; r3=r2; r2=r1; r1=High[nCurBar+(nPeriod-1)/2];
         rt6=rt5; rt5=rt4; rt4=rt3; rt3=rt2; rt2=rt1; rt1=nCurBar+(nPeriod-1)/2;
        }
     }
//---- Move Object in Chart

   ObjectMove("Trend DN-0",1,Time[st1],s1);
   ObjectMove("Trend DN-0",0,Time[st2],s2);
//----
   ObjectMove("Trend UP-0",1,Time[rt1],r1);
   ObjectMove("Trend UP-0",0,Time[rt2],r2);
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments