//+------------------------------------------------------------------+ //| 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); } }
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Series array that contains open prices of each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Other Features:
It issuies visual alerts to the screen
It plays sound alerts