StochTxt(komposter)2007

Download script
Author: Copyright � 2007, komposter
StochTxt(komposter)2007

This script is a custom technical analysis tool designed for the MetaTrader platform to identify potential entry points in the financial markets. It operates by analyzing price momentum and visualizing specific trading signals directly on your chart using visual markers and optional alerts.

Core Logic and Functionality

Momentum Tracking The primary engine behind this tool is the "Stochastic Oscillator." This mathematical formula measures where the current price sits relative to its recent price range. Essentially, it helps traders determine if a market is "overbought" (trading at the top of its range) or "oversold" (trading at the bottom).

Signal Identification The script looks for specific "crossover" moments to trigger signals:

  • Buy Signals: The tool identifies when the momentum indicator moves from an oversold state back upward. It marks these points on the chart with a visual arrow.
  • Sell Signals: The tool identifies when the momentum indicator moves from an overbought state back downward. These are marked with a different visual arrow to distinguish them from buys.

Dynamic Visual Placement To ensure the markers are easy to read, the script uses an "Average True Range" calculation. This allows the tool to automatically adjust the distance of the arrows and text labels based on how volatile the market is. In a high-volatility environment, the markers stay out of the way; in a calm market, they sit closer to the price action.

Customizable Notifications The script includes three main features for the user experience:

  1. Visual Arrows: Direct indicators placed on the chart to highlight where the momentum shift occurred.
  2. Text Labels: An optional feature that creates text tags on the chart, displaying the closing price and the exact time of the signal.
  3. Real-time Alerts: If enabled, the script will trigger a pop-up notification on your screen the moment a new Buy or Sell signal is detected, allowing for immediate attention without constantly watching the screen.

Summary for the User

This tool serves as a "momentum filter." Instead of you having to manually watch every wiggle in the price chart, the script monitors the mathematical trends for you. It highlights the moments where the market shows signs of exhaustion—either being pushed too high or falling too low—and provides a clear visual cue (arrows and text) along with an optional alarm to notify you of these transitions.

Indicators Used
Stochastic oscillatorIndicator of the average true range
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
14 Views
0 Downloads
0 Favorites
StochTxt(komposter)2007
//+------------------------------------------------------------------+
//|                                     iStochTxt(komposter)2007.mq4 |
//|                                      Copyright © 2007, komposter |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, komposter"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//----
extern int        k                = 5;
extern int        s                = 3;
extern double    up_l            = 80;
extern double    dn_l            = 20;
extern bool        text            = false;
extern color    text_color    = Yellow;
extern bool        alert            = false;
//----
double BuyBuffer[], SellBuffer[];
int pre_signal = 0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
      IndicatorShortName("iStochTxt");
//----
      SetIndexBuffer(0, BuyBuffer);
      SetIndexLabel(0, "Buy");
      SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 1);
      SetIndexArrow(0, 241);
//----
      SetIndexBuffer(1, SellBuffer);
      SetIndexLabel(1, "Sell");
      SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1);
      SetIndexArrow(1, 242);
//----
      return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
      if(text)
        {
             for(int i = 0; i < ObjectsTotal(); i++)
               {
                    if(StringFind( ObjectName(i), "txt_", 0 ) == 0)
                      {
                           ObjectDelete(ObjectName(i));
                           i--;
                      }
               }
        }
      return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
      int counted_bars = IndicatorCounted();
//----
      if(counted_bars < 0) 
        { 
          Print("Indicator Error (Counted bars < 0)!"); 
          return(-1); 
        }
//----
      if(Bars < 17) 
        { 
          Print("Indicator Error (Bars < 12)!" ); 
          return(-1); 
        }
   int limit = Bars - 17;
//----
   if(counted_bars > 17) 
     { 
       limit = Bars - counted_bars; 
     }
//----
      for(int i = limit; i >= 0; i --)
        {
             BuyBuffer[i] = EMPTY_VALUE;
             SellBuffer[i] = EMPTY_VALUE;      
             //----
                double mc = iStochastic(NULL, 0, k, 3, s, 0, 0, MODE_MAIN, i);
                 double mp = iStochastic(NULL, 0, k, 3, s, 0, 0, MODE_MAIN, i+1);
             //----
           if(mc > dn_l && mp <= dn_l)
               {
                    BuyBuffer[i] = Low[i] - iATR(NULL, 0, 14, i);
                    if(text) 
                      { 
                        create_text(i, Low[i] - 1.5*iATR(NULL, 0, 14, i )); 
                      }
               }
             if(mc < up_l && mp >= up_l)
               {
                    SellBuffer[i] = High[i] + iATR(NULL, 0, 14, i);         
                    if(text) 
                      { 
                        create_text(i, High[i] + 1.5*iATR( NULL, 0, 14, i)); 
                      }
               }
        }
      if(alert)
        {
             if(pre_signal <= 0 && BuyBuffer [1] != EMPTY_VALUE) 
               { 
                 Alert("iStochTxt( ", Symbol(), ", ", Period(), " ) - BUY!"); 
                 pre_signal =  1; 
               }
             if(pre_signal >= 0 && SellBuffer[1] != EMPTY_VALUE) 
               { 
                 Alert("iStochTxt( ", Symbol(), ", ", Period(), " ) - SELL!"); 
                 pre_signal = -1; 
               }
        }
      return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void create_text(int u, double p)
  {
      string name = "txt_" + Time[u];
      ObjectDelete(name);
      ObjectCreate(name, OBJ_TEXT, 0, Time[u], p);
      ObjectSetText(name, DoubleToStr( Close[u], Digits ) + " " + TimeToStr( Time[u], 
                    TIME_MINUTES), 8, "Arial", text_color);
  }
//+------------------------------------------------------------------+

Comments