多種止盈止損的統一處理函數 [開拓者 TB]
- 咨詢內容:
//------------------------------------------------------------------------
// 簡稱: DoPosition
// 名稱: 處理持倉部位
// 類別: 用戶函數
// 類型: 用戶函數
// 輸出: 字符串
//------------------------------------------------------------------------
Params
Numeric tradState(0); // 當前頭寸,1=多,-1=空
Numeric tradCyc(0); // 持倉周期數
Numeric curProfit(0); //持倉當前浮動盈虧
Numeric maxProfit(0); //持倉最大浮盈
Numeric stopLoss(0); //盈利低于此值時止損,為0不判斷
Numeric stopProfis(0); //盈利高于此值時止贏,為0不判斷
Numeric tracProfis(0); //盈利高于此值后執行追蹤止贏,為0不判斷
Numeric tracLoss(0); //追蹤止盈的回撤值,為0不判斷,盈利超過tracProfis后,從最大浮贏回撤tracLoss后止盈
Numeric returnProfis(0); //盈利高于此值后執行回撤止贏,為0不判斷
Numeric minProfis(0); //持倉bar數超過maxHoles后,盈利依然小于此值平倉,為0不判斷
Numeric maxHolds(0);//最多持倉bar數,為0不判斷
Numeric closeTime(1457); //持倉bar的時間超過此時間后清倉
Vars
String str(" ");
Begin
//-------------------------------處理持倉-------------------------------------------
if(tradState != 0 )
{
//價格止損:虧損超過stopLoss-------------------------------------------------
If(stopLoss>0)
{
If(curProfit<=(0-stopLoss) ) str = "止損平倉";
}
//時間止損:持倉超過maxHolds后最大浮動盈虧在正負minProfis之間------------------------------
If(minProfis>0 And maxHolds>0)
{
If(curProfit<=minProfis And tradCyc>=maxHolds ) str = "超時未達盈利平倉";
}
//超時平倉--------------------------------------------------------------
If(closeTime>100)
{
If(Time>=0.0001*closeTime) str = "超過清倉時間平倉";
}
//停板平倉-----------------------------------------------
If(BarStatus==2)
{
if(High==Q_UpperLimit() Or Low==Q_LowerLimit()) str = "停板平倉";
}
Else
{
if(High==Low And High==Close And High[1]==Low[1] And High[2]==Low[2]) str = "停板平倉";
}
//價格止盈:盈利超過stopProfis-----------------------------------------------
If(stopProfis>0)
{
If(curProfit>=stopProfis ) str = "止盈平倉";
}
//跟蹤止盈:盈利超過tracProfis后回撤超過tracLoss平倉---------------------------
If(tracLoss>0 And tracProfis>0)
{
If((maxProfit-curProfit)>=tracLoss And maxProfit>tracProfis) str = "跟蹤止盈平倉";
}
//回撤止盈:盈利超過returnProfis后回撤平倉-------------------------------------
If(returnProfis>0 And maxProfit>0.9*returnProfis)
{
If(maxProfit>0.9*returnProfis And maxProfit<=1.1*returnProfis And curProfit<=0.1*maxProfit) str = "盈利回撤止盈平倉1倍90%";
If(maxProfit>1.1*returnProfis And maxProfit<=2*returnProfis And curProfit<=0.5*maxProfit) str = "盈利回撤止盈平倉1-2倍50%";
If(maxProfit>2*returnProfis And maxProfit<=3*returnProfis And curProfit<=0.6*maxProfit) str = "盈利回撤止盈平倉2-3倍40%";
If(maxProfit>3*returnProfis And maxProfit<=4*returnProfis And curProfit<=0.7*maxProfit) str = "盈利回撤止盈平倉3-4倍30%";
If(maxProfit>4*returnProfis And maxProfit<=5*returnProfis And curProfit<=0.8*maxProfit) str = "盈利回撤止盈平倉4-5倍20%";
If(maxProfit>6*returnProfis And curProfit<=0.9*maxProfit) str = "盈利回撤止盈平倉大于6倍10%";
}
}
Return str;
End
//------------------------------------------------------------------------
// 編譯版本 GS2004.06.12
// 用戶版本 2009/04/15 21:11
// 版權所有 fish0451
// 更改聲明 TradeBlazer Software保留對TradeBlazer平臺
// 每一版本的TrabeBlazer公式修改和重寫的權利
//------------------------------------------------------------------------ - TB技術人員:
是用戶函數,配合“較完善的日內交易系統框架”使用,注意返回值是“字符串”
- TB客服:
離樓主很近
沙個發 - 網友回復:
頂樓主,
好久沒有見到這么勇于共享的人了。 - 網友回復:
頂一個,好貼!!! 頂一個,好貼!!!
如果以上指標公式不適用于您常用的行情軟件
或者您想改編成選股公式,以便快速選出某種形態個股的話,
相關文章
-
沒有相關內容