小幫手好:
我想在日K上只秀出第一次觸發的指標訊號(之後符合條件的日K不再顯示),已閱讀過這篇
但仍寫不太出來。
想請小幫手幫忙,謝謝
Hello bill666,
您可以參考 intrabarpersist 的說明。
由於是使用在日頻率上,所以每次洗價都會是在同根Bar上,故要使用此語法來宣告變數,才能夠讓變數保存同根Bar洗價間的運算。
舉例來說:
var: intrabarpersist _first(0);
condition1 = 條件;
if _first <> currentbar and condition1 then begin
...第一次符合要執行的腳本...
_first = currentbar;
end;
小幫手好,
value1=barslast(average(close,5) cross over average(close,10));
condition2 = close>high[value1];
if _first <> currentbar and condition2 then begin
plot1(close);
_first = currentbar;
end;
我想僅標示出 收盤價>上次均線交叉時的K棒的收盤價,但以上述寫法會連續plot多個K棒,想請問如何解決?
謝謝
如果是要日K上面根據所需邏輯,只畫第一次觸發的訊號,可以試試這個:
// 腳本運行一開始 _first = 0
var: IntrabarPersist _first(0);
value1=barslast(average(close,5) cross over average(close,10));
condition2 = close>high[value1];
// 先檢查 _first 是否不等 0,只要不等於就代表已經不是第一次觸發
if _first = 0 then NoPlot(1) else
// 進到這段代表 _first = 0,訊號還沒觸發過,這時才檢查你要的條件 condition2 是否符合
if condition2 then begin
plot1(close);
_first = 1;
end;
iker你好
謝謝你的回答,我將你示範的code貼上,但顯示plot1 N/A
我還在想怎麼寫出
抱歉我上面條件寫錯,把不等於寫成了等於。你再試試看。
// 腳本運行一開始 _first = 0
var: IntrabarPersist _first(0);
value1=barslast(average(close,5) cross over average(close,10));
condition2 = close>high[value1];
// 先檢查 _first 是否不等 0,只要不等於就代表已經不是第一次觸發
if _first <> 0 then NoPlot(1) else
// 進到這段代表 _first = 0,訊號還沒觸發過,這時才檢查你要的條件 condition2 是否符合
if condition2 then begin
plot1(close);
_first = 1;
end;
Hello bill666,
小幫手誤會您的需求了,如果是這樣的話其實也並不需要使用 intrabarpersist。
您可以用個簡單的方法來判別,第一次符合條件 => 當根Bar條件成立,前一根Bar條件不成立。
所以這樣寫:
value1=barslast(average(close,5) cross over average(close,10));
condition2 = close>high[value1];
if condition2 and condition2[1] = False then plot1(close);
這樣就可以只標示出連續符合條件時的第一次觸發。
若是整個腳本運算期間只標示出一根的話,那麼在用變數來記錄處理。
舉例來說:
value1=barslast(average(close,5) cross over average(close,10));
condition2 = close>high[value1];
if condition2 and condition2[1] = False and value2 = 0 then begin
plot1(close);
value2 = 1;
end;
這樣整段計算區間就只會標示出第一次觸發。
Hi Billbird13
想請問你是用小幫手的哪一種方式解決的呢?
看起來第二種方式只是加上了 condition2[1] = false,如果這個能正常運作,原本的寫法應該也要可以正常才是
8 評論