3barpullback

Download script
Author: Plamen
3barpullback

The 3barpullback script is a technical analysis tool designed to identify specific price action patterns on a trading chart. It focuses on detecting "pullback" movements—situations where the market briefly moves against a primary trend before potentially continuing in its original direction.

To help traders visualize these moments, the script scans historical data and identifies two distinct scenarios: bullish (upward) and bearish (downward) setups based on specific structural requirements.

How the Logic Works

1. Bullish Pullback Identification (Up Signals) The script looks for a combination of three specific conditions to trigger an upward signal:

  • Structural Decline: It identifies a sequence where the highest points of three consecutive candles are decreasing. This indicates a temporary "dip" or pullback in price.
  • Price Recovery: It checks if the current closing price has moved significantly higher than the closing price from 10 bars ago.
  • Breakout Confirmation: It ensures that the current candle's high is higher than the previous candle's high, suggesting the momentum is shifting back upward.

When these conditions are met simultaneously, the script provides several visual cues:

  • Arrows: Lime-colored arrows appear below the price to highlight the entry zone.
  • Lower Highs: It marks the peaks of the pullback candles to show the declining trend.
  • Close-to-Close Lines: It draws horizontal lines connecting the closing prices across the 10-bar period to visualize the overall price recovery.

2. Bearish Pullback Identification (Down Signals) Similarly, the script looks for a downward reversal pattern by identifying:

  • Structural Rise: A sequence where the lowest points of three consecutive candles are increasing, indicating a temporary "relief" rally in a downtrend.
  • Price Drop: It verifies that the current opening price is lower than the opening price from 10 bars ago.
  • Breakout Confirmation: It confirms that the current candle's low is lower than the previous candle's low, signaling the resumption of the downward move.

When these conditions are met, the script provides:

  • Arrows: Red arrows appear above the price to highlight the entry zone.
  • Higher Lows: It marks the bottoms of the rally candles to show the rising floor.
  • Open-to-Open Lines: It draws horizontal lines connecting the opening prices across the 10-bar period to visualize the overall price decline.

Key Features for the User

  • Visual Customization: Users can toggle specific elements (arrows, highs/lows, or trend lines) on or off depending on their personal trading style.
  • Dynamic Scaling: The script automatically adjusts its visual spacing based on whether the asset has 2 or 4 decimal places, ensuring the markings look consistent regardless of the currency pair or instrument being traded.
  • Historical Analysis: The tool processes data across the entire chart history, allowing traders to see where these patterns occurred in the past to refine their strategy.
Miscellaneous
Implements a curve of type %1
10 Views
1 Downloads
0 Favorites
3barpullback
//+------------------------------------------------------------------+
//|                                         3barpullback.mq4 |
//|                                                           Plamen |
//|                                                 http://127.0.0.1 |
//+------------------------------------------------------------------+
#property copyright "Plamen"
#property link      "http://127.0.0.1"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 2
#property indicator_width4 2

//---- options
extern string UpSignal="===== Up Signal Settings =====";
extern bool ShowUpArrows=true;
extern color UpArrowsColor=Lime;
extern bool ShowLowerHighs=true;
extern color LowerHighsColor=Lime;
extern bool ShowCloseToCloseLines=true;
extern color CloseToCloseLinesColor=Lime;
extern string EndUpSignalSettings="==============================";
extern string DownSignal="==== Down Signal Settings ====";
extern bool ShowDownArrows=true;
extern color DownArrowsColor=Red;
extern bool ShowHigherLows=true;
extern color HigherLowsColor=Red;
extern bool ShowOpenToOpenLines=true;
extern color OpenToOpenLinesColor=Red;
extern string EndDownSignalSettings="==============================";

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

int CloseToCloseLinesCounter=0;
int OpenToOpenLinesCounter=0;
int pos=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW, EMPTY, EMPTY, HigherLowsColor);
   SetIndexArrow(0,217);
   SetIndexBuffer(0,Buffer1);
   SetIndexDrawBegin(0, 7);
   
   SetIndexStyle(1,DRAW_ARROW, EMPTY, EMPTY, LowerHighsColor);
   SetIndexArrow(1,218);
   SetIndexBuffer(1,Buffer2);
   SetIndexDrawBegin(1,7);
   
   SetIndexStyle(2,DRAW_ARROW, EMPTY, EMPTY, UpArrowsColor);
   SetIndexArrow(2,67);
   SetIndexBuffer(2, Buffer3);
   SetIndexDrawBegin(2,7);
   
   SetIndexStyle(3,DRAW_ARROW, EMPTY, EMPTY, DownArrowsColor);
   SetIndexArrow(3,68);
   SetIndexBuffer(3,Buffer4);
   SetIndexDrawBegin(3,7);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
    int i;
    
    for(i=0; i<=CloseToCloseLinesCounter; i++)
      ObjectDelete("CloseToCloseLines"+i);
      
    for(i=0; i<=OpenToOpenLinesCounter; i++)
      ObjectDelete("OpentoOpenLines"+i);
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   
   pos=Bars-counted_bars;
   
   while(pos>0)
   {
     if( (High[pos+1]<High[pos+2])&&(High[pos+2]<High[pos+3]) &&
         (Close[pos]>Close[pos+10]) &&
         (High[pos]>High[pos+1]) )
     {    
       if(ShowCloseToCloseLines) DisplayCloseToCloseLines();     
       if(ShowUpArrows) DisplayUpArrows();
       if(ShowLowerHighs) DisplayLowerHighs();
     }
           
     if( (Low[pos+1]>Low[pos+2])&&(Low[pos+2]>Low[pos+3]) &&
         (Open[pos]<Open[pos+10]) &&
         (Low[pos]<Low[pos+1]) )
     {
       if(ShowOpenToOpenLines) DisplayOpenToOpenLines();     
       if(ShowDownArrows) DisplayDownArrows();
       if(ShowHigherLows) DisplayHigherLows();
     }   

     pos--;
   }
   
   return(0);
  }
//+------------------------------------------------------------------+
void DisplayUpArrows()
{
  if(Digits==2)
    Buffer3[pos]=Low[pos]-0.30;
  else if(Digits==4)
    Buffer3[pos]=Low[pos]-0.0030;
}
//+------------------------------------------------------------------+
void DisplayDownArrows()
{
  if(Digits==2)
    Buffer4[pos]=High[pos]+0.30;
  else if(Digits==4)
    Buffer4[pos]=High[pos]+0.0030;
}
//+------------------------------------------------------------------+
void DisplayLowerHighs()
{
  if(Digits==2)
  {
    Buffer2[pos+1]=High[pos+1]+0.10;
    Buffer2[pos+2]=High[pos+2]+0.10;
    Buffer2[pos+3]=High[pos+3]+0.10;
  }
  else
  {
    Buffer2[pos+1]=High[pos+1]+0.0010;
    Buffer2[pos+2]=High[pos+2]+0.0010;
    Buffer2[pos+3]=High[pos+3]+0.0010;
  }
}
//+------------------------------------------------------------------+
void DisplayHigherLows()
{
  if(Digits==2)
  {
    Buffer1[pos+1]=Low[pos+1]-0.10;
    Buffer1[pos+2]=Low[pos+2]-0.10;
    Buffer1[pos+3]=Low[pos+3]-0.10;
  }
  else
  {
    Buffer1[pos+1]=Low[pos+1]-0.0010;
    Buffer1[pos+2]=Low[pos+2]-0.0010;
    Buffer1[pos+3]=Low[pos+3]-0.0010;
  }
}
//+------------------------------------------------------------------+
void DisplayCloseToCloseLines()
{
  ObjectCreate("CloseToCloseLines"+CloseToCloseLinesCounter, OBJ_TREND, 0, Time[pos+10], Close[pos+10], Time[pos], Close[pos+10]);
  ObjectSet("CloseToCloseLines"+CloseToCloseLinesCounter, OBJPROP_COLOR, CloseToCloseLinesColor);
  ObjectSet("CloseToCloseLines"+CloseToCloseLinesCounter, OBJPROP_RAY, false);
  CloseToCloseLinesCounter++;
  ObjectCreate("CloseToCloseLines"+CloseToCloseLinesCounter, OBJ_TREND, 0, Time[pos+10], Close[pos], Time[pos], Close[pos]);
  ObjectSet("CloseToCloseLines"+CloseToCloseLinesCounter, OBJPROP_COLOR, CloseToCloseLinesColor);
  ObjectSet("CloseToCloseLines"+CloseToCloseLinesCounter, OBJPROP_RAY, false);
  CloseToCloseLinesCounter++;
  ObjectCreate("CloseToCloseLines"+CloseToCloseLinesCounter, OBJ_TREND, 0, Time[pos+10], Close[pos+10], Time[pos+10], Close[pos]);
  ObjectSet("CloseToCloseLines"+CloseToCloseLinesCounter, OBJPROP_COLOR, CloseToCloseLinesColor);
  ObjectSet("CloseToCloseLines"+CloseToCloseLinesCounter, OBJPROP_RAY, false);
  CloseToCloseLinesCounter++;
}
//+------------------------------------------------------------------+
void DisplayOpenToOpenLines()
{
  ObjectCreate("OpenToOpenLines"+OpenToOpenLinesCounter, OBJ_TREND, 0, Time[pos+10], Open[pos+10], Time[pos], Open[pos+10]);
  ObjectSet("OpenToOpenLines"+OpenToOpenLinesCounter, OBJPROP_COLOR, OpenToOpenLinesColor);
  ObjectSet("OpenToOpenLines"+OpenToOpenLinesCounter, OBJPROP_RAY, false);
  OpenToOpenLinesCounter++;
  ObjectCreate("OpenToOpenLines"+OpenToOpenLinesCounter, OBJ_TREND, 0, Time[pos+10], Open[pos], Time[pos], Open[pos]);
  ObjectSet("OpenToOpenLines"+OpenToOpenLinesCounter, OBJPROP_COLOR, OpenToOpenLinesColor);
  ObjectSet("OpenToOpenLines"+OpenToOpenLinesCounter, OBJPROP_RAY, false);
  OpenToOpenLinesCounter++;
  ObjectCreate("OpenToOpenLines"+OpenToOpenLinesCounter, OBJ_TREND, 0, Time[pos+10], Open[pos+10], Time[pos+10], Open[pos]);
  ObjectSet("OpenToOpenLines"+OpenToOpenLinesCounter, OBJPROP_COLOR, OpenToOpenLinesColor);
  ObjectSet("OpenToOpenLines"+OpenToOpenLinesCounter, OBJPROP_RAY, false);
  OpenToOpenLinesCounter++;
}
//+------------------------------------------------------------------+

Comments