BBStopLightv2

Download script
Author: BBStopLight
BBStopLightv2

This technical indicator, designed for the MetaTrader platform, functions as a visual "Stoplight" system. Its primary purpose is to analyze market volatility and momentum to provide traders with clear signals on when it is optimal to enter a trade and when the market conditions are unfavorable.

Core Logic and Mechanism

The script operates by calculating the relationship between price movement and historical averages. It focuses on three main components:

  • Volatility Measurement: The tool calculates the "Standard Deviation," which measures how much the price is fluctuating relative to its average price over a specific period. By comparing this fluctuation to the moving average, the script determines the "width" or intensity of the current market movement.
  • Trend Analysis: It evaluates whether the expansion of this volatility is increasing, decreasing, or remaining stagnant. This helps distinguish between active trending markets and exhausted movements.
  • Dynamic Scaling: The indicator uses a multiplier to project these values into a readable format in a separate window, allowing for easier visual interpretation of the data.

The "Stoplight" Visual System

The indicator translates complex mathematical calculations into three distinct visual states (represented by different colors) to act as a traffic light for trading:

  1. Trading Allowed (The Green Light): When the volatility metric is rising, the script identifies this as an active trend or increasing momentum. This signals that market conditions are favorable for taking positions.
  2. Run is Over / No Trading (The Yellow Light): When the volatility metric begins to decline, the indicator suggests that the current move is losing steam. This serves as a warning that the "run" may be ending and it might be a risky time to enter a new trade.
  3. No Trading Allowed (The Red Light): If specific negative conditions are met in the calculation, the indicator signals a complete lack of favorable conditions, advising the user to stay out of the market entirely.

Summary for Traders

Instead of forcing you to interpret raw numbers or complex charts, this script automates the analysis of price "expansion." It tells you whether the market is currently gaining strength (safe to trade), losing power (caution), or lacking direction (stay out). It simplifies your decision-making process by highlighting the momentum of the market in real-time.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
BBStopLightv2
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                              BBStopLight.mq4     |
//|                           based on BBandWidthRatio.mq4 from Maji |
//|                                -- adapted by Gideon, August 2006 |
//| August 31, 2006 Robert Hill Fixed CPU usage problem              |
//+------------------------------------------------------------------+
#property copyright "BBStopLight"
#property link      "gideon@smolders.biz"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 SlateGray
#property indicator_color2 DarkOrange // trading allowed
#property indicator_color3 Pink // run is over, no trading
#property indicator_color4 Black // no trading allowed


//---- input parameters
extern int       BB_Period=20;
extern double    Deviation=2.0;
extern double    Multiply=2000;
extern double    Zeroline=3;

double buf1[];
double buf2[];
double buf3[];
double buf4[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0, DRAW_NONE, 1, 2);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
   SetIndexDrawBegin(0,BB_Period);
   SetIndexLabel(0,"BBandWidthRatio");
   SetIndexBuffer(0, buf1);
   
   SetIndexStyle(1, DRAW_HISTOGRAM, 1, 2);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
   SetIndexDrawBegin(1,BB_Period);
   SetIndexLabel(1,"BBandWidthRatio");
   SetIndexBuffer(1, buf2);
   
   SetIndexStyle(2, DRAW_HISTOGRAM, 1, 2);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
   SetIndexDrawBegin(2,BB_Period);
   SetIndexLabel(2,"BBandWidthRatio");
   SetIndexBuffer(2, buf3);
   
   SetIndexStyle(3, DRAW_HISTOGRAM, 1, 2);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
   SetIndexDrawBegin(3,BB_Period);
   SetIndexLabel(3,"BBandWidthRatio");
   SetIndexBuffer(3, buf4);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i, j, Limit;
   double ave, sko, sum;
   int counted_bars=IndicatorCounted();
   double MA, Up, Dn;
   
   if(Bars<=BB_Period) return(0);
      
   if(counted_bars>0) counted_bars--;
   Limit=Bars-counted_bars-BB_Period;
   
   for (i=Limit; i>=0; i--) 
   {
    
    MA = iMA(NULL,0,BB_Period,0,MODE_LWMA,PRICE_OPEN,i);
    sum = 0;
    for (j=0; j<BB_Period; j++) sum+=Close[i+j];
    ave = sum / BB_Period;
    sum = 0;
    for (j=0; j<BB_Period; j++) sum+=(Close[i+j]-ave)*(Close[i+j]-ave);
    sko = MathSqrt(sum / BB_Period);

    Up = MA+(Deviation*sko);
    Dn = MA-(Deviation*sko);
    
    buf1[i] = (Multiply*(Deviation*sko)/MA);
    
    if (buf1[i]>0 && buf1[i]>buf1[i+1]) {
    buf2[i] = buf1[i];
    buf3[i] = 0;
    buf4[i] = 0;
    }
    if (buf1[i]>0 && buf1[i]<buf1[i+1]) {
    buf2[i] = 0;
    buf3[i] = buf1[i];
    buf4[i] = 0;
    }
    if (buf1[i]<0) {
    buf2[i] = 0;
    buf3[i] = 0;
    buf4[i] = buf1[i];
    }
  
   }
  
    return(0);
  
  }
//+------------------------------------------------------------------+

Comments