#property description "The indicator analyzes data for the last month and draws all candlesticks with small"
#property description "and large tick volumes. The tick volume array is sorted out"
#property description "to define such candlesticks. The candlesticks having the volumes comprising the first InpSmallVolume"
#property description "per cent of the array are considered small. The candlesticks having the tick volumes comprising "
#property description "the last InpBigVolume per cent of the array are considered large."
//--- 指標の設定
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 1
//--- プロット
#property indicator_label1 "VolumeFactor"
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 clrDodgerBlue,clrOrange
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//--- 定義済み定数
#define INDICATOR_EMPTY_VALUE 0.0
//--- 入力パラメータ
input int InpSmallVolume=15; // 小ボリューム( <50 )の百分率値
input int InpBigVolume=20; // 大ボリューム( <50 )の百分率値
//--- 分析開始時間 (移動される)
datetime ExtStartTime;
//--- 指標バッファ
double ExtOpenBuff[];
double ExtHighBuff[];
double ExtLowBuff[];
double ExtCloseBuff[];
double ExtColorBuff[];
//--- ローソク足を表示するためのボリュームの境界値
long ExtLeftBorder=0;
long ExtRightBorder=0;
//+------------------------------------------------------------------+
//| ティックボリュームの境界値を受け取る |
//+------------------------------------------------------------------+
bool GetVolumeBorders(void)
{
//--- 変数
datetime stop_time; // 終了時刻を複製する
long buff[]; // 複製に使用するバッファ
//--- 終了時刻が現在の時刻
stop_time=TimeCurrent();
//--- start time は現在時間より1か月前である
ExtStartTime=GetStartTime(stop_time);
//--- ティックボリュームの値を受け取る
ResetLastError();
if(CopyTickVolume(Symbol(),Period(),ExtStartTime,stop_time,buff)==-1)
{
//--- データの受信に失敗し、再計算コマンドを起動するために false を返す
PrintFormat("Failed to receive tick volume values. Error code = %d",GetLastError());
return(false);
}
//--- 配列サイズを計算する
int size=ArraySize(buff);
//--- 配列をソートする
ArraySort(buff);
//--- ティックボリュームの左と右の境界線の値を定義する
ExtLeftBorder=buff[size*InpSmallVolume/100];
ExtRightBorder=buff[(size-1)*(100-InpBigVolume)/100];
//--- 実行成功
return(true);
}
//+------------------------------------------------------------------+
//| 渡されたものよりも1ヶ月前のデータを受け取る |
//+------------------------------------------------------------------+
datetime GetStartTime(const datetime stop_time)
{
//--- 終了時間を MqlDateTime 型構造変数に変換する
MqlDateTime temp;
TimeToStruct(stop_time,temp);
//--- 1ヶ月前のデータを受け取る
if(temp.mon>1)
temp.mon-=1; // 現在の月が 1 月ではないので、前月の数が 1 小さい
else
{
temp.mon=12; // 現在の月が 1 月なので、前月の数は 12
temp.year-=1; // 年番号が 1 少ないうち
}
//--- 日数は 28 を超えない
if(temp.day>28)
temp.day=28;
//--- 取得された日付を返す
return(StructToTime(temp));
}
//+------------------------------------------------------------------+
//| カスタム指標を初期化する関数 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 入力パラメータが条件を満たしているかどうかを確認する
if(InpSmallVolume<0 || InpSmallVolume>=50 || InpBigVolume<0 || InpBigVolume>=50)
{
Print("Incorrect input parameters");
return(INIT_PARAMETERS_INCORRECT);
}
//--- 指標バッファマッピング
SetIndexBuffer(0,ExtOpenBuff);
SetIndexBuffer(1,ExtHighBuff);
SetIndexBuffer(2,ExtLowBuff);
SetIndexBuffer(3,ExtCloseBuff);
SetIndexBuffer(4,ExtColorBuff,INDICATOR_COLOR_INDEX);
//--- 表示されない値を設定する
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,INDICATOR_EMPTY_VALUE);
//--- 指標バッファのラベルを設定する
PlotIndexSetString(0,PLOT_LABEL,"Open;High;Low;Close");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| カスタム指標の反復関数 |
//+------------------------------------------------------------------+
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[])
{
//--- 未処理のバーがまだ存在しているかどうかを確認する
if(prev_calculated<rates_total)
{
//--- ボリュームの左右の境界線の新しい値を受け取る
if(!GetVolumeBorders())
return(0);
}
//--- バーの計算に使用されるstart 変数
int start=prev_calculated;
//--- 指標値が前のティックで計算されている場合には最後のバーを使用する
if(start>0)
start--;
//--- 時系列に直接のインデックス作成を設定する
ArraySetAsSeries(time,false);
ArraySetAsSeries(open,false);
ArraySetAsSeries(high,false);
ArraySetAsSeries(low,false);
ArraySetAsSeries(close,false);
ArraySetAsSeries(tick_volume,false);
//--- 指標値の計算ループ
for(int i=start;i<rates_total;i++)
{
//--- 最初の日からローソク足に必要事項を記入する
if(ExtStartTime<=time[i])
{
//--- 値が右の境界以上であれば、ローソク足に必要事項を記入する
if(tick_volume[i]>=ExtRightBorder)
{
//--- ローソク足を描画するためのデータを受信する
ExtOpenBuff[i]=open[i];
ExtHighBuff[i]=high[i];
ExtLowBuff[i]=low[i];
ExtCloseBuff[i]=close[i];
//--- DodgerBlue 色
ExtColorBuff[i]=0;
//--- ループを続行する
continue;
}
//--- 値が左の境界線を超えていない場合にはローソク足に必要事項を記入する
if(tick_volume[i]<=ExtLeftBorder)
{
//--- ローソク足を描画するためのデータを受信する
ExtOpenBuff[i]=open[i];
ExtHighBuff[i]=high[i];
ExtLowBuff[i]=low[i];
ExtCloseBuff[i]=close[i];
//--- 橙色
ExtColorBuff[i]=1;
//--- ループを続行する
continue;
}
}
//--- 計算に含まれていないバーの空の値を設定する
ExtOpenBuff[i]=INDICATOR_EMPTY_VALUE;
ExtHighBuff[i]=INDICATOR_EMPTY_VALUE;
ExtLowBuff[i]=INDICATOR_EMPTY_VALUE;
ExtCloseBuff[i]=INDICATOR_EMPTY_VALUE;
}
//--- 次の呼び出しのために prev_calculated の値を返す
return(rates_total);
}
|