咨詢內容:
策略倉位管理
策略引用商品指數日線跨周期數據指標DMI+AXD>(55)同時 下穿-AXD 平倉(止盈多空全部平)/或其他指標
1:止盈條件平倉 (比如止盈條件DMI)
2:止盈條件平倉后特別標記平倉方向!多單平倉后只能開空單,空單開出后取消限制條件。多空同樣原理。
這個代碼要怎么實現呢?
?
?來源: m.kzuj.com.cn
金字塔資深技術:
1.跨指標引用參考:
http://www.weistock.com/bbs/dispbbs.asp?boardid=17&Id=162644
參考這個函數說明
2.用全局變量處理。在每次止盈平倉后,重置全局變量的值。后續開倉都要先判斷下這個全局變量的值。
[PEL]
復制代碼ma3:ma(close,3);
ma5:ma(c,5);
ma10:ma(close,10);
kd:cross(ma3,ma5);
kk:cross(ma10,ma5);
VARIABLE:ct:=0;
if kd and ct>=0 and holding=0 then
begin
buy(1,1,market);
ct:=0;
end
if kk and ct<=0 and holding=0 then
begin
buyshort(1,1,market);
ct:=0;
end
if (c-AVGENTERPRICE)>=5*MINDIFF and holding>0 then
begin
多止盈:sell(1,0,market);
ct:=-1;
end
if (AVGENTERPRICE-c)>=5*MINDIFF and holding<0 then
begin
空止盈:sellshort(1,0,market);
ct:=1;
end
參考這里全局變量的使用
技術交流:
if kd and ct>=0 and holding=0 then
begin
buy(1,1,market);
ct:=0;
end
if kk and ct<=0 and holding=0 then
begin
buyshort(1,1,market);
ct:=0;
end
這個里面的 CT>=0和CT<=0 ,這個沒有看懂,后面的多止盈和空止盈的話,跟我的根據商品指數引用編寫代碼一模板一樣的嗎?,
?
技術交流:
ct>=0 意思是開倉條件默認需要滿足:1.首次開倉 。ct自然是0? ???2.前面ct是1 說明多止盈了,-1 是空止盈了。
“跟我的根據商品指數引用編寫代碼一模板一樣的嗎?” 我這個止盈條件隨便寫的。你只要改成你自己的止盈條件就行了。