st_ind_2x_v1

Download script
Author: Ron T
st_ind_2x_v1

This tool is designed to serve as a visual aid for traders by identifying specific momentum shifts in the market using a smoothing technique. By analyzing price trends, it provides clear visual markers on your chart to highlight potential moments of interest based on directional changes.

How the Logic Works

The core functionality of this script relies on a mathematical calculation known as a Linear Weighted Moving Average (LWMA). Unlike standard averages that treat all past data equally, this specific method places more importance on recent price action, allowing the tool to react more dynamically to current market movements while still filtering out minor "noise."

Here is the step-by-step logic the script follows:

  • Data Smoothing: The script looks at a specific period of historical price data (which can be customized by the user). It calculates a weighted average to determine the general direction of the trend.
  • Trend Comparison: To decide whether to place a signal on the chart, the script compares the current average value against the previous one. It is essentially looking for "inflection points"—the exact moment where the trend shifts from moving up to moving down, or vice versa.
  • Visual Signaling:
    • When the script detects that the trend has shifted in a specific direction (where the previous average is lower than the current one), it places a white dot at the bottom of the price candle.
    • When it detects an opposite shift (where the previous average is higher than or equal to the current one), it places a red dot at the top of the price candle.

Summary for Traders

Instead of forcing you to manually track whether a trend is curving upward or downward, this script automates that observation. It scans the historical data and automatically paints dots on your chart whenever the momentum changes direction. This allows you to quickly identify potential turning points in the market at a glance, helping you stay aligned with the prevailing price movement.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
st_ind_2x_v1
//+------------------------------------------------------------------+
//|                              |
//+------------------------------------------------------------------+
#property copyright "Ron T"
#property link      "http://www.lightpatch.com"

#property indicator_chart_window
#property indicator_buffers 2

#property indicator_color1 White
#property indicator_color2 Red


//---- buffers
double Buffer1[];
double Buffer2[];

// User Input
extern double MovingAvg=23;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|

int init()
  {

   // 233 up arrow
   // 234 down arrow
   // 159 big dot
   // 158 little dot
   // 168 open square
   // 120 box with X
   
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0, Buffer1);
   SetIndexArrow(0,159);  //big dot
   
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1, Buffer2);
   SetIndexArrow(1,159);  //big dot

   return(0);
  }


//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   int i;
   
   for( i=0; i<Bars; i++ ) Buffer1[i]=0;
   for( i=0; i<Bars; i++ ) Buffer2[i]=0;

   return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {
   int      pos=500; // leave room for moving average periods

   double   cMA=0, pMA=0;

   bool     found=false;
   bool    rising=false;
   bool   falling=false;
   bool    bought=false;
   bool      sold=false;
   
   int      cnt=0;
   int      err=0;
   
   // get 1 & 2 MA (avoid 0, as it's too noisy)
   // (possible mod - open of 0 and 1 has no noise)
   cMA=iMA(Symbol(), 0, MovingAvg, 0, MODE_LWMA, PRICE_CLOSE, pos);
   pMA=iMA(Symbol(), 0, MovingAvg, 0, MODE_LWMA, PRICE_CLOSE, pos+1);

   if (pMA<=cMA) {Buffer1[pos]=Low[pos];}
   if (pMA>=cMA) {Buffer2[pos]=High[pos];}

   pos--;

   return(0);
  }
//+------------------------------------------------------------------+

Comments