//+------------------------------------------------------------------+
//| スクリプトプログラムを開始する関数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 補助配列
double high[],low[],price1,price2;
datetime time[],time1,time2;
//--- 始値のコピー - 最新の100バーで充分
int copied=CopyHigh(Symbol(),0,0,100,high);
if(copied<=0)
{
Print("Failed to copy the values of the High price series");
return;
}
//--- 終値のコピー - 最新の100バーで充分
copied=CopyLow(Symbol(),0,0,100,low);
if(copied<=0)
{
Print("Failed to copy the values of the Low price series");
return;
}
//--- 最後の100バーの始値を複製する
copied=CopyTime(Symbol(),0,0,100,time);
if(copied<=0)
{
Print("Failed to copy the values of the price series of Time");
return;
}
//--- 複製されたデータへのアクセスを時系列のように(反対に)整理する
ArraySetAsSeries(high,true);
ArraySetAsSeries(low,true);
ArraySetAsSeries(time,true);
//--- フィボナッチオブジェクトの初めのアンカーポイントの座標
price1=high[70];
time1=time[70];
//--- フィボナッチオブジェクトの2 番目のアンカーポイントの座標
price2=low[50];
time2=time[50];
//--- フィボナッチオブジェクトを作成する
bool created=ObjectCreate(0,"Fibo",OBJ_FIBO,0,time1,price1,time2,price2);
if(created) // オブジェクト作成が成功した場合
{
//--- フィボナッチレベルの色を設定する
ObjectSetInteger(0,"Fibo",OBJPROP_LEVELCOLOR,Blue);
//--- フィボナッチレベルの数を見つける
int levels=ObjectGetInteger(0,"Fibo",OBJPROP_LEVELS);
Print("Fibo levels before = ",levels);
//---操作ログに出力 => number of level:value level_desription
for(int i=0;i<levels;i++)
{
Print(i,": ",ObjectGetDouble(0,"Fibo",OBJPROP_LEVELVALUE,i),
" ",ObjectGetString(0,"Fibo",OBJPROP_LEVELTEXT,i));
}
//--- 単位当たりのレベルの数の増加を試みる
bool modified=ObjectSetInteger(0,"Fibo",OBJPROP_LEVELS,levels+1);
if(!modified) // レベル数の変更に失敗
{
Print("Failed to change the number of levels of Fibo, error ",GetLastError());
}
//--- 情報のみ
Print("Fibo levels after = ",ObjectGetInteger(0,"Fibo",OBJPROP_LEVELS));
//--- 新しく作成したレベルの値を設定する
bool added=ObjectSetDouble(0,"Fibo",OBJPROP_LEVELVALUE,levels,133);
if(added) // レベルに値を設定することができた
{
Print("Successfully set one more Fibo level");
//--- レベル説明を忘れずに設定
ObjectSetString(0,"Fibo",OBJPROP_LEVELTEXT,levels,"my level");
ChartRedraw(0);
//--- フィボナッチオブジェクトの実際のレベル数を取得する
levels=ObjectGetInteger(0,"Fibo",OBJPROP_LEVELS);
Print("Fibo levels after adding = ",levels);
//--- 確認のためにもう一度全レベルを出力する
for(int i=0;i<levels;i++)
{
Print(i,":",ObjectGetDouble(0,"Fibo",OBJPROP_LEVELVALUE,i),
" ",ObjectGetString(0,"Fibo",OBJPROP_LEVELTEXT,i));
}
}
else // フィボナッチオブジェクトのレベル数を増加しようとすると失敗する
{
Print("Failed to set one more Fibo level. Error ",GetLastError());
}
}
}
|