#property copyright "Copyright 2015, Created by Yuki."
#property link "http://yukifx.web.fc2.com/"
#property version "1.02"
#property strict
#property indicator_chart_window
#property description "チャート上に指定pips毎の節目となるレートに水平線を描画する"
#define OBJ_OPTION_HEAD "IRSO_"
#define DISP_ARRAY_MAX 100
enum e_style{
E_STYLE_SOLID = STYLE_SOLID
, E_STYLE_DOT = STYLE_DOT
, E_STYLE_DASH = STYLE_DASH
, E_STYLE_DASHDOT = STYLE_DASHDOT
, E_STYLE_DASHDOTDOT = STYLE_DASHDOTDOT
};
enum e_back{
E_DISP_FRONT = (int)false
, E_DISP_BACK = (int)true
};
sinput double _SectionRange = 100;
sinput color _SetLineColor = clrWhite;
sinput e_style _SetLineStyle = E_STYLE_SOLID;
sinput e_back _SetLineBack = E_DISP_FRONT;
double Set_SectionRange = _SectionRange;
int OnInit() {
EventSetTimer(60);
DrawRateLine();
if ( Set_SectionRange < 5) {
Set_SectionRange = 5;
}
if ( Set_SectionRange > 9000) {
Set_SectionRange = 9000;
}
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) {
EventKillTimer();
ObjectsDeleteAll( 0 , OBJ_OPTION_HEAD);
}
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[])
{
bool testbool;
datetime gettime[];
int cret;
testbool = MQLInfoInteger(MQL_TESTER);
if ( testbool == true ) {
Print("デバッグテスト");
static datetime lasttime;
datetime temptime;
cret = CopyTime( Symbol(),Period(),0,1,gettime);
if ( cret < 0 ) {
return rates_total;
}
temptime = gettime[0];
if ( temptime != lasttime ) {
lasttime = temptime;
} else {
return rates_total;
}
DrawRateLine();
}
return(rates_total);
}
#define DRAWTIME 60
void OnTimer() {
static int timer_count = DRAWTIME;
if ( timer_count >= DRAWTIME ) {
DrawRateLine();
timer_count = 0;
}
timer_count++;
}
void DrawRateLine( void ) {
double nowrate;
double nowtrimrate;
double disprate[DISP_ARRAY_MAX];
int icount;
int trimdigits;
int array_diff;
string objname;
int cret;
double getrate[];
int displine_number = DISP_ARRAY_MAX - 1;
cret = CopyClose( Symbol(),PERIOD_D1,1,1,getrate);
if ( cret < 0 ) {
printf("月足データ取得エラー");
return;
}
nowrate = getrate[0];
if ( Set_SectionRange >= 1000) {
trimdigits = Digits() - 4;
} else if ( Set_SectionRange >= 100) {
trimdigits = Digits() - 3;
} else if ( Set_SectionRange >= 10) {
trimdigits = Digits() - 2;
} else {
trimdigits = Digits() - 1;
}
nowtrimrate = NormalizeDouble( nowrate , trimdigits );
array_diff = displine_number / 2;
for ( icount = 0 ; icount < displine_number ; icount++ ) {
disprate[icount] = nowtrimrate + ( Set_SectionRange * Point() * 10 ) * (double)( array_diff - icount );
objname = StringFormat( "%s %s" , OBJ_OPTION_HEAD , DoubleToString( disprate[icount] , trimdigits ));
if (ObjectFind(0,objname) == -1) {
ObjectCreate( 0,objname, OBJ_HLINE, 0 , 0 , disprate[icount] );
ObjectSetInteger( 0,objname, OBJPROP_COLOR, _SetLineColor);
ObjectSetInteger( 0,objname, OBJPROP_STYLE, _SetLineStyle);
ObjectSetInteger( 0,objname, OBJPROP_WIDTH, 1);
ObjectSetInteger( 0,objname, OBJPROP_BACK, _SetLineBack);
ObjectSetInteger( 0,objname, OBJPROP_SELECTABLE,false);
ObjectSetInteger( 0,objname, OBJPROP_SELECTED,false);
}
}
}
int GetDispLineNumber(double in_range ){
double DispChartHeight = ChartGetDouble(0,CHART_PRICE_MAX,0) - ChartGetDouble(0,CHART_PRICE_MIN,0);
double range_point = in_range * Point() * 10;
int ret = DISP_ARRAY_MAX;
if ( range_point != 0) {
ret = (int)(DispChartHeight / range_point);
}
if ( ret >= DISP_ARRAY_MAX) {
ret = DISP_ARRAY_MAX - 1;
}
if ( ret < 10 ) {
ret = 10;
}
if ( ret % 2 != 0) {
ret++;
}
return ret;
}