Author: No Copyright, funtrader
Sashken_v2

This technical indicator is designed to help traders identify potential momentum shifts in the market by analyzing the relationship between two different sets of Moving Averages (MA). Rather than looking at just one trend line, it compares "Short-Term" data against "Long-Term" data to detect specific crossing behaviors.

Core Logic Overview

The script operates by calculating four distinct moving average lines simultaneously on your chart. These lines are categorized into two groups:

  • Short-Term Group: Two fast-moving lines that react quickly to recent price fluctuations.
  • Long-Term Group: Two slower-moving lines that represent the broader, established trend of the market.

To increase precision, the script applies "shifts" to these lines. This means it doesn't just look at where the prices are right now; it looks at where they were a few candles back, allowing for a more cushioned and less "noisy" interpretation of price movement.

How It Identifies Signals

The logic focuses on the interaction between these two groups. Instead of simply waiting for one line to cross another, the script looks for a specific dual-condition alignment:

1. Long Opportunities (Potential Buy Interest) The indicator monitors for a situation where the Short-Term average falls below the Long-Term average on one side, while simultaneously rising above it on the other side. When these two conditions align (specifically when the current short-term value is less than the long-term value, but the shifted short-term value is greater), it logs a "Long" signal.

2. Short Opportunities (Potential Sell Interest) Conversely, the script looks for the opposite behavior to identify downward pressure. If the Short-Term average rises above the Long-Term average on one side while falling below it on the other, it logs a "Short" signal.

Key Features for the User

  • Multi-Layered Analysis: By using four different lines instead of two, the indicator filters out minor market "jitters," aiming to capture more significant trend reversals.
  • Automated Logging: Every time the specific logic requirements are met, the script automatically records the event in the system log, including the exact timestamp, the currency pair being traded, and the opening price at that moment.
  • Customizable Parameters: You can adjust the length of the periods (how many candles to look back), the calculation method (e.g., Simple vs. Smoothed averages), and the "shift" offsets to fine-tune how sensitive or responsive the indicator is to market changes.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
4 Views
1 Downloads
0 Favorites
Sashken_v2
//+------------------------------------------------------------------+
//|                                            sashken_indicator.mq4 |
//|                                          No Copyright, funtrader |
//+------------------------------------------------------------------+
#property copyright "No Copyright, funtrader"
#property link      "http://championship.mql4.com"
 
//
// Indicatorsettings
//
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Yellow
//
// Buffer
//
double bufferMA1[];
double bufferMA2[];
double bufferMA3[];
double bufferMA4[];
//
// Parameter
//
// MA-Properties
extern int       shortMAPeriod  = 7;
extern int       shortMAMethod  = MODE_SMMA;
extern int       shortMAValue   = PRICE_CLOSE;
 
extern int       longMAPeriod   = 20;
extern int       longMAMethod   = MODE_SMA;
extern int       longMAValue    = PRICE_OPEN;
 
extern int       maShift1       = 1;
extern int       maShift2       = 2;
extern int       maOffset       = 0;
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
 
    SetIndexStyle(  0, DRAW_LINE );
    SetIndexBuffer( 0, bufferMA1 );
    SetIndexStyle(  1, DRAW_LINE );
    SetIndexBuffer( 1, bufferMA2 );
    SetIndexStyle(  2, DRAW_LINE );
    SetIndexBuffer( 2, bufferMA3 );
    SetIndexStyle(  3, DRAW_LINE );
    SetIndexBuffer( 3, bufferMA4 );
 
    Print( "ServerTime: ", TimeToStr( CurTime(),TIME_DATE|TIME_SECONDS ), ", LocalTime: ", TimeToStr( LocalTime(),TIME_DATE|TIME_SECONDS ) );
    return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
 
    int countedBars = IndicatorCounted();
 
    //---- check for possible errors
    if  ( countedBars < 0 ) {
        return(-1);
    }
    //---- the last counted bar will be recounted
    if  ( countedBars > 0 ) {
        countedBars--;
    }
    
    int    barsToCount = Bars - countedBars;
    double MA1, MA2, MA3, MA4;
 
    for ( int i = barsToCount; i >= 0; i-- ) {
 
                
        MA1          = iMA( NULL, 0, shortMAPeriod, maOffset, shortMAMethod, shortMAValue, i + maShift1 );
        MA2          = iMA( NULL, 0, shortMAPeriod, maOffset, shortMAMethod, shortMAValue, i + maShift2 );
        MA3          = iMA( NULL, 0, longMAPeriod,  maOffset, longMAMethod,  longMAValue,  i + maShift1 );
        MA4          = iMA( NULL, 0, longMAPeriod,  maOffset, longMAMethod,  longMAValue,  i + maShift2 );
        bufferMA1[i] = MA1;
        bufferMA2[i] = MA2;
        bufferMA3[i] = MA3;
        bufferMA4[i] = MA4;
        
        if  ( MA1 < MA3 && MA2 > MA4 ) {
            Print("Long. ", TimeToStr( Time[i], TIME_DATE|TIME_SECONDS ), " - ", Symbol(), ", Open: ", Open[i] );
        }
        if  ( MA1 > MA3 && MA2 < MA4) {
            Print("Short. ",TimeToStr( Time[i], TIME_DATE|TIME_SECONDS ), " - ", Symbol(), ", Open: ", Open[i] );
        }
    }
    
    return(0);
}
//+------------------------------------------------------------------+

Comments