Author:
iStochTxt

This tool is designed to help traders identify specific momentum shifts in the market by using a combination of a Stochastic Oscillator and price volatility measurements. Its primary purpose is to visually flag "oversold" and "overbought" conditions directly on your trading chart with clear text labels.

How the Logic Works

The script continuously monitors the price action and applies the following logic to determine where to place markers:

1. Momentum Tracking The tool uses a Stochastic Oscillator (a standard momentum indicator) to measure whether the current price is moving significantly higher or lower relative to its recent historical range. It looks at the "Main" line of this oscillator to detect when the market reaches extremes.

2. Identifying Buy and Sell Signals Instead of just showing a general trend, the script looks for specific "crosses" in momentum:

  • The Lower Threshold: The tool watches for moments where the momentum indicator rises above a specific lower limit (defined by the user). When this happens, it suggests a potential upward move.
  • The Upper Threshold: Conversely, it watches for moments when the momentum indicator drops below a specific upper limit. This identifies points where the market might be reaching a peak and could face a downward turn.

3. Visual Mapping and Labeling When these specific conditions are met, the script automatically performs several actions on your chart:

  • Dynamic Positioning: It uses an Average True Range (ATR) calculation to determine how much "breathing room" there is in the current market volatility. This ensures that the labels aren't placed directly on top of the price candles but are offset slightly above or below them based on how volatile the market is at that moment.
  • Automated Text Labels: The script generates a text label for each occurrence. These labels display two pieces of information: the closing price of that specific candle and the exact time it occurred.
  • Clean Chart Management: The tool is programmed to automatically manage its own objects. It ensures that labels are correctly placed based on the specific timestamp of the candle, preventing visual clutter or duplicate entries as the chart updates.

Summary for the User

In simple terms, this script acts as a "signal scout." It scans the history of your chart to find moments where momentum suggests the market is overextended. When it finds these moments, it leaves a breadcrumb (a text label) showing you exactly what the price was and when it happened, helping you spot potential turning points in the market trend more efficiently.

Indicators Used
Stochastic oscillatorIndicator of the average true range
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
iStochTxt
//+------------------------------------------------------------------+
//|                                                    iStochTxt.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//----
extern int k = 5, s = 3, l = 20;
extern color txtColor = Brown;
//----
int d=3;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 1);
   SetIndexArrow(0, 241);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexEmptyValue(0, 0.0);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1);
   SetIndexArrow(1, 242);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexEmptyValue(1, 0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int i = 0; i < ObjectsTotal(); i++)
     {
       if(StringFind(ObjectName(i), "txt_", 0) == 0)
         {
           ObjectDelete(ObjectName(i));
           i--;
         }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   string on;
   int limit;
	  int counted_bars = IndicatorCounted(); // îïðåäåëèì êîëè÷åñòâî ïðîñ÷èòàíûõ áàðîâ ó èíäèêàòîðà
	  if(counted_bars > 0)
	    {
	      counted_bars--;
	    }	
	  limit = Bars - counted_bars; // îïðåäåëÿåì ãðàíèöó äî êîòîðîé ðàññ÷èòûâàåì çíà÷åíèÿ èíäèêàòîðà
//----
	  for(int i = 0; i < limit; i++)
	    {
       double mc = iStochastic(NULL, 0, k, d, s, 0, 0, MODE_MAIN, i);
       double mp = iStochastic(NULL, 0, k, d, s, 0, 0, MODE_MAIN, i + 1);
       //----
       ExtMapBuffer1[i] = EMPTY_VALUE;
       ExtMapBuffer2[i] = EMPTY_VALUE;      
       //----
       if(mc > l && mp <= l)
         {
           ExtMapBuffer1[i] = Low[i] - iATR(NULL, 0, 14, i);
           on = "txt_" + Time[i];
           ObjectDelete(on);
           ObjectCreate(on, OBJ_TEXT, 0, Time[i], Low[i] - 1.5*iATR(NULL, 0, 14, i));
           ObjectSetText(on, DoubleToStr(Close[i], Digits) + " " + TimeToStr(Time[i], 
                         TIME_MINUTES), 8, "Arial", txtColor);
         }
       if(mc < 100 - l && mp >= 100 - l)
         {
           ExtMapBuffer2[i] = High[i] + iATR(NULL, 0, 14, i);         
           on = "txt_" + Time[i];
           ObjectDelete(on);
           ObjectCreate(on, OBJ_TEXT, 0, Time[i], High[i] + 2*iATR(NULL, 0, 14, i));
           ObjectSetText(on, DoubleToStr(Close[i], Digits) + " " + TimeToStr(Time[i], 
                         TIME_MINUTES), 8, "Arial", txtColor);
         }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments