DIBS_TriggerLines1[1].1

Download script
Author: Copyright � 2008, ForexArea.com
DIBS_TriggerLines1[1].1

This script is a visual trading tool designed for the MetaTrader 4 platform, specifically tailored for use on the 1-hour (H1) timeframe. Its primary purpose is to identify specific price action patterns during the start of the trading day and provide visual "trigger" markers to help traders decide when to enter a position.

Core Functionality

The script monitors the market during a specific window of time following the daily open. It automatically identifies two key components: the opening price of the day and a specific price action formation known as an "Inside Bar."

1. Day Open Identification At a user-defined hour (the start of the trading day), the script marks the opening price. This is displayed on your chart as a vertical dotted line, providing a constant reference point for whether the current price is trading above or below the day's starting level.

2. Inside Bar Detection & Trigger Lines The logic scans for "Inside Bars"—a situation where one candle's high and low are completely contained within the range of the previous candle. When this occurs during the active monitoring window, the script evaluates the price relative to the Day Open:

  • Buy Triggers: If an Inside Bar appears and its high is above the Day Open price, the script draws a horizontal line (in Lime) at the high of that bar.
  • Sell Triggers: If an Inside Bar appears and its low is below the Day Open price, the script draws a horizontal line (in Red) at the low of that bar.

Visual & Audio Notifications

To assist with real-time trading, the script includes several interactive features:

  • Visual Markers: It places clear lines on the chart to show exactly where a "breakout" would occur. You can also choose to have stop-loss markers (arrows) displayed automatically.
  • Dynamic Alerts: When a new trigger is detected on the current live candle, the script can play a specific sound file and/or display a pop-up alert on your screen.
  • Smart Filtering: It includes a delay mechanism for alerts to ensure you aren't overwhelmed with repeated sounds for the same price movement.

Customization Options

The script is designed to be flexible, allowing users to adjust:

  • Timeframes: Define which hours of the day are monitored and how many bars following the open should be active.
  • Aesthetics: Customize the colors of the trigger lines and the visibility of stop-loss indicators.
  • Backtesting: A toggle exists to choose between viewing only today’s data or looking back at historical data to see where past triggers occurred.
Price Data Components
Series array that contains open prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Miscellaneous
It plays sound alerts
17 Views
0 Downloads
0 Favorites
DIBS_TriggerLines1[1].1
//+------------------------------------------------------------------+
//|                                            DIBS_TriggerLines.mq4 |
//|                                  Copyright © 2008, ForexArea.com |
//|                                         http://www.forexarea.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, ForexArea.com"
#property link      "http://www.forexarea.com"

// DIBS Indicator - for more information http://www.forexfactory.com/showthread.php?t=86766 
// or http://www.forexfactory.com/showthread.php?t=56907

#property indicator_chart_window

extern int     iOpenHour               = 5;  // open day hour 
extern int     iBarsToTrade            = 9;  // active hours to monitor (recommended 9-10)
extern int     iTriggerLineLength      = 7;  // lenght of trigger lines 
extern color   cBuyTriggerClr          = Lime;
extern color   cSellTriggerClr         = Red;
extern color   cDayOpenClr             = DeepPink;
extern bool    bShowStoploss           = false;
extern int     iPriceLabelSize         = 2;
extern string  sComment1               = "---- Only set ONE alert to true!!! ----";
extern bool    bPopUpAlert             = false; // can only have one type of alert sound or popup
extern bool    bSoundAlert             = true;  // NOT both!!!
extern string  sSoundFile              = "wait.wav"; // name of sound file 
extern int     iDelayBetweenAlarm      = 60; // delay between each alarm  
extern bool    bBackTest               = false;  // set to false to only show current day 
extern int     iBarsToCount            = 200;


double dBuyTriggerLines[], dSellTriggerLines[];
bool bDrawAll;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   NewBar();
   bDrawAll = true;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int j = 0; j <= 25000; j++){
      ObjectDelete("DIBS_Trigger_B" + j);
      ObjectDelete("DIBS_Trigger_S" + j);
      ObjectDelete("DIBS_DayOpen" + j);
      ObjectDelete("DIBS_Stoploss_B" + j);
      ObjectDelete("DIBS_Stoploss_S" + j);
   } 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  if(Period() != PERIOD_H1){Comment("Only works on 1H timeframe!"); return(0);}
  
int limit;
     int counted_bars=IndicatorCounted();
     int iBarHour;
     int iExtension;
     double dDayOpenPrice;
     bool bDrawToday;
     int iUniqueID;
     
  //---- check for possible errors
     if(counted_bars<0) return(-1);
  //---- the last counted bar will be recounted
     if(counted_bars>0) counted_bars--;
     if(iBarsToCount == 0){
         limit=Bars-counted_bars;
      }else{
         limit=iBarsToCount-counted_bars;
      }
  //---- main loop

   for(int i=limit; i>0; i--){
      bDrawToday = false;
	   // only draw objects for today
      if(bBackTest == false && TimeDay(Time[i]) == TimeDay(TimeCurrent()) && TimeMonth(Time[i]) == TimeMonth(TimeCurrent())){
            bDrawToday = true;
         }else{
           //bDrawToday = false;
         }
	     
     if(bBackTest == true){
            bDrawToday = true;
        }
        
     if(bDrawToday){
		   // only trade set hours
		   iBarHour = TimeHour(Time[i]);
		   if( iBarHour >= iOpenHour && iBarHour <= iOpenHour + iBarsToTrade){
			   // get day open price
			   if(iBarHour == iOpenHour){
			      dDayOpenPrice = iOpen(NULL, 0, i);
			      // draw vertical bar to show open of day 
			      ObjectCreate("DIBS_DayOpen" + i, OBJ_VLINE, 0, Time[i], 0);
			      ObjectSet("DIBS_DayOpen" + i, OBJPROP_COLOR, cDayOpenClr);
			      ObjectSet("DIBS_DayOpen" + i, OBJPROP_STYLE, STYLE_DOT);
			   }
			   
			   // see if we have an inside bar 
			   if(iHigh(NULL, 0, i) <= iHigh(NULL, 0, i+1) && iLow(NULL, 0,i) >= iLow(NULL, 0, i+1)){
			      // IB found so draw triggers
			      if(iHigh(NULL, 0, i) > dDayOpenPrice){
                  // draw buy trigger object 
                  if(i<iBarsToTrade){
                        iExtension = i;
                        //iUniqueID = 25000;
                        iUniqueID = i;
                    }else{
                        iExtension = iBarsToTrade;
                        iUniqueID = i;
                     }
                  if(bSoundAlert && i == 1)Alerts(1);
                  if(bPopUpAlert && i == 1)Alert("DIBS " + Symbol() + " - Buy Trigger");
                     if(ObjectFind("DIBS_Trigger_B" + iUniqueID) != 0){
                           ObjectCreate("DIBS_Trigger_B" + iUniqueID, OBJ_TREND, 0, Time[i], iHigh(NULL, 0, i) , Time[i-iExtension], iHigh(NULL, 0, i));
                           ObjectSet("DIBS_Trigger_B" + iUniqueID, OBJPROP_RAY, false);
                           ObjectSet("DIBS_Trigger_B" + iUniqueID, OBJPROP_WIDTH, 3);
                           ObjectSet("DIBS_Trigger_B" + iUniqueID, OBJPROP_COLOR, cBuyTriggerClr);
                        }else{
                           ObjectMove("DIBS_Trigger_B" + iUniqueID, 2, Time[i], iHigh(NULL, 0, i));  
                        }

                     if(bShowStoploss){
                        ObjectCreate("DIBS_Stoploss_B" + iUniqueID, OBJ_ARROW, 0, Time[i], iLow(NULL, 0, i));
                        ObjectSet("DIBS_Stoploss_B" + iUniqueID, OBJPROP_ARROWCODE, 5);
                        ObjectSet("DIBS_Stoploss_B" + iUniqueID, OBJPROP_COLOR, cBuyTriggerClr);
                        ObjectSet("DIBS_Stoploss_B" + iUniqueID, OBJPROP_WIDTH, iPriceLabelSize);
                    }
                    
               }
               if(iLow(NULL, 0, i) < dDayOpenPrice){
                  // draw sell trigger object 
                  if(i<iBarsToTrade){
                        iExtension = i;
                        //iUniqueID = 25000;
                        iUniqueID = i;
                    }else{
                        iExtension = iBarsToTrade;
                        iUniqueID = i;
                     }
                  if(bSoundAlert && i == 1)Alerts(1);
                  if(bPopUpAlert && i == 1)Alert("DIBS " + Symbol() + " - Sell Trigger");
                  if(ObjectFind("DIBS_Trigger_S" + iUniqueID) != 0){
                        ObjectCreate("DIBS_Trigger_S" + iUniqueID, OBJ_TREND, 0, Time[i], iLow(NULL, 0, i) , Time[i-iExtension], iLow(NULL, 0, i));
                        ObjectSet("DIBS_Trigger_S" + iUniqueID, OBJPROP_RAY, false);
                        ObjectSet("DIBS_Trigger_S" + iUniqueID, OBJPROP_WIDTH, 3);
                        ObjectSet("DIBS_Trigger_S" + iUniqueID, OBJPROP_COLOR, cSellTriggerClr);
                     }else{
                        ObjectMove("DIBS_Trigger_S" + iUniqueID, 2, Time[i], iLow(NULL, 0, i)); 
                     }
                  if(bShowStoploss){
                     ObjectCreate("DIBS_Stoploss_S" + iUniqueID, OBJ_ARROW, 0, Time[i], iHigh(NULL, 0, i));
                     ObjectSet("DIBS_Stoploss_S" + iUniqueID, OBJPROP_ARROWCODE, 5);
                     ObjectSet("DIBS_Stoploss_S" + iUniqueID, OBJPROP_WIDTH, iPriceLabelSize);
                     ObjectSet("DIBS_Stoploss_S" + iUniqueID, OBJPROP_COLOR, cSellTriggerClr);
                 }
               
		        } 
			   }// if 3
		    }// if 2
	   }// if 1    
   }// for

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

bool NewBar() {

	static datetime LastTime = 0;

	if (Time[0] != LastTime) {
		LastTime = Time[0];		
		return (true);
	} else
		return (false);
}

void Alerts(int Direction)
{
   static datetime AlertLastTime = 0;

   if(TimeCurrent() > AlertLastTime ) {
      AlertLastTime = TimeCurrent()+iDelayBetweenAlarm;
      PlaySound(sSoundFile);
   
   }
}

Comments