勝率を表示するインジゲーターを作っています。
しかし勝率を1日ごとにリセットさせたいのですが、OnTimerで試みましたが失敗しました
どのようなやり方が良いのかわからない状況です。ぜひ教えてください。
発生している問題・エラーメッセージ
'OnTimer' - function can be declared only in the global scope オリジナル.mq4 121 9
該当のソースコード
言語名
mql4
ソースコード
double BufSAR[];
double BufBuy[];
double BufSell[];
double Batsu[];
double Maru[];
int sum=0;
int win=0;
string text;
string original = "オリジナル";
extern int Corner = 0;
extern double LocationX = 0;
extern double LocationY = 20;
extern int FontSize = 10;
extern color FontColor = White;
int init()
{
SetIndexBuffer(0,BufSAR);
SetIndexBuffer(1,BufBuy);
SetIndexBuffer(2,BufSell);
SetIndexBuffer(3,Batsu);
SetIndexBuffer(4,Maru);
SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,2,Blue); SetIndexArrow(1,233); SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,2,Red); SetIndexArrow(2,234); SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,1,White); SetIndexArrow(3,251); SetIndexStyle(4,DRAW_ARROW,STYLE_SOLID,0.9,White); SetIndexArrow(4,162);
EventSetTimer(8);
return(INIT_SUCCEEDED);
}
int deinit(const int reason)
{
ObjectDelete(original);
EventKillTimer();
return(0);
}
int start()
{
int counted_bar = IndicatorCounted();
int limit = Bars-counted_bar;
if(counted_bar == 0) limit -= 1;//過去の変化しなかったバーが0の時、元々のlimitから1を引く for (int i = limit-1; i>=0; i--)//limit(計算してないバー)が1本以上ある時ループ処理 { BufSAR[i] = iSAR(NULL,0,0.02,0.2,i); } if(counted_bar == 0) limit -= 2; for (int i = limit-1; i>=0; i--) { BufBuy[i] = EMPTY_VALUE; if(BufSAR[i+1] >= Close[i+1] && BufSAR[i] <= Close[i] && Open[i]>Close[i] && Close[i+1]-Open[i+1] < Open[i]-Close[i]) { BufBuy[i] = Low[i]-20*Point; if(Open[i-1] < Close[i-2]){ Maru[i-2] = Low[i-2]-10*Point; win++; sum++; }else{ Batsu[i-2] = Low[i-2]-20*Point; if(Open[i-3]<Close[i-3]){ Maru[i-3] = Low[i-3]-10*Point; win++; sum++; }else{ Batsu[i-3] = Low[i-3]-10*Point; sum++; } } text="エントリー数"+sum+"勝率"+win*100/sum+"%";
}
BufSell[i] = EMPTY_VALUE;
if(BufSAR[i+1] <= Close[i+1] && BufSAR[i] >= Close[i] && Open[i] < Close[i] && Open[i+1]-Close[i+1] < Close[i]-Open[i])
{
BufSell[i] = High[i]+10Point;
if(Open[i-1] > Close[i-2]){
Maru[i-2] = Low[i-2]-10Point;
win++;
sum++;
}else{
Batsu[i-2] = Low[i-2]-10Point;
if(Open[i-3]>Close[i-3]){
Maru[i-3] = Low[i-3]-10Point;
win++;
sum++;
}else{
Batsu[i-3] = Low[i-3]-20Point;
sum++;
}
}
text="エントリー数"+sum+"勝率"+win100/sum+"%";
}
void OnTimer(){
printf("1日経過したので勝率をリセットします。");
win=0;
sum=0;
}
}
ObjectCreate(original, OBJ_LABEL, 0, 0, 0);
ObjectSetText(original, text, FontSize, "Terminal", FontColor);
ObjectSet(original, OBJPROP_XDISTANCE, LocationX);
ObjectSet(original, OBJPROP_YDISTANCE, LocationY);
ObjectSet(original, OBJPROP_CORNER, Corner);
return(0);
}
試したこと
OnTimerをstart()の外に書いてもリセット出来なかったです
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー