トップ  >  ダウンロード  >  インジケータ  >  IND_RateSection.ex4 /.ex5
スポンサーリンク
検索

↑の検索エンジンが表示されない人は、
↓の古い検索エンジンを使用して下さい。
カスタム検索
MQL4リファレンスツリー
IND_RateSection.ex4

注意事項:
自動売買を行うEAや売買シグナルのソフトウェアの配布は行っておりません。
このページにあるのは管理人が自作した便利関数やインジケータです。
ソースコードも公開していますので、ご自由にカスタマイズして下さい。
その代わりどんな不具合があっても私は責任を負いません。


IND_RateSection.ex4


指定したpips毎の節目に水平線を引きます。






変更履歴
Ver 変更内容
1.01 MQL5でも動作するように処理を変更
1.02 水平線をパラメータ指定できるように変更


ソースコード


ソースコード:
//+------------------------------------------------------------------+
//|                                          IND_RateSection |
//|                                 Copyright 2015, Created by Yuki. |
//|                                       http://yukifx.web.fc2.com/ |
//+------------------------------------------------------------------+
//|処理概要:チャート上に指定pips毎の節目となるレートに水平線を描画する
//+------------------------------------------------------------------+
//| date:        Ver:    detail
//| 15/09/01    1.00    new
//| 15/10/26    1.01    !変更    MQL5でも動作するように処理を変更
//| 19/02/27    1.02    水平線をパラメータ指定できるように変更。
//|                                                                  
//+------------------------------------------------------------------+

#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;                                  // 節目の間隔[pips] (範囲:5~9000)
sinput    color     _SetLineColor    = clrWhite;                             // 線の色
sinput    e_style   _SetLineStyle    = E_STYLE_SOLID;                        // 線の種類
sinput    e_back    _SetLineBack     = E_DISP_FRONT;                         // 線の表示位置

double Set_SectionRange = _SectionRange;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {

    EventSetTimer(60);
    DrawRateLine();

    if ( Set_SectionRange < 5) {
        Set_SectionRange = 5;
    }
    if ( Set_SectionRange > 9000) {
        Set_SectionRange = 9000;
    }

    return(INIT_SUCCEEDED);
}


//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
    EventKillTimer();
    ObjectsDeleteAll( 0 , OBJ_OPTION_HEAD);
}


//+------------------------------------------------------------------+
//| 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[])
{

    bool        testbool;
    datetime    gettime[];
    int         cret;

//    testbool = IsTesting();
    testbool = MQLInfoInteger(MQL_TESTER);

    if ( testbool == true ) {
        Print("デバッグテスト");
        static  datetime lasttime;
                datetime temptime;

//        temptime    = iTime(NULL,Period(),0);
        cret        = CopyTime( Symbol(),Period(),0,1,gettime);
        if ( cret < 0 ) {
            return rates_total;
        }
        temptime        = gettime[0];


        if ( temptime != lasttime ) {                // 時間足が確定時にtrue
            lasttime = temptime;
        } else {
            return rates_total;
        }
        
        DrawRateLine();
        
    }

    return(rates_total);
}


#define        DRAWTIME    60    // 描画間隔[分]

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer() {

    static int    timer_count        = DRAWTIME;
    
    
    if ( timer_count >= DRAWTIME ) {
        DrawRateLine();
        timer_count = 0;
    }

    timer_count++;

}


//+------------------------------------------------------------------+
//| 関数名    :DrawRateLine
//| 概要    :
//| 備考    :無し
//| ―――――――――――――――――――――――――――――――――
//| 戻り値    :無し
//| 引数    :無し
//+------------------------------------------------------------------+
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 = GetDispLineNumber(Set_SectionRange);
    int       displine_number = DISP_ARRAY_MAX - 1;    // 表示本数固定
    
    cret        = CopyClose( Symbol(),PERIOD_D1,1,1,getrate);    // 前日日足終値取得
    if ( cret < 0 ) {
        printf("月足データ取得エラー");
        return;
    }
    nowrate        = getrate[0];
//    nowrate        = iClose(Symbol(),PERIOD_D1,1);

    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);
        }
    }
}

//+------------------------------------------------------------------+
//| 関数名    :GetDispLineNumber
//| 概要    :現在のチャート表示範囲と指定値幅から、表示可能本数を算出
//| 備考    :無し
//| ―――――――――――――――――――――――――――――――――
//| 戻り値    :int        表示本数
//| 引数    :double    表示間隔
//+------------------------------------------------------------------+
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;
}





スポンサーリンク
スポンサーリンク


Copyright ©2015 MT4でEA自作しちゃお~ All Rights Reserved.


Top

inserted by FC2 system