|
*
如果是單純圖表上的顯示以及計算加碼口數的部分
小弟這邊提供一個簡單的範例好了~
---
基本單進場條件為收盤同時站上兩條均線
加碼單進場條件為基本單進場後之短均線向上 100點進場
空單反之亦然
---
圖中 ① 為基本單進場 ② 為加碼單
*右下角顯示目前倉位
---
範例程式 for 30min
- _SECTION_BEGIN("Background_Setting");
- SetChartBkColor(1);
- SetChartOptions(2,chartShowArrows|chartShowDates|chartWrapTitle);
- SetChartBkGradientFill(1, 1, 1);
- GraphXSpace = Param("Zoom/In Out",100,-50,150,1);
- _SECTION_END();
- _SECTION_BEGIN("Backtest Setting");
- SetPositionSize(1, spsShares);
- SetOption("InitialEquity", 1000000);
- SetOption("CommissionMode", 3);
- SetOption("CommissionAmount", 1000);
- RoundLotSize = 1;
- PointValue = 200;
- _SECTION_END();
- _SECTION_BEGIN("Trading Rules");
- barcomplete = BarIndex() < LastValue(BarIndex());
- Length1 = 30;
- Length2 = 300;
- Mae1 = AMA( C, 2 / (length1 + 1 ) );
- Mae2 = AMA( C, 2 / (length2 + 1 ) );
- Plot(Mae1, "", 7, 1);
- Plot(Mae2, "", 6, 1);
- Buy = C>MAe1 AND C>MAe2 AND barcomplete;
- Short = C<MAe1 AND C<MAe2 AND barcomplete;
- BuyPrice = CoverPrice = C;
- ShortPrice = SellPrice = C;
- Buy = Cover = ExRem(Buy, Short);
- Short = Sell = ExRem(Short, Buy);
- P1 = IIf(Buy, 1, IIf(Short, -1, 0));
- P1 = ValueWhen(P1!=0, P1, 1);
- SEntry = ValueWhen(Buy OR Short, MAe1, 1);
- addBuy = C>SEntry+100;
- addShort = C<SEntry-100;
- addBuy = ExRem(addBuy , Short);
- addShort = ExRem(addShort , addBuy );
- P2 = IIf(addBuy , 1, IIf(addShort , -1, 0));
- P2 = ValueWhen(P2!=0, P2, 1);
- CP =
- IIf(Buy AND Ref(P1+P2, -1) == -2, 1,
- IIf(Short AND Ref(P1+P2, -1) == 2, -1,
- IIf(Short AND Ref(P1, -1) == 1, -1,
- IIf(Buy AND Ref(P1, -1) == -1, 1,
- IIf(addBuy AND P1 == P2, 2,
- IIf(addShort AND P1 == P2, -2, 0))))));
- CurrentPosition = ValueWhen(CP !=0, CP, 1);
- _SECTION_END();
- _SECTION_BEGIN("Charts");
- SetBarFillColor(IIf(O>C,19,24));
- PlotOHLC(O,H,L,C,"",IIf(O>C,34,32),64+4096);
- PlotShapes(IIf(Buy, shapeDigit1, shapeNone), 9, 0, WMA(O,10)-2*ATR(15), 6);
- PlotShapes(IIf(Short, shapeDigit1, shapeNone), 10, 0, WMA(O,10)+2*ATR(15), 0);
- PlotShapes(IIf(addBuy , shapeDigit2, shapeNone), 9, 0, WMA(O,10)-2*ATR(15), 6);
- PlotShapes(IIf(addShort , shapeDigit2, shapeNone), 10, 0, WMA(O,10)+2*ATR(15), 0);
- _SECTION_END();
- _SECTION_BEGIN("Position");
- GfxSelectFont("Tahoma", Status("pxheight")/7*0.5 );
- GfxSetTextAlign( 6 );
- GfxSetBkMode(0);
- GfxSelectFont("Tahoma", Status("pxheight")/7*0.2 );
- GfxSetTextColor( 3 );
- GfxTextOut( " Position: "+CurrentPosition, Status("pxwidth")/1.35, Status("pxheight")/(55*0.02));
- _SECTION_END();
複製代碼
---
不過如果是跑 AB 裡的 automatic analyisis
只能跑 buy 和 short 這一組(基本單)進場的回測
如果也要回測加碼單的部分,建議還是分開來寫會比較恰當囉
在 AB 裡是頗麻煩的
參考看看了
補充內容 (13-2-12 11:53):
對了,範例中 C>MAe1+100 這裡,如果要自動下單,請改為H>MAe1+100,另一個為L<MAe1-100。這樣訊號才不會跳動。 |
評分
-
查看全部評分
|