诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

自动画线类指标 DIBS_TriggerLines1.2.mq4

DIBS_TriggerLines1.2指标按设定条件画线为交易提供参考。

图表:DIBS_TriggerLines1.2指标

源码:

//+------------------------------------------------------------------+
//|                                         DIBS_TriggerLines1.2.mq4 |
//|                                   Copyright @2008, ForexArea.com |
//+------------------------------------------------------------------+
#property copyright "Copyright @2008, ForexArea.com"
#property link      "http://www.125808047.com"

#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            = Lime;
extern bool    bShowDayClose           = true;
extern bool    bShowStoploss           = true;
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               = true;  // 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 OnInit(void)
{
    Comment("www.125808047.com");
    return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   DeleteAll();
  }
//+------------------------------------------------------------------+
//| 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 OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
      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;

     if(counted_bars<0) return(-1);

     if(iBarsToCount == 0){
         limit=Bars;
      }else{
         limit=iBarsToCount;
      }
  
while(bDrawLines==true)
{
   if(bShowWeeklyOpen)DrawWeeklyOpen();
   for(i=limit; i>0; i--){
      bDrawToday = false;
      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){
		   iBarHour = TimeHour(Time[i]);
		   if( iBarHour+1 >= iOpenHour && iBarHour+1 <= iOpenHour + iBarsToTrade ){
			   
			   if(iBarHour+1 == iOpenHour){
			      dDayOpenPrice = iOpen(NULL, 0, i);
			      ObjectCreate("DIBS_DayOpen" + i, OBJ_VLINE, 0, Time[i-1], 0);
			      ObjectSet("DIBS_DayOpen" + i, OBJPROP_COLOR, cDayOpenClr);
			   }
			   
			   if(iBarHour+1 == iOpenHour + iBarsToTrade && bShowDayClose){
			      ObjectCreate("DIBS_DayClose" + i, OBJ_VLINE, 0, Time[i-1], 0);
			      ObjectSet("DIBS_DayClose" + i, OBJPROP_COLOR, cDayCloseClr);
			   }
			   
			   if(iHigh(NULL, 0, i) <= iHigh(NULL, 0, i+1) && iLow(NULL, 0,i) >= iLow(NULL, 0, i+1)){
			      if(iHigh(NULL, 0, i) > dDayOpenPrice){
                  iTriggerObjects--;
                  if(i<iBarsToTrade){
                        iExtension = i;
                        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){
                  iTriggerObjects--;
                  if(i<iBarsToTrade){
                        iExtension = i;
                        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(rates_total);
  }
//+------------------------------------------------------------------+

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);
   }
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 自动画线类指标 DIBS_TriggerLines1.2.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏