BT2Stop_v1

The BrainTrend1Stop is a technical analysis tool designed to help traders visualize market trends and identify potential reversal points by monitoring price action relative to historical volatility. Instead of providing a simple moving average, this script calculates a dynamic "buffer zone" around the price to determine when a trend has officially shifted from bullish (upward) to bearish (downward), or vice versa.

Core Logic and Mechanism

The script operates based on three primary components: volatility measurement, price tracking, and trend switching logic.

1. Volatility Measurement (WATR) Before determining the trend, the tool analyzes a specific number of previous candles (defined by the "AveragePeriod"). It looks at the high and low points of these candles to calculate an average range. This result is converted into a "buffer value" (WATR). Essentially, this allows the indicator to understand how much the price normally fluctuates; a high-volatility market will have a wider buffer, while a low-volatility market will have a tighter one.

2. Dynamic Price Tracking The script constantly monitors the closing prices of candles. It maintains a "memory" of the highest or lowest price reached during the current trend:

  • In an uptrend, it tracks the highest price reached to ensure the trend remains strong.
  • In a downtrend, it tracks the lowest price reached to monitor the depth of the decline.

3. Trend Detection and Reversal The indicator decides whether to display an upward or downward signal based on whether the current price "breaks" through its calculated buffer:

  • Bullish Phase: If the trend is moving up, the script projects a value slightly below the current price. If the market price drops significantly below this projected level (hitting the buffer), the logic assumes the upward momentum has failed and switches the trend to bearish.
  • Bearish Phase: If the trend is moving down, the script projects a value slightly above the current price. If the market price rises above this projected level, the logic assumes the downward momentum has stalled and switches the trend to bullish.

Visual Representation

On your trading chart, the script simplifies this complex math into two visual markers (arrows):

  • Red Markers: Represent bearish sentiment or a confirmed downward trend.
  • Blue Markers: Represent bullish sentiment or a confirmed upward trend.

By using these markers, traders can see where the script identifies a definitive shift in momentum, helping to filter out minor price "noise" and focus on the broader direction of the market.

Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
BT2Stop_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+-----------------------------------------------------------------------+
//|                                                   BrainTrend1Stop.mq4 |
//|                                   Copyright © 2005. Alejandro Galindo |
//|                                                   http://elCactus.com |
//+-----------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue

//---- input parameters
extern int AveragePeriod=10;
extern int Reg=1;

//---- buffers
double Buffer1[];
double Buffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator line
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(0,Buffer1);
   SetIndexBuffer(1,Buffer2);
   SetIndexArrow(0,159);
   SetIndexArrow(1,159);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| BrainTrend1Stop                                                  |
//+------------------------------------------------------------------+
int start()
  {
  
   int i,shift,counted_bars=IndicatorCounted();
   double value=0, price=0, trend=0, dK=0, AvgRange=0, WATR=0;
   int bar=0;
   int CountBars=500;
   if (CountBars>=Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+11+1);
   SetIndexDrawBegin(1,Bars-CountBars+11+1);   
         
//---- initial zero
   AvgRange=0;
   for (i=1;i<=AveragePeriod;i++) 
   { 
      dK = 1+(AveragePeriod-i)/AveragePeriod;
      AvgRange=AvgRange+ dK*MathAbs(High[i]-Low[i]);      
   }
   if (Point>=0.01) { WATR = (AvgRange/AveragePeriod)*Point; }
   else { WATR = AvgRange/AveragePeriod; }
   
   if (Close[Bars-1] > Open[Bars-1]) 
   {
      value = Close[Bars - 1] * (1 - WATR);
      trend = 1;
      Buffer2[Bars-1]=value;
   }
   if (Close[Bars-1] < Open[Bars-1]) 
   {
      value = Close[Bars - 1] * (1 + WATR);
      trend = -1;
      Buffer1[Bars-1]=value;
   }
   
   bar=CountBars-11-1;
   while(bar>=0)
   {
   
   Buffer1[shift]=0;
   Buffer2[shift]=0;
   

   if (Reg==2) 
   {
      AvgRange=0;
      for (i=1;i<=AveragePeriod;i++) 
      {
         dK = 1+(AveragePeriod-i)/AveragePeriod;
         AvgRange=AvgRange+ dK*MathAbs(High[bar + i]-Low[bar + i]);
      }
      if (Point>=0.01) { WATR = (AvgRange/AveragePeriod)*Point; }
      else { WATR = AvgRange/AveragePeriod; }
   
   }
   
   if (trend >= 0) 
   {
      if (Close[bar] > price) { price = Close[bar]; }
      value = price * (1 - WATR);
      if (Close[bar] < value) 
      {
          price = Close[bar];
          value = price * (1 + WATR);
          trend = -1;
       }
    } else {
      if (trend <= 0) {
         if (Close[bar] < price) { price = Close[bar]; }
         value = price * (1 + WATR);
         if (Close[bar] > value) 
         {
             price = Close[bar];
            value = price * (1 - WATR);
            trend = 1;
         }
      }
    }

   if (trend == -1) { Buffer1[bar]=value; }
   if (trend == 1) { Buffer2[bar]=value; }
//----
           
   bar--;
   }
   return(0);
  }
//+------------------------------------------------------------------+


Comments