MT5インジ

これはつかえるかなと思ったインジケータ。

0時にVline。

 東京株式オープン時間に直前の数時間(HLBand)内の高安を表示。

 ロンドン株式オープン時間に直前の数時間(HLBand)内の高安を表示。

 ニューヨーク株式オープン時間に直前の数時間(HLBand)内の高安を表示。

 それだけですが、結構ブレイク狙いに使えるかも、逆に反発もすることもあり。

 0時にVlineは記述調整必要か。

 自分は15分足のみで表示。

 

//+------------------------------------------------------------------+
//| All_In_worktime.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_plots 6

#property indicator_label1 "TRH"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrMaroon
#property indicator_width1 1
#property indicator_label2 "TRL"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrMaroon
#property indicator_width2 1

#property indicator_label3 "LRH"
#property indicator_type3 DRAW_ARROW
#property indicator_color3 clrDarkBlue
#property indicator_width3 1
#property indicator_label4 "LRL"
#property indicator_type4 DRAW_ARROW
#property indicator_color4 clrDarkBlue
#property indicator_width4 1

#property indicator_label5 "NRH"
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrPurple
#property indicator_width5 1
#property indicator_label6 "NRL"
#property indicator_type6 DRAW_ARROW
#property indicator_color6 clrPurple
#property indicator_width6 1

//指標バッファ
double TRH;
double TRL
;
double LRH;
double LRL
;
double NRH;
double NRL
;

//ハンドル
input int TargetHour1 = 2;
input int TargetHour1_ = 8;
input int TargetHour2 = 10;
input int TargetHour2_ = 18;
input int TargetHour3 = 15;
input int TargetHour3_ = 23;
input int HLBand = 56;

extern int Line_Width_1_2_3_4_or_5 = 1;
extern int Line_Style = 2;
extern color Asia_Color = White;
extern int Historical_Days = 10;

static double TKRangeH, TKRangeL;
static double LDRangeH, LDRangeL;
static double NYRangeH, NYRangeL;

//初期化関数
int OnInit() {
SetIndexBuffer(0, TRH, INDICATOR_DATA);
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 0);
PlotIndexSetInteger(0, PLOT_ARROW, 159);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
ArraySetAsSeries(TRH, true);

SetIndexBuffer(1, TRL, INDICATOR_DATA);
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, 0);
PlotIndexSetInteger(1, PLOT_ARROW, 159);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
ArraySetAsSeries(TRL, true);

SetIndexBuffer(2, LRH, INDICATOR_DATA);
PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, 0);
PlotIndexSetInteger(2, PLOT_ARROW, 159);
PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, EMPTY_VALUE);
ArraySetAsSeries(LRH, true);

SetIndexBuffer(3, LRL, INDICATOR_DATA);
PlotIndexSetInteger(3, PLOT_DRAW_BEGIN, 0);
PlotIndexSetInteger(3, PLOT_ARROW, 159);
PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, EMPTY_VALUE);
ArraySetAsSeries(LRL, true);

SetIndexBuffer(4, NRH, INDICATOR_DATA);
PlotIndexSetInteger(4, PLOT_DRAW_BEGIN, 0);
PlotIndexSetInteger(4, PLOT_ARROW, 159);
PlotIndexSetDouble(4, PLOT_EMPTY_VALUE, EMPTY_VALUE);
ArraySetAsSeries(NRH, true);

SetIndexBuffer(5, NRL, INDICATOR_DATA);
PlotIndexSetInteger(5, PLOT_DRAW_BEGIN, 0);
PlotIndexSetInteger(5, PLOT_ARROW, 159);
PlotIndexSetDouble(5, PLOT_EMPTY_VALUE, EMPTY_VALUE);
ArraySetAsSeries(NRL, true);

DeleteObjects();
for (int i=0; i<Historical_Days; i++) {
string ii = IntegerToString(i);
CreateObjects("day"+ii, Asia_Color);
}

IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
/*
REASON_PROGRAM 0 EAがExpertRemove関数を呼び出して操作を終了しました。
REASON_REMOVE 1 プログラムがチャートから削除されました。
REASON_RECOMPILE 2 プログラムが再コンパイルされました。
REASON_CHARTCHANGE 3 通貨ペアか時間足が変更されました。
REASON_CHARTCLOSE 4 チャートが閉じられました。
REASON_PARAMETERS 5 パラメータがユーザ—によって変更されました。
REASON_ACCOUNT 6 別のアカウントが有効化されるか、アカウントの設定変更によってサーバへの再接続が発生しました。
REASON_TEMPLATE 7 新しいテンプレートが適用されました。
REASON_INITFAILED 8 OnInit関数がゼロ以外の値を返しました。
REASON_CLOSE 9 MT4のターミナルが閉じられた。
*/
if(reason == REASON_REMOVE || reason == REASON_CHARTCLOSE) {
DeleteObjects();
Comment("");
}
}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CreateObjects(string no, color cl) {
ObjectCreate(0, no, OBJ_VLINE,0,0,0);
ObjectSetInteger(0, no, OBJPROP_WIDTH, Line_Width_1_2_3_4_or_5);
ObjectSetInteger(0, no, OBJPROP_STYLE, Line_Style);
ObjectSetInteger(0, no, OBJPROP_COLOR, cl);
ObjectSetInteger(0, no, OBJPROP_BACK, false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DeleteObjects() {
for (int i=0; i<Historical_Days; i++) {
string ii = IntegerToString(i);
ObjectDelete(0, "day"+ii);
}
}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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
) {
int limit, to_copy;
if(prev_calculated > rates_total || prev_calculated <= 0) to_copy = rates_total;
else {
to_copy = rates_total - prev_calculated;
to_copy++;
}
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);

limit = rates_total - prev_calculated;
if(prev_calculated == 0)
limit -= 11;
else
limit--;

for(int i = limit; i >= 0; i--) {
MqlDateTime STime;
datetime dtime = time[i];
TimeToStruct(dtime, STime);
//--------------------------------------------------TK8 Range
int nowhour = STime.hour;
int nowmin = STime.min;
if(nowhour == TargetHour1 && nowmin <= 15) {
TKRangeH = high[iHighest(NULL, 0, MODE_HIGH, HLBand, i)];
TKRangeL = low[iLowest(NULL, 0, MODE_LOW, HLBand, i)];
}
if(nowhour >= TargetHour1 && nowhour <= TargetHour1_) {
TRH[i] = TKRangeH;
TRL[i] = TKRangeL;
}
//--------------------------------------------------LD8 Range
if(nowhour == TargetHour2 && nowmin <= 15) {
LDRangeH = high[iHighest(NULL, 0, MODE_HIGH, HLBand, i)];
LDRangeL = low[iLowest(NULL, 0, MODE_LOW, HLBand, i)];
}
if(nowhour >= TargetHour2 && nowhour <= TargetHour2_) {
LRH[i] = LDRangeH;
LRL[i] = LDRangeL;
}
//--------------------------------------------------NY8 Range
if(nowhour == TargetHour3 && nowmin <= 15) {
NYRangeH = high[iHighest(NULL, 0, MODE_HIGH, HLBand, i)];
NYRangeL = low[iLowest(NULL, 0, MODE_LOW, HLBand, i)];
}
if(nowhour >= TargetHour3 && nowhour <= TargetHour3_) {
NRH[i] = NYRangeH;
NRL[i] = NYRangeL;
}
//-----------------------end loop
datetime dt=TimeCurrent();
for (int ii=0; ii<Historical_Days; ii++) {
string ii_ = IntegerToString(ii);
DrawObjects(dt, "day"+ii_, "00:00","AsiaOpen");
dt=decDateTradeDay(dt);
// while (TimeDayOfWeek(dt)>5) dt=decDateTradeDay(dt);
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
void DrawObjects(datetime dt, string no, string tb, string te) {
datetime t1, t2;
// double p1, p2;
int b1, b2;

t1=StringToTime(TimeToString(dt, TIME_DATE)+" "+tb);
t2=StringToTime(TimeToString(dt, TIME_DATE)+" "+te);
b1=iBarShift(NULL, 0, t1);
b2=iBarShift(NULL, 0, t2);
// p1=high[Highest(NULL, 0, MODE_HIGH, b1-b2, b2)];
// p2=low [Lowest (NULL, 0, MODE_LOW, b1-b2, b2)];
ObjectMove(0, no, OBJPROP_TIME, t1, 0);
// ObjectSet(no, OBJPROP_PRICE1, p1);
ObjectMove(0, no, OBJPROP_TIME, t2, 0);
// ObjectSet(no, OBJPROP_PRICE2, p2);
}
//+------------------------------------------------------------------+
datetime decDateTradeDay (datetime dt) {
MqlDateTime STime;
TimeToStruct(dt, STime);
int ty=STime.year;
int tm = STime.mon;
int td=STime.day;
int th=STime.hour;
int ti=STime.min;

td--;
if (td==0) {
tm--;
if (tm==0) {
ty--;
tm=12;
}
if (tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12) td=31;
if (tm==2) if (MathMod(ty, 4)==0) td=29;
else td=28;
if (tm==4 || tm==6 || tm==9 || tm==11) td=30;
}
return(StringToTime(ty+"."+tm+"."+td+" "+th+":"+ti));
}
//+------------------------------------------------------------------+