BB_PRC-1_v1

Download script
Author: Kalenzo
BB_PRC-1_v1

This script is a custom technical analysis tool designed for the MetaTrader platform. It functions by calculating a specific relative position of price within a moving range and then analyzing that position to identify potential trading opportunities through visual signals and automated alerts.

Core Logic and Calculations

The tool operates through a three-step mathematical process:

  1. Relative Range Positioning: The script looks at the current market price in relation to the "Bollinger Bands" (a standard technical indicator that measures volatility). Instead of just looking at the price itself, it calculates where the price sits as a percentage or ratio within those bands. This tells the user how "stretched" the price is relative to its recent history.

  2. Trend Smoothing: Once the relative position is determined, the script applies a Moving Average to that data. This step is crucial because it filters out "market noise"—the small, erratic ups and downs of the market—to reveal a smoother trend of where the price's relative position is heading over time.

  3. Visual Representation: The tool plots two distinct lines on a separate window in your trading platform:

    • The primary line represents the raw relative position of the price.
    • The secondary line represents the smoothed trend of that position.

Alert System and Signal Logic

Beyond just providing visual lines, the script includes an automated logic engine to notify the user of specific market behaviors via pop-up alerts. It monitors for four specific conditions:

  • Relative Lows: It triggers an alert when the price reaches a point significantly low relative to its recent range.
  • Relative Highs: It triggers an alert when the price reaches a point significantly high relative to its recent range.
  • Sell Signals (Crosses): The script monitors for moments when the smoothed trend line crosses above the raw price position, which can indicate a shift in momentum toward the downside.
  • Buy Signals (Crosses): Conversely, it alerts you when the smoothed trend line crosses below the raw price position, indicating a potential upward shift in momentum.

User Experience Features

To ensure the tool is practical for live trading, it includes several "quality of life" features:

  • Alert Frequency Control: It includes a built-in "sleep" timer to prevent the system from spamming multiple alerts for the same price movement, ensuring you only receive one notification per specified interval.
  • Customizable Parameters: Users can adjust the sensitivity of the Bollinger Bands, the length of the Moving Average, and the specific timing of the alerts to suit different trading styles (e.g., scalping vs. long-term investing).
Indicators Used
Bollinger bands indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
16 Views
0 Downloads
0 Favorites
BB_PRC-1_v1
//+------------------------------------------------------------------+
//|                                                       BB_PRC.mq4 |
//|                                                          Kalenzo |
//|                                      bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
#property indicator_color1 Red
#property indicator_color2 Gold
#property indicator_buffers 2

double bol[];
double ma[];
extern int bPer=20,bDev=2,maPer=50,maMeth=MODE_EMA;
extern bool useAlerts=true;
extern int alertBar=1;
extern int alertSleep=1800;//in seconds
int lastAlert;
#property indicator_separate_window

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexBuffer(0,bol);
   SetIndexStyle(0,DRAW_LINE,EMPTY,2);

   SetIndexBuffer(1,ma);
   SetIndexStyle(1,DRAW_LINE,EMPTY,1);

   IndicatorShortName("BB PRC RANGE v1");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) counted_bars=0;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars-bPer;

   for(int i=0; i<=limit;i++)
     {
      double bandL=iBands(Symbol(),0,bPer,bDev,0,PRICE_CLOSE,MODE_MINUSDI,i);
      double bandH=iBands(Symbol(),0,bPer,bDev,0,PRICE_CLOSE,MODE_PLUSDI,i);
      bol[i]=((Close[i]-bandL)/(bandH-bandL));

      if((Close[i]-bandL)==0 || (bandH-bandL)==0)
         Print(i," ",(Close[i]-bandL)," ",(bandH-bandL));
     }

   for(int j=0; j<=limit;j++)
     {
      ma[j]=iMAOnArray(bol,0,maPer,0,maMeth,j);
     }

   if(useAlerts)
     {
      if(ma[alertBar]>=bol[alertBar] && CurTime()>lastAlert && (bol[2+alertBar]>=bol[1+alertBar]) && (bol[1+alertBar] < bol[alertBar]))
        {
         Alert("BB PRC MADE LOW "+ Symbol() + " on the " +  Period() + " minute chart.");
         lastAlert=CurTime()+alertSleep;
        }

      if(ma[alertBar]<=bol[alertBar] && CurTime()>lastAlert && (bol[2+alertBar]<=bol[1+alertBar]) && (bol[1+alertBar] > bol[alertBar]))
        {
         Alert("BB PRC MADE HIGH "+ Symbol() + " on the " +  Period() + " minute chart.");
         lastAlert=CurTime()+alertSleep;
        }

      if(CurTime()>lastAlert && bol[alertBar+1]>=ma[alertBar+1] && bol[alertBar] < ma[alertBar])
        {
         Alert("BB PRC CROSSED MA FOR SELL "+ Symbol() + " on the " +  Period() + " minute chart.");
         lastAlert=CurTime()+alertSleep;
        }

      if(CurTime()>lastAlert && bol[alertBar+1]<=ma[alertBar+1] && bol[alertBar] > ma[alertBar])
        {
         Alert("BB PRC CROSSED MA FOR BUY "+ Symbol() + " on the " +  Period() + " minute chart.");
         lastAlert=CurTime()+alertSleep;
        }
     }

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

Comments