Batfink Signal (Stoploss A)

Download script
Batfink Signal (Stoploss A)

This script is designed for the MetaTrader 4 platform to help traders identify specific "breakout" moments based on price action during certain timeframes of the trading day. Instead of simply looking at every price movement, the logic focuses on defining specific zones and monitoring when the market pushes beyond those boundaries.

Core Logic Overview

The tool operates by segmenting the trading day into three distinct periods. It tracks the behavior of the market during these times to establish "Zones." Once these zones are established, the script monitors the current price to see if it breaks out of these established levels, providing a visual signal and optional alerts for the trader.

Key Functional Components

1. Time Zone Management The script is designed to be versatile regarding geography. It allows the user to input their local time zone and the destination time zone (the server time). This ensures that the "daily range" calculations remain accurate regardless of where the trader is located or what server they are using.

2. Period Segmentation The logic divides the day into three specific windows:

  • First Period: The initial morning session.
  • Second Period: The middle session.
  • Rest of Day: The final remaining hours.

The script identifies the highest and lowest prices reached during these specific blocks of time to define the market's "boundaries."

3. Zone Projection & Buffers Once the first period is completed, the script calculates a trading zone based on that data. It takes the price level from that session and extends it forward.

  • It creates an Upper Boundary and a Lower Boundary.
  • The distance between these boundaries is customizable by the user (defined in "PipsForEntry"). This allows the trader to determine how much "room" or "buffer" they want to see before a signal is valid.

4. Breakout Detection The script constantly monitors the relationship between the current candle's price and the projected Upper/Lower boundaries:

  • Buy Signals: Occur when the price pushes upward and crosses above the established Upper Boundary.
  • Sell Signals: Occur when the price pushes downward and crosses below the established Lower Boundary.

5. Visual & Audio Notifications To make the data actionable, the script provides three types of feedback:

  • Visual Lines: It draws the boundaries directly on the chart so the trader can see the current "zones."
  • Visual Arrows: It places specific icons (arrows) on the chart exactly where a breakout occurs.
  • Alerts: If enabled, the script will trigger an active alert notification on the platform the moment a breakout signal is confirmed, allowing the trader to react instantly without staring at the screen constantly.

Summary for the User

Essentially, this tool automates the process of "marking the lines" based on the day's morning and midday activity. It filters out minor price fluctuations and only alerts you when the market shows enough strength to break through the established boundaries of those previous sessions.

Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
14 Views
0 Downloads
0 Favorites
Batfink Signal (Stoploss A)

//+------------------------------------------------------------------+
//|  Batfink Daily Range.MT4                                         |
//|                                                                  |
//+------------------------------------------------------------------+


/* Introduction:

   Draw Line at 00:00GMT + and - 10

   TimeZONE Information - Indicator can be used for different Time Zones. 
                          For Batfink settings set to -5 for MetaQuotes demo Server
                          This will place home line at 00:00GMT Time

*/

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Red

extern bool DoEntryAlerts= false;
extern int LocalTimeZone= 2;
extern int DestTimeZone= 0;
extern int PipsForEntry= 10;

double Zone1Upper[];
double Zone1Lower[];
double EntrySignalsBuffer[];   

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Zone1Upper);
   SetIndexEmptyValue(0, 0.0);

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Zone1Lower);
   SetIndexEmptyValue(1, 0.0);
   
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2, 117);
   SetIndexBuffer(2, EntrySignalsBuffer);
   SetIndexEmptyValue(2, 0.0);
   SetIndexLabel(2, "Zone Breakout Signal");

   return(0);
}

int deinit()
{

   return(0);
}
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int counted_bars= IndicatorCounted(),
         lastbar, result;

   if (Bars<=100) 
      return(0);
      
   if (counted_bars>0)
      counted_bars--;
      
   lastbar= Bars - counted_bars;
   
   BreakoutRanges(0, lastbar, LocalTimeZone, DestTimeZone);
   
   //
   // check alerts   
   //
   
   static datetime lastalerttime;
   static double lastalertprice;

   if (DoEntryAlerts && lastalerttime!=Time[0] && EntrySignalsBuffer[0]!=0 && EntrySignalsBuffer[0]!=lastalertprice) {
      Alert("ZoneBreakout signals entry!");
      lastalerttime= Time[0];
      lastalertprice= EntrySignalsBuffer[0];
   } 
   else {
      lastalerttime= 0;
      lastalertprice= 0.0;
   }


   return(0);
}
   
 
//+------------------------------------------------------------------+
//| Compute index of first/last bar of yesterday and today           |
//+------------------------------------------------------------------+
int BreakoutRanges(int offset, int lastbar, int tzlocal, int tzdest)
{     
   int i, j, k,
       tzdiff= tzlocal - tzdest,
       tzdiffsec= tzdiff*3600, 
       tidxstart[2]= { 0, 0}, 
       tidxend[2]= { 0, 0 };
   double topen[2]= { 0.0, 0.0 }, 
           tclose[2]= { 99999.9, 99999.9 };
   string tfrom[3]= { "07:00", "08:00" ,  /*rest of day: */ "12:00"},
          tto[3]=   { "08:00", "12:00",   /*rest of day: */ "24:00" },
          tday;
   bool inperiod= -1;
   datetime timet;
   

   //
   // search back for the beginning of the day
   //
   tday= TimeToStr(Time[lastbar]-tzdiffsec, TIME_DATE);   
   for (  ; lastbar<Bars; lastbar++) {
      if (TimeToStr(Time[lastbar] - tzdiffsec, TIME_DATE)!=tday) {
         lastbar--;
         break;      
      }
   }   



   //
   // find the high/low for the two periods and carry them forward through the day
   //
   tday= "XXX";
   for (i= lastbar; i>=offset; i--) {
   
      timet= Time[i] - tzdiffsec;   // time of this bar
      
      string timestr= TimeToStr(timet, TIME_MINUTES),    // current time HH:MM
             thisday= TimeToStr(timet, TIME_DATE);       // current date
             
      EntrySignalsBuffer[i]= 0;  
      
      //
      // for all three periods (first period, second period, rest of day)
      //
      for (j= 0; j<3; j++) {
      
         if (tfrom[j]<=timestr && timestr<tto[j]) {   // Bar[i] in this period
      
            if (inperiod!=j) { // entered new period, so last one is completed
                                 
               if (j>0) {      // now draw high/low back over the recently completed period
               
                  for (k= tidxstart[j-1]; k>=tidxend[j-1]; k--) {
                     if (j-1==0) {
                        Zone1Upper[k]= tclose[j-1];
                        Zone1Lower[k]= tclose[j-1];
           
                  }
               }
               
               inperiod= j;   // remember current period
            }
            


            // for the current period find idxstart, idxend and compute high/low
            if (tidxstart[j]==0) {
               tidxstart[j]= i;
               tday= thisday;
            }
         
            tidxend[j]= i;
      
            topen[j]= MathMax(topen[j], Open[i]);
            tclose[j]= MathMin(tclose[j], Close[i]);
         }
      }
     
      
      //------------------------------------------------------------------------ 
      // carry forward the periods for which we have definite high/lows
      //
      if (inperiod>=1 && tday==thisday) { // first time period completed
         Zone1Upper[i]= tclose[0] + PipsForEntry*Point;
         Zone1Lower[i]= tclose[0] - PipsForEntry*Point;
    }
         
         CheckSignal(i, Zone1Upper[i], OP_BUY, EntrySignalsBuffer);
         CheckSignal(i, Zone1Lower[i], OP_SELL, EntrySignalsBuffer);
      }
    {   // none yet to carry forward (zero to clear old values, e.g. from switching timeframe)
         Zone1Upper[i]= 0;
         Zone1Lower[i]= 0;
      }
     

      //
      // at the beginning of a new day reset everything
      //
      if (tday!="XXX" && tday!=thisday) {
         Print("#", i, "new day ", thisday, "/", tday);
      
         tday= "XXX";
         
         inperiod= -1;
         
         for (j= 0; j<2; j++) {
            tidxstart[j]= 0;
            tidxend[j]= 0;
         
            topen[j]= 0;
            tclose[j]= 99999;
         }
      }
   }

   return (0);       
}
//+------------------------------------------------------------------+
//| Check price break                                                |
//+------------------------------------------------------------------+
bool CheckSignal(int shift, double price, int type, double &signalbuffer[]) 
{
   bool signal= false;

   if (type==OP_BUY && ((Open[shift]<price && High[shift]>price) || (Close[shift+1]<price && Open[shift]>price)) ) {
      signalbuffer[shift]= price;
      signal= true;
  }

   if (type==OP_SELL && (Open[shift]>price && Low[shift]<price) || (Close[shift+1]>price && Open[shift]<price)) {
      signalbuffer[shift]= price;
      signal= true;
  }
  
  return (signal);
}



Comments