$_MT4-Psychological

Author: Copyright � 2007, Bruce Hellstrom (brucehvn)
$_MT4-Psychological

The Psychological Indicator is a specialized technical analysis tool designed to measure market momentum by analyzing the frequency of price movement over a specific timeframe. Rather than simply looking at how much the price has moved (the magnitude), this tool focuses on "sentiment"—specifically, how often the price moves in a positive direction compared to a negative one.

Core Logic and Functionality

The indicator operates by scanning a designated "lookback period" (defaulting to 25 bars) to determine the prevailing trend of the market. It performs a bar-by-bar count to establish a percentage score based on the following logic:

  • Upward Momentum Tracking: The script examines each candle within the lookback window. If a candle's closing price is higher than the previous candle's closing price, it registers as an upward move.
  • Trend Weighting: It takes into account the immediate history of the current price action and compares it against the historical boundary of the lookback period to ensure the calculation remains fluid as new data enters the chart.
  • Percentage Calculation: Once the count of upward movements is established, the script converts this number into a percentage. This result is plotted on a separate window, creating a visual "momentum score."

Visual Interpretation

The tool provides a clear visual representation of market sentiment through a dedicated line graph:

  • The 50% Mid-Line: This serves as the neutral equilibrium. When the indicator is above 50, it suggests that, mathematically, more price closes have been higher than lower within the selected period (bullish sentiment). When below 50, it suggests a higher frequency of downward closes (bearish sentiment).
  • Extreme Zones: The indicator features designated levels at 25% and 75%. These represent high-conviction zones. Values near these extremes indicate very strong, consistent price movement in one specific direction, while values hovering near the middle suggest a choppy or undecided market.

Key Features for Users

  • Timeframe Awareness: The tool automatically detects which timeframe you are currently viewing (e.g., M15, H1, D1) and updates its name and labels accordingly to ensure clarity on the chart.
  • Customizable Sensitivity: By adjusting the "PsychPeriod" input, users can change how many bars of history the indicator considers. A smaller period makes the tool more reactive to immediate price changes, while a larger period smooths out the data to show broader market trends.
Price Data Components
Series array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
$_MT4-Psychological
//+------------------------------------------------------------------+ 
//|   $_MT4-Psychological                                            | 
//|   Modified by, Avery T. Horton, Jr. aka TheRumpledOne            |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|                                                                  |
//|   therumpldone@gmail.com                                         |  
//+------------------------------------------------------------------+ 



/////////////////////////////////////////////////////////////////////
// Psychological Indicator (Ported from FXAccucharts)
// Version 1.0
// Copyright © 2007, Bruce Hellstrom (brucehvn)
// bhweb@speakeasy.net
// http://www.metaquotes.net
/////////////////////////////////////////////////////////////////////

/*

    This indicator is ported from the FXAccuCharts platform to MT4.  The formula
    used here has been tested on FXAccuCharts to insure it displays the same as
    their default psychological indicator.
    
    Input Parameters:
    PsychPeriod - Lookback periods for the indicator (25 default)
    
    
    Revision History
    Version 1.0
    * Initial Revision
    
*/    


#property copyright "Copyright © 2007, Bruce Hellstrom (brucehvn)"
#property link      "http: //www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#property indicator_style1 STYLE_SOLID

#property indicator_level1 50.0
#property indicator_level2 75.0
#property indicator_level3 25.0
#property indicator_levelcolor Silver
#property indicator_levelwidth 1
#property indicator_levelstyle STYLE_DOT

#define INDICATOR_VERSION "v1.0"


// Input Parameters
extern int PsychPeriod = 25;

extern int myPeriod = 0;

// Buffers
double PsychBuffer[];

// Other Variables
string ShortName;
int CountBuf[];

int xPeriod ;

//+------------------------------------------------------------------+

string TimeFrameToString(int tf)
{
   string tfs;
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN1";
   }
   return(tfs);
}

//+------------------------------------------------------------------+


/////////////////////////////////////////////////////////////////////
// Custom indicator initialization function
/////////////////////////////////////////////////////////////////////

int init() {

    IndicatorBuffers( 1 );
    SetIndexStyle( 0, DRAW_LINE, STYLE_SOLID, 1 );
    SetIndexBuffer( 0, PsychBuffer );
    SetIndexDrawBegin( 0, PsychPeriod );
    
    ArraySetAsSeries( CountBuf, true );
  
    if(myPeriod == 0) {xPeriod = Period();} else { xPeriod = myPeriod ; }   
    string tPeriod   = TimeFrameToString(xPeriod) ;
    
    ShortName = tPeriod +" Psychological-" + INDICATOR_VERSION + "(" + PsychPeriod + ")";
    
    IndicatorShortName( ShortName );
    SetIndexLabel( 0, ShortName );
    
    Print( ShortName );
    Print( "Copyright (c) 2007 - Bruce Hellstrom, bhweb@speakeasy.net" );
    
    
    return( 0 );
}

/////////////////////////////////////////////////////////////////////
// Custom indicator deinitialization function
/////////////////////////////////////////////////////////////////////

int deinit() {
    return( 0 );
}

/////////////////////////////////////////////////////////////////////
// Indicator Logic run on every tick
/////////////////////////////////////////////////////////////////////

int start() {
    
    int counted_bars = IndicatorCounted();
    
    // Check for errors
    if ( counted_bars < 0 ) {
        return( -1 );
    }

    // Last bar will be recounted
    if ( counted_bars > 0 ) {
        counted_bars--;
    }
    
    // Resize the non-buffer array if necessary
    if ( ArraySize( CountBuf ) != ArraySize( PsychBuffer ) ) {
        ArraySetAsSeries( CountBuf, false );
        ArrayResize( CountBuf, ArraySize( PsychBuffer ) );
        ArraySetAsSeries( CountBuf, true );
    }
    

    // Get the upper limit
    int limit = Bars - counted_bars;
    
    for ( int ictr = 0; ictr < limit; ictr++ ) {
        int Count = 0;
        int endctr = ictr + 1 + PsychPeriod;
        
        for ( int jctr = ictr + 1; jctr < endctr; jctr++ ) {
            if ( iClose(NULL,xPeriod,jctr ) > iClose(NULL,xPeriod,jctr + 1 )) {
                Count++;
            }
        }

        if ( iClose(NULL,xPeriod,ictr) > iClose(NULL,xPeriod,ictr + 1) ) {
            Count++;
        }
                
        if ( iClose(NULL,xPeriod,ictr + PsychPeriod) >iClose(NULL,xPeriod,ictr + PsychPeriod + 1) ) {
            Count--;
        }

        double dCount = Count;
        PsychBuffer[ictr] = ( dCount / PsychPeriod ) * 100.0;
    }
            
    return( 0 );
}

    

Comments