請ALEX幫忙看看階梯止損 [MC]
-
MC用戶求助:
if bb cross over cc? then begin
? ? ? ? buy next bar at market;
? ? ? ? buyexit1=lowest(low,2);
end;
value1=highest(high,barsSinceEntry(0));
if value1>value1[1] then
? ? ? ? buyexit1=lowest(low,2);
if marketposition>0 and close cross under buyexit1 then sell next bar at market;
if bb cross under cc? then begin
? ? ? ? sellshort at next bar market;
? ? ? ? buyexit2=highest(high,2);
end;
value2=lowest(low,barsSinceEntry(0));
if value2>value2[1]
then buyexit2=highest(high,2);
if marketposition<0 and close cross above buyexit2 then buytocover next bar at market;
對您的代碼進行了簡單的優化,其中有以下幾個問題:
第一、barssinceentry(0)[1]和barssinceentry(0)的返回值是一樣的,所以可以通過變量先存儲該關鍵字的返回值,然后再回溯。
第二、highest(high,barsSinceEntry(0))>highest(high,barsSinceEntry(0))[1]和value1=highest(high,barsSinceEntry(0)); value1>value1[1]; 的區別在于,highest(high,barsSinceEntry(0))[1]在基于前一根bar回溯比較barssincenentry(0)根bar的最高價。
第三、highest(high,barsSinceEntry(0))在執行中,會隨著barssinceentry(0)的值的增大,而使函數對歷史數據的回溯范圍增大,可能會超出策略屬性中設置的最大bar設置值。
第四、若您基于5分鐘周期,需要使用30周期的數據,比如基于30分鐘周期的20日均線,那么一種方法是通過調用子圖的方法,正如樓上所說的,另一種方法是,直接在5分鐘周期上使用120日均線。
?
-
MC回復討論一:
if bb cross over cc? then begin
? ? ? ? buy next bar at market;
? ? ? ? buyexit1=lowest(low,2);
end;
value1=highest(high,barsSinceEntry(0));
if value1>value1[1] then
? ? ? ? buyexit1=lowest(low,2);
if marketposition>0 and close cross under buyexit1 then sell next bar at market;
if bb cross under cc? then begin
? ? ? ? sellshort at next bar market;
? ? ? ? buyexit2=highest(high,2);
end;
value2=lowest(low,barsSinceEntry(0));
if value2>value2[1]
then buyexit2=highest(high,2);
if marketposition<0 and close cross above buyexit2 then buytocover next bar at market;
對您的代碼進行了簡單的優化,其中有以下幾個問題:
第一、barssinceentry(0)[1]和barssinceentry(0)的返回值是一樣的,所以可以通過變量先存儲該關鍵字的返回值,然后再回溯。
第二、highest(high,barsSinceEntry(0))>highest(high,barsSinceEntry(0))[1]和value1=highest(high,barsSinceEntry(0)); value1>value1[1]; 的區別在于,highest(high,barsSinceEntry(0))[1]在基于前一根bar回溯比較barssincenentry(0)根bar的最高價。
第三、highest(high,barsSinceEntry(0))在執行中,會隨著barssinceentry(0)的值的增大,而使函數對歷史數據的回溯范圍增大,可能會超出策略屬性中設置的最大bar設置值。
第四、若您基于5分鐘周期,需要使用30周期的數據,比如基于30分鐘周期的20日均線,那么一種方法是通過調用子圖的方法,正如樓上所說的,另一種方法是,直接在5分鐘周期上使用120日均線。
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯系技術人員 QQ: 511411198 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容