PriceTrenderChartTest

Download script
Author: Kalenzo
PriceTrenderChartTest

This tool is designed to help traders identify and visualize market trends by comparing actual price movements against a moving average. Its primary purpose is to simplify technical analysis by automatically highlighting when the market shifts from an upward momentum to a downward one, or vice versa.

Core Functionality

1. Multi-Source Price Tracking The script doesn't just look at one type of price. It allows for various "price points" to be used as the basis for its calculations. Depending on your settings, it can evaluate the market based on:

  • Closing prices
  • Opening prices
  • Highs and Lows
  • Custom averages (such as the midpoint between high/low or a mean of all four price points)

2. Trend Identification Logic The logic operates by comparing these price points against a Moving Average (MA).

  • Bullish Signal: If the price is currently trading above the moving average, the script identifies the current trend as "Up."
  • Bearish Signal: If the price falls below the moving average, the script recognizes the trend as "Down."

3. Trend Shift Detection The script is specifically designed to notice the exact moment the trend changes. It monitors the relationship between the price and the moving average from one candle to the next. When a crossover occurs:

  • It detects whether the price crossed from below to above (Upward) or above to below (Downward).
  • It marks these specific transition points on your chart with visual indicators (arrows).
  • It provides an automated text notification on the screen, notifying you of the "Up cross" or "Down cross" along with the specific price at which that shift occurred.

Visual Feedback

To make this data easy to read at a glance, the script handles three distinct visual layers:

  • Price Mapping: A line representing the price basis selected by the user.
  • Trend Line: A visual representation of the moving average used for the comparison.
  • Directional Arrows: Clear markers that appear specifically at the moment the trend reverses, helping you pinpoint potential entry or exit zones without having to manually calculate the crossover.

In summary, this tool acts as an automated "trend watcher." It filters out standard price noise by focusing on the relationship between price and a moving average, alerting you immediately whenever the market's fundamental direction changes.

Price Data Components
Series array that contains close prices for each barSeries array that contains open prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
PriceTrenderChartTest
//+------------------------------------------------------------------+
//|                                                 PriceTrender.mq4 |
//|                                                          Kalenzo |
//|                                      bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Gold
#property indicator_color3 OrangeRed


// Use short MA lengths for testing purposes

extern int TimeFrame = 15,
           Price = 0,
           MaType = 0,
           MaPrice = 0,
           MaLength = 2;
           

double price[], trend[], trend_dir[];
int cur_trend = 0, last_trend = 0;
string trade_direction;
 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
IndicatorBuffers(3);
SetIndexBuffer(0,price);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,0);

SetIndexBuffer(1,trend);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,0);

SetIndexBuffer(2,trend_dir);
SetIndexStyle(2,DRAW_ARROW,0);
SetIndexArrow(2,108);

    
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    limit, bigshift; 
   int    counted_bars=IndicatorCounted(); 
//---- 
   if (counted_bars<0) return(-1); 
   if (counted_bars>0) counted_bars--; 
   limit=Bars-counted_bars; 
   

  
      
// Has trend direction changed?
  if (cur_trend != last_trend)
  {
     if (cur_trend ==1) 
     {
        trend_dir[1] = Low[1]-1*Point;
        trade_direction = "Up cross at price ";
     }   
     else
     {
     trend_dir[1] = High[1]+1*Point;
     trade_direction = "Down cross at price ";
     }
            
    last_trend = cur_trend;
    Comment(trade_direction+iClose(NULL,5,1));  // +Period()+" minute chart.");
   }
   
   
    
   for (int i=limit; i>=0; i--) 
   { 
      bigshift = iBarShift(Symbol(),TimeFrame,Time[i]); 
      price[i] = getPrice(bigshift);
      trend[i] = iMA(Symbol(),TimeFrame,MaLength,0,MaType,MaPrice,bigshift);
   }
   

   // Identify trend direction
   if (price[1] > trend[1])
   {
      cur_trend = 1; 
      // Comment("Trend is up");
   }

   if (price[1] < trend[1])
   {
      cur_trend = -1;
      // Comment("Trend is down");
   }   
       
//---- 
   return(0);
  } 
//+------------------------------------------------------------------+


double getPrice(int shift)
{
   switch(Price)
   {
      case 0 : return ( iClose(Symbol(),TimeFrame,shift) );
      case 1 : return (iOpen(Symbol(),TimeFrame,shift));
      case 2 : return (iHigh(Symbol(),TimeFrame,shift));
      case 3 : return (iLow(Symbol(),TimeFrame,shift));
      case 4 : return ((iLow(Symbol(),TimeFrame,shift)+iHigh(Symbol(),TimeFrame,shift))/2);
      case 5 : return ((iClose(Symbol(),TimeFrame,shift)+iLow(Symbol(),TimeFrame,shift)+iHigh(Symbol(),TimeFrame,shift))/3);
      case 6 : return ((iOpen(Symbol(),TimeFrame,shift)+iClose(Symbol(),TimeFrame,shift)+iLow(Symbol(),TimeFrame,shift)+iHigh(Symbol(),TimeFrame,shift))/4);
   }
}

Comments