反应趋势交易系统(RTS)
本帖最后由 duck_arrow 于 2014-10-29 13:33 编辑最近市场可能比较震荡,农产品有许多震荡交易系统比较适用!所以在研究反应趋势交易系统(RTS)即The Reaction Trend System 由J.WELLES WILDER发明。本人粗糙简略地写了下代码:Params
Numeric NumATRs(1);
Numeric ATRLength(10);
//Track Stop Profit or Loss
Numeric StopATRLength(10);
Numeric StopLossPcnt(3); //价格止损控制
Numeric InitialStop(2); // 初始止损
Numeric BreakEvenStop(2); // 保本止损
Numeric TrailStop(2); // 追踪止损,回撤ATR的倍数
//PriceOffset
Numeric Offset(10);
Vars
NumericSeries TPrice;
//Track Stop Loss or Profit
NumericSeries HigherAfterEntry;
NumericSeries LowerAfterEntry;
NumericSeries HighestAfterEntry;
NumericSeries LowestAfterEntry;
BoolSeries bLongTrailingStoped;
BoolSeries bShortTrailingStoped;
Numeric MyExitPrice; // Exit Market Price
//Stop Position
Numeric MyPrice;
Numeric MinPoint; // 一个最小变动单位,也就是一跳
Numeric StopLine;
Numeric StopLossBuffSet(15); //止损位Buffer
NumericSeries ATRValue; //记录ATR值
Numeric PriceOffset; //Buy or Sell Price Buffer
//RTS Variables
Numeric HBOP; //高价突破点
Numeric LBOP; //低价突破点
Numeric SellPoint; //卖点
Numeric BuyPoint; //买点
Begin
//Price Offset
PriceOffset = Offset * MinMove * PriceScale;
//Track Stop Profit or Loss
MinPoint = MinMove*PriceScale;
ATRValue = AvgTrueRange(StopATRLength);
//KeltnerChannel Variables
TPrice = (High + Low + Close)/3;
HBOP = 2 * TPrice - 2 * Low + High;
LBOP = 2 * TPrice - 2 * High + Low;
SellPoint = TPrice * 2 - Low; // Sell Point
BuyPoint = TPrice * 2 - High; //Buy Point
PlotNumeric("HBOP",HBOP);
PlotNumeric("LBOP",LBOP);
PlotNumeric("SellPoint", SellPoint);
PlotNumeric("BuyPoint", BuyPoint);
If (Open < HBOP And Open > LBOP)
{
//Long Futures High greater than UpperBand
If(MarketPosition != 1 And High > BuyPoint)
{
MyPrice = BuyPoint;
If(Open > MyPrice) MyPrice = Open;
//Buy(1, Q_BidPrice + PriceOffset);
//Buy(1, MyPrice + PriceOffset);
SellShort(1, MyPrice - PriceOffset);
}
//Short Futures Low less than LowerBand
If(MarketPosition != -1 And Low < SellPoint)
{
MyPrice = SellPoint;
If(Open < MyPrice) MyPrice = Open;
//SellShort(1, Q_AskPrice - PriceOffset);
//SellShort(1, MyPrice - PriceOffset);
Buy(1, MyPrice + PriceOffset);
}
} Else If(Open > HBOP) {
//Long Futures High greater than UpperBand
If(MarketPosition != 1)
{
MyPrice = HBOP;
If(Open > MyPrice) MyPrice = Open;
//Buy(1, Q_BidPrice + PriceOffset);
Buy(1, MyPrice + PriceOffset);
}
} Else If(Open < LBOP) {
//Short Futures Low less than LowerBand
If(MarketPosition != -1)
{
MyPrice = LBOP;
If(Open < MyPrice) MyPrice = Open;
//SellShort(1, Q_AskPrice - PriceOffset);
SellShort(1, MyPrice - PriceOffset);
}
}
/* Set Loss Postion */
MinPoint = MinMove * PriceScale;
Myprice = EntryPrice * (1 - StopLossPcnt * 0.01);
If(MarketPosition==1 and Low <= Myprice and BarsSinceEntry>0)
{
Myprice=Min(Myprice,Open);
Sell(0, Myprice - stopLossBuffSet * MinPoint);
Commentary("Price Pcnt Stop Loss");
}
Myprice = EntryPrice * (1 + StopLossPcnt * 0.01);
If(MarketPosition==-1 and High>=Myprice and BarsSinceEntry>0)
{
Myprice=Max(Myprice,Open);
BuyToCover(0, Myprice + stopLossBuffSet * MinPoint);
Commentary("Price Pcnt Stop Loss");
}
/* Set Loss Postion */
End代码中应该还需要计算Buy Day(B), Sell Dya(S), 还有Oday。但是不知道如何计算得出当前Bar应该是 B or S or O。如果得出当前Bar是 B就做Long操作。如果是S就做Short操作。本人在恒温器策略中得到启示见原帖:http://bbs.tb18.net/thread-24916-1-1.html
恒温器中是这样确定的。
keyofday=(HighD(0)+LowD(0)+CloseD(0))/3;
If(Date<>Date){
If(CloseD(1)>keyofday)
{
selleasierday=1;//空头日
}Else{
buyeasierday=1;//多头日
}
希望大家给点建议!!! 先顶了 再看 牛! 不理想
页:
[1]