$_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 );
}

    



Sample





Analysis



Market Information Used:

Series array that contains close prices for each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: