Stochastic_Cross_Levels(AM)

Download script
Author: Andrey Matvievskiy
Stochastic_Cross_Levels(AM)

This script is a technical analysis tool designed to identify specific momentum shifts and price action signals on a trading chart. It uses a variety of mathematical conditions to "read" the market's behavior and place visual markers (arrows) on the screen to alert the user to potential trend changes or overextended price movements.

The logic operates based on three distinct types of signals:

1. Momentum Crossovers

The script first monitors two specific moving average lines within a Stochastic Oscillator (a common momentum indicator). It looks for "crossovers," which occur when one line crosses over the other.

  • Buy Signals: Triggered when the fast-moving line climbs above the slow-moving signal line.
  • Sell Signals: Triggered when the fast-moving line drops below the slow-moving signal line.

2. Specific Level Breaches

The indicator is programmed to watch for the momentum reaching three specific "threshold" levels (set at 80, 50, and 20). Instead of just looking at where the lines cross each other, it looks for moments when the price momentum breaks through these significant psychological barriers.

  • When the momentum moves from below a level to above it (e.g., breaking out of a "low" zone), it generates an upward signal.
  • When the momentum drops from above a level to below it (e.g., falling out of a "high" zone), it generates a downward signal.

3. Trend Reversals (V-Shape/Inverted V-Shape)

The final layer of logic looks for "turning points." Rather than just comparing two lines, it compares three consecutive data points in the momentum stream. It is searching for a specific pattern where the price moves forward and then immediately reverses direction (forming a "hook" or a "V" shape). This helps identify areas where the momentum has exhausted itself and is beginning to pivot back in the opposite direction.

Visual Presentation

To make this information easy for a trader to read at a glance, the script automatically calculates the "Range" of the current market volatility. It then places the arrows at a specific distance from the price candles based on that volatility. This ensures that whether the market is moving slowly or swinging wildly, the markers remain clearly visible and do not overlap with the price bars.

Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
4 Views
0 Downloads
0 Favorites
Stochastic_Cross_Levels(AM)

//+------------------------------------------------------------------+
//|                                  Stochastic_Cross_Levels(AM).mq4 |
//|                                               Andrey Matvievskiy |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Andrey Matvievskiy"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Aqua
#property indicator_color2 Aqua
#property indicator_color3 Silver
#property indicator_color4 Silver
#property indicator_color5 Orange
#property indicator_color6 Orange

//---- input parameters
extern int KPeriod=5;
extern int DPeriod=3;
extern int Slowing=3;
extern int MA_Method = 0; // SMA 0, EMA 1, SMMA 2, LWMA 3
extern int PriceField = 0; // Low/High 0, Close/Close 1

extern int L_1=  80;
extern int L_2=  50;
extern int L_3=  20;


extern int CountedBars = 30;

double CrossUp1[];
double CrossDown1[];
double CrossUp2[];
double CrossDown2[];
double CrossUp3[];
double CrossDown3[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp1);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown1);
   
   SetIndexStyle(2, DRAW_ARROW, EMPTY);
   SetIndexArrow(2, 233);
   SetIndexBuffer(2, CrossUp2);
   SetIndexStyle(3, DRAW_ARROW, EMPTY);
   SetIndexArrow(3, 234);
   SetIndexBuffer(3, CrossDown2);
   
   SetIndexStyle(4, DRAW_ARROW, EMPTY);
   SetIndexArrow(4, 233);
   SetIndexBuffer(4, CrossUp3);
   SetIndexStyle(5, DRAW_ARROW, EMPTY);
   SetIndexArrow(5, 234);
   SetIndexBuffer(5, CrossDown3);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

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


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double tmp=0;
   double fastMAnow, slowMAnow, fastMAprevious, slowMAprevious, fastMAprevious2;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=CountedBars;
   
   for(i = 1; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
       
      fastMAnow = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i);
      fastMAprevious = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i+1);
      fastMAprevious2 = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i+2);

      slowMAnow = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_SIGNAL, i);
      slowMAprevious = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_SIGNAL, i+1);
      
      CrossUp1[i] = 0;
      CrossDown1[i] = 0;
      CrossUp2[i] = 0;
      CrossDown2[i] = 0;
      CrossUp3[i] = 0;
      CrossDown3[i] = 0;
      
      
      if ((fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious))
      {
         CrossUp1[i] = Low[i] - Range*0.4;
      }
      else if ((fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious))
      {
         CrossDown1[i] = High[i] + Range*0.4;        
      }
     
                              
      if ((fastMAnow > L_1) && (fastMAprevious < L_1))
      {
         CrossUp2[i] = Low[i] - Range*0.2;
      }
      else if ((fastMAnow < L_1) && (fastMAprevious > L_1))
      {
         CrossDown2[i] = High[i] + Range*0.2;
      }
     
     
     
      if ((fastMAnow > L_2) && (fastMAprevious < L_2))
      {
         CrossUp2[i] = Low[i] - Range*0.2;
      }
      else if ((fastMAnow < L_2) && (fastMAprevious > L_2))
      {
         CrossDown2[i] = High[i] + Range*0.2;
      }
      
      
      
      if ((fastMAnow > L_3) && (fastMAprevious < L_3))
      {
         CrossUp2[i] = Low[i] - Range*0.2;
      }
      else if ((fastMAnow < L_3) && (fastMAprevious > L_3))
      {
         CrossDown2[i] = High[i] + Range*0.2;
      }
    
      
      if ((fastMAprevious2 > fastMAprevious) && (fastMAprevious < fastMAnow))
      {
         CrossUp3[i] = Low[i] - Range*0.6;
      }
      else if ((fastMAprevious2 < fastMAprevious) && (fastMAprevious > fastMAnow))    
      {
         CrossDown3[i] = High[i] + Range*0.6;        
      }
             
          
}
   return(0);
}

Comments