DIBS_TriggerLines1.2

Author: Copyright � 2008, ForexArea.com
DIBS_TriggerLines1.2
3 Views
0 Downloads
0 Favorites
DIBS_TriggerLines1.2
//+------------------------------------------------------------------+
//|                                         DIBS_TriggerLines1.2.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      = 10;  // lenght of trigger lines 
extern color   cBuyTriggerClr          = OrangeRed;
extern color   cSellTriggerClr         = DarkOrange;
extern color   cDayOpenClr             = FireBrick;
extern color   cDayCloseClr            = Black;
extern bool    bShowDayClose           = true;
extern bool    bShowStoploss           = false;
extern bool    bShowWeeklyOpen         = true;
extern int     iPriceLabelSize         = 2;
extern string  sComment1               = "---- Only set ONE alert to true!!! ----";
extern bool    bPopUpAlert             = true; // can only have one type of alert sound or popup
extern bool    bSoundAlert             = false;  // NOT both!!!
extern string  sSoundFile              = "puff.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;
bool bDrawLines;
int iTriggerObjects = 10000;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   //NewBar();  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   DeleteAll();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void DeleteAll(){

   ObjectDelete("DIBS_WeeklyOpen");
   
   for(int j = 0; j <= 10000; j++){
      ObjectDelete("DIBS_Trigger_B" + j);
      ObjectDelete("DIBS_Trigger_S" + j);
      ObjectDelete("DIBS_DayOpen" + j);
      ObjectDelete("DIBS_DayClose" + j);
      ObjectDelete("DIBS_Stoploss_B" + j);
      ObjectDelete("DIBS_Stoploss_S" + j);
   } 
}

int start()
  {
  
      if(Period() != PERIOD_H1){Comment("Only works on 1H timeframe!"); return(0);}
  
     if(NewBar()){DeleteAll(); bDrawLines = true; iTriggerObjects = 10000;}

     int limit;
     int counted_bars=IndicatorCounted();
     int iBarHour;
     int iExtension;
     double dDayOpenPrice;
     bool bDrawToday;
     int iUniqueID;
     int i;

     
  //---- check for possible errors
     if(counted_bars<0) return(-1);

     if(iBarsToCount == 0){
         limit=Bars;
      }else{
         limit=iBarsToCount;
      }
      
      
  //---- main loop
  
while(bDrawLines==true){

   if(bShowWeeklyOpen)DrawWeeklyOpen();

   // MUST be left at -1
   for(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+1 >= iOpenHour && iBarHour+1 <= iOpenHour + iBarsToTrade ){
			   // get day open price
			   
			   if(iBarHour+1 == iOpenHour){
			      dDayOpenPrice = iOpen(NULL, 0, i);
			      // draw vertical bar to show open of day 
			      ObjectCreate("DIBS_DayOpen" + i, OBJ_VLINE, 0, Time[i-1], 0);
			      ObjectSet("DIBS_DayOpen" + i, OBJPROP_COLOR, cDayOpenClr);
			      //ObjectSet("DIBS_DayOpen" + i, OBJPROP_STYLE, STYLE_DOT);
			   }
			   
			   if(iBarHour+1 == iOpenHour + iBarsToTrade && bShowDayClose){
			      // draw vertical bar to show close of day 
			      ObjectCreate("DIBS_DayClose" + i, OBJ_VLINE, 0, Time[i-1], 0);
			      ObjectSet("DIBS_DayClose" + i, OBJPROP_COLOR, cDayCloseClr);
			      //ObjectSet("DIBS_DayClose" + 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 
                  iTriggerObjects--;
                  if(i<iBarsToTrade){
                        iExtension = i;
                        //iUniqueID = 25000;
                        iUniqueID = iTriggerObjects;
                    }else{
                        iExtension = iTriggerLineLength-1;
                        iUniqueID = iTriggerObjects;
                     }
                  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, 5);
                           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 
                  iTriggerObjects--;
                  if(i<iBarsToTrade){
                        iExtension = i;
                        //iUniqueID = 25000;
                        iUniqueID = iTriggerObjects;
                    }else{
                        iExtension = iTriggerLineLength-1;
                        iUniqueID = iTriggerObjects;
                     }
                  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, 5);
                        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
  bDrawLines = false;
}
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

void DrawWeeklyOpen(){

   double WkOpen = iOpen(NULL, PERIOD_W1, 0);
   
   ObjectCreate("DIBS_WeeklyOpen", OBJ_HLINE, 0, 0, WkOpen);
   ObjectSet("DIBS_WeeklyOpen" , OBJPROP_COLOR, DarkGreen);
   ObjectSet("DIBS_WeeklyOpen" , OBJPROP_WIDTH, 5);
   ObjectSet("DIBS_WeeklyOpen" , OBJPROP_STYLE, STYLE_DOT);
			      
}

bool NewBar() {

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

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

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

Comments