//------------------------------------------------------------------
// Traders ATR
#property copyright "Copyright 2018,Daisuke "
#property link "http://mt4program.blogspot.com/"
#property version "1.00"
#property strict
#property indicator_chart_window
//buffers
#property indicator_buffers 4
#property indicator_plots 4
#property indicator_label1 "HIGH"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrIndianRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_label2 "LOW"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrAqua
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
#property indicator_label3 "HIGH2"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrIndianRed
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
#property indicator_label4 "LOW2"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrAqua
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
input int AtrPeriod = 14; // ATR Period
input double Rate1 = 1.0; // Rate
input double Rate2 = 2.0; // Rate
input ENUM_APPLIED_PRICE PriceType = PRICE_WEIGHTED; // Price Type
//buffer variables
double atrH1[];
double atrL1[];
double atrH2[];
double atrL2[];
//------------------------------------------------------------------
//initialize
int OnInit()
{
// short name setting
string shortName = "TATR (" + IntegerToString(AtrPeriod) + ")";
IndicatorShortName(shortName);
int count = 0;
SetIndexBuffer(count++, atrH1);
SetIndexBuffer(count++, atrL1);
SetIndexBuffer(count++, atrH2);
SetIndexBuffer(count++, atrL2);
return(INIT_SUCCEEDED);
}
//------------------------------------------------------------------
//calculate event
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[])
{
for( int i = rates_total - prev_calculated - 1 ; i >= 0; i-- )
{
TradersAtr(atrH1, atrL1, Rate1, rates_total, open, close, high, low, i);
TradersAtr(atrH2, atrL2, Rate2, rates_total, open, close, high, low, i);
}
return(rates_total - 1);
}
void TradersAtr(
double &bufferH[],
double &bufferL[],
double rate,
int rates_total,
const double &open[], // オープン値
const double &close[], // クローズ値
const double &high[], // 高値
const double &low[], // 安値
int i)
{
double atr = iATR(NULL, PERIOD_CURRENT, AtrPeriod, i);
double price = GetPrice(open[i], close[i], high[i], low[i], PriceType);
double h = price + rate * atr;
double l = price - rate * atr;
if( rates_total - 2 <= i )
{
bufferH[i] = h;
bufferL[i] = l;
}
else
{
if( bufferH[i + 1] != EMPTY_VALUE &&
bufferL[i + 1] != EMPTY_VALUE &&
bufferH[i + 1] < bufferL[i + 1] )
{
bufferH[i] = close[i + 1] > bufferH[i + 1] ? EMPTY_VALUE : MathMin(h, bufferH[i + 1]);
bufferL[i] = close[i + 1] < bufferL[i + 1] ? EMPTY_VALUE : MathMax(l, bufferL[i + 1]);
}
else
{
bufferH[i] = bufferH[i + 1] == EMPTY_VALUE ? h : MathMin(h, bufferH[i + 1]);
bufferL[i] = bufferL[i + 1] == EMPTY_VALUE ? l : MathMax(l, bufferL[i + 1]);
}
}
}
//------------------------------------------------------------------
// 価格を計算する。
// return 対象価格
double GetPrice(
double open, // オープン値
double close, // クローズ値
double high, // 高値
double low, // 安値
ENUM_APPLIED_PRICE maPrice //取得価格
)
{
double price = 0;
switch( maPrice )
{
case PRICE_CLOSE:
price = close;
break;
case PRICE_OPEN:
price = open;
break;
case PRICE_HIGH:
price = high;
break;
case PRICE_LOW:
price = low;
break;
case PRICE_MEDIAN:
price = (high + low) / 2;
break;
case PRICE_TYPICAL:
price = (high + low + close) / 3;
break;
case PRICE_WEIGHTED:
price = (high + low + close + close) / 4;
break;
}
return price;
}
「MT4でFXを勝ち抜く研究をするブログ」で公開している無料インジケータは、こちらの一覧から。
インジケータ一覧
Twitterもよろしくお願いします。
https://twitter.com/mt4program
Trading View プロフィール
ブログランキングにご協力よろしくお願いします。m(._.)m
にほんブログ村 |
お約束ですが、本ブログは、投資に対する利益を約束する物ではありません。最終的には自己責任によるご判断よろしくお願いいたします。