- //+------------------------------------------------------------------+
- //| CCT_BreakoutBox.mq4 |
- //| Copyright Complete Currency Trader Ltd |
- //| |
- //+------------------------------------------------------------------+
- #property copyright "Copyright, Complete Currency Trader Ltd"
- #property link ""
- #property version "1.00"
- #property strict
- #property indicator_chart_window
- extern string OpenTime = "10:00";
- extern int PipsAbove = 100;
- extern int PipsBelow = 100;
- extern color BoxColor = DarkOliveGreen;
- extern int MaxBoxes = 50;
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int onInit()
- {
- return(INIT_SUCCEEDED);
- }
- void onDeinit(const int reason)
- {
- for(int i = ObjectsTotal()-1; i>=0; i--)
- {
- if(StringFind(ObjectName(i),"BOXMODEL9") != -1)
- ObjectDelete(ObjectName(i));
- }
- }
-
- //+------------------------------------------------------------------+
- //| Custom indicator iteration function |
- //+------------------------------------------------------------------+
- 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[])
- {
- datetime startTime = StrToTime(OpenTime);
- int targetTimeframe = getTargetTf(startTime);
-
- int days = -1, lastDay = -1;
- for(int i = 0; i < Bars; i++)
- {
- int today = iTime(Symbol(), PERIOD_D1, iBarShift(Symbol(), PERIOD_D1, Time[i]));
-
- // skip till new day
- if(today == lastDay)
- continue;
- else
- {
- days++;
- lastDay = today;
- }
-
- // objects drawn, exit
- if(ObjectFind("BOXMODEL9"+DoubleToStr(today,0)) != -1)
- break;
-
- // draw box on new day
- if(ObjectFind("BOXMODEL9"+DoubleToStr(today,0)) == -1)
- {
- int shift = iBarShift(Symbol(), targetTimeframe, startTime-days*1440*60, true);
- if(shift != -1)
- {
- double price = iOpen(Symbol(), targetTimeframe, shift);
- ObjectCreate("BOXMODEL9"+DoubleToStr(today,0), OBJ_RECTANGLE, 0, startTime-days*1440*60, price+PipsAbove*Point, startTime-(days-1)*1440*60-TimeHour(startTime)*60*60-TimeMinute(startTime)*60, price-PipsBelow*Point);
- ObjectSet("BOXMODEL9"+DoubleToStr(today, 0), OBJPROP_COLOR, BoxColor);
- }
- }
-
- if(days == MaxBoxes)
- break;
- }
- return(rates_total);
- }
- //+------------------------------------------------------------------+
- // returns tf to get data from depending on user input
- //+------------------------------------------------------------------+
- int getTargetTf(datetime time)
- {
- if(TimeMinute(time) == 0 && Period() <= 60)
- return(Period());
- else if(TimeMinute(time) == 0 && Period() >= 60)
- return(PERIOD_H1);
- else if(TimeMinute(time) == 15)
- return(PERIOD_M15);
- else if(TimeMinute(time) == 30)
- return(PERIOD_M30);
- else if(TimeMinute(time) == 45)
- return(PERIOD_M15);
- else
- return(PERIOD_M1);
- }
|