LSwpr_in_Color_mtf

Download script
LSwpr_in_Color_mtf

This script is a custom technical analysis tool designed for the MetaTrader platform. It combines two distinct financial indicators—the Linear Weighted Moving Average (LWMA) and the Williams %R (WPR)—to create a visual representation of market momentum and price trends.

Core Logic Overview

The primary purpose of this script is to calculate a weighted value based on the Williams %R indicator, which measures overbought and oversoldcanc conditions. Unlike a standard calculation, this script applies a "Linear Weighting" logic to those values. This means it gives more importance to recent price action than to older data, allowing the resulting line to react more fluidly to current market shifts.

Key Features and Functionalities

1. Multi-Timeframe Analysis One of the most sophisticated aspects of this script is its ability to "look" at different timeframes simultaneously. It can pull data from higher timeframes (such as Daily or Weekly charts) and project that information onto your current view. This helps traders identify the broader market trend without having to constantly switch back and forth between different screens.

2. Dynamic Color Coding The script uses a multi-colored buffer system to provide immediate visual cues regarding price direction:

  • It tracks the movement of the calculated weighted value.
  • By comparing the current value to the previous one, the script identifies whether the momentum is pushing upward or downward.
  • It manages three different color buffers (Yellow, Chartreuse, and Red) to highlight these transitions, helping users distinguish between bullish and bearish shifts at a glance.

3. Weighted Smoothing The script performs a mathematical loop to calculate a "sum" of the Williams %R values over a specific period. It then applies a weight formula to ensure the final output is balanced. This smoothing process helps filter out "market noise"—the small, erratic price fluctuations that can often trigger false signals—leaving a cleaner line that represents the underlying trend.

Summary for the User

Essentially, this tool acts as a sophisticated momentum tracker. It takes the raw data of where prices are currently sitting (Williams %R), weights it based on how recently those prices occurred (LWMA), and projects that information from higher timeframes onto your chart. The color-changing logic then serves as an alert system, highlighting when the momentum is shifting in a specific direction.

Indicators Used
Larry William percent range indicator
Miscellaneous
Implements a curve of type %1It opens Message Boxes to the user
14 Views
0 Downloads
0 Favorites
LSwpr_in_Color_mtf
//+------------------------------------------------------------------+
//|                                                  LSMA_in_color3  |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
//lsmawpr  Perky
//mtf2009fxtsd   ki
#property  copyright "Copyright © 2005, FX Sniper "
#property  link      "http://www.metaquotes.net/"

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property indicator_color1 Yellow      
#property indicator_color2 Chartreuse
#property indicator_color3 Red
#property indicator_width1  2
#property indicator_width2  2
#property indicator_width3  2
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
int width;



extern int Rperiod = 14;
extern int Draw4HowLongg = 900;  // 500 // 1000
extern int TimeFrame     = 0;
extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";


int Draw4HowLong;
int shift;
int i;
int loopbegin;
double sum[];
int length;
double lengthvar;
double tmp ;
double wt[];
int c;
string IndicatorFileName;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(5);
   
//---- drawing settings
   SetIndexBuffer(2,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(0,ExtMapBuffer3);
   SetIndexBuffer(3,sum);
   SetIndexBuffer(4,wt);
   
   SetIndexStyle(2,DRAW_LINE);  
   SetIndexStyle(1,DRAW_LINE);  
   SetIndexStyle(0,DRAW_LINE);  
   
   TimeFrame=MathMax(TimeFrame,Period());
   
   string shortname = "("+Rperiod+") ["+TimeFrame+"]  ";
   
   IndicatorShortName("LS WPR "+shortname);  
   SetIndexLabel(0,"");
   SetIndexLabel(1,"");
   SetIndexLabel(2,"ls/wpr "+shortname);


   IndicatorFileName = WindowExpertName();
//---- initialization done
   return(0);
  }

int start()

  {   Draw4HowLong = 1000-Rperiod - 5;
      length = Rperiod;
      loopbegin = Draw4HowLong - length - 1;
      
 
       if (TimeFrame != Period())
       {
         loopbegin = MathMax(loopbegin,TimeFrame/Period());
            
            for(i=loopbegin; i>=0; i--)
            {
            int y = iBarShift(NULL,TimeFrame,Time[i]);
            
       ExtMapBuffer1[i] = iCustom(NULL,TimeFrame,IndicatorFileName,Rperiod,Draw4HowLongg,2,y); 
       ExtMapBuffer2[i] = iCustom(NULL,TimeFrame,IndicatorFileName,Rperiod,Draw4HowLongg,1,y); 
       ExtMapBuffer3[i] = iCustom(NULL,TimeFrame,IndicatorFileName,Rperiod,Draw4HowLongg,0,y); 
      
            }
        return(0);         
       }
      
      for(shift = loopbegin; shift >= 0; shift--)
      { 
        
         sum[1] = 0;
         for(i = length; i >= 1  ; i--)
         {

         lengthvar = length + 1;
         lengthvar /= 3;
         tmp = 0;
         tmp = ( i - lengthvar)*iWPR(NULL,0,Rperiod,length-i+shift);
         
 
         
         sum[1]+=tmp;
         }
        
         wt[shift] = sum[1]*6/(length*(length+1));
        
       // wt[]=wt1[y]; 
//========== COLOR CODING ===========================================               
        
       ExtMapBuffer3[shift] = wt[shift]; //red 
       ExtMapBuffer2[shift] = wt[shift]; //green
       ExtMapBuffer1[shift] = wt[shift]; //yellow
       
       //  for(c=loopbegin;c==shift;c++)
       // {
        if (wt[shift+1] > wt[shift])
        {
        ExtMapBuffer2[shift+1] = EMPTY_VALUE;
  // ObjectCreate("smiley_face", OBJ_ARROW, 0, Time[shift], Low[shift]-Point*20);
  // Print("time=  ",Time[shift]);
  // ObjectSet("smiley_face", OBJPROP_ARROWCODE, 242);
  // ObjectSet("smiley_face", OBJPROP_COLOR , Red);
  // ObjectSet("smiley_face", OBJPROP_WIDTH  , 1);
  // ObjectsRedraw();

        //ExtMapBuffer3[shift+1] = EMPTY_VALUE;
        //ExtMapBuffer3[shift+1] = EMPTY_VALUE;
        
        }
       else if (wt[shift+1] < wt[shift]) 
        {
        ExtMapBuffer1[shift+1] = EMPTY_VALUE; //-1 red/greem tight
        MessageBox("asda");
        
       //ExtMapBuffer3[shift+1] = EMPTY_VALUE;
        
        }
         else 
         {
         
         ExtMapBuffer1[shift+1]=CLR_NONE;//EMPTY_VALUE;
         ExtMapBuffer2[shift+1]=CLR_NONE;//EMPTY_VALUE;
         }
        
      }
    
      return(0);
  }
//+------------------------------------------------------------------+



Comments