各位大大,請問這個威廉指標策略如何寫?
因為威廉指標沒有內建所以參考爬文的結果如下:_SECTION_BEGIN("William's % R");
SetChartOptions(0,0,chartGrid30|chartGrid70);
function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods ) );
}
Plot( PercentR( Param("Periods", 12, 2, 100 ) ),_DEFAULT_NAME(),ParamColor("Color", ColorCycle ) );
Plot( -30,_DEFAULT_NAME(),colorGreen );
Plot( -70,_DEFAULT_NAME(),colorGreen );
_SECTION_END();
好啦!問題來了!若是我現在想SCAN出威廉指標本身的數值與他自己的25日移動平均呈現黃金交叉。我的寫法是:
_SECTION_BEGIN("William's % R");
SetChartOptions(0,0,chartGrid30|chartGrid70);
function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods ) );
}
Plot( PercentR( Param("Periods", 12, 2, 100 ) ),_DEFAULT_NAME(),ParamColor("Color", ColorCycle ) );
Plot( -30,_DEFAULT_NAME(),colorGreen );
Plot( -70,_DEFAULT_NAME(),colorGreen );
_SECTION_END();
_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 25, 2, 200, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
Buy = Cross (PercentR( periods ), MA( PercentR( periods ) , 25 ) ) ;
可是,發現有些買進訊號並沒有在正常的位置。請問是否有哪位可以告訴我錯在哪裡。
你的MA好像畫錯了?
MA( P, Periods )
MA( PercentR( periods ) , 25 ) 本帖最後由 kilroy 於 14-2-26 20:21 編輯
Hi,
小弟這邊給大大範例
RequestTimedRefresh(1, onlyvisible = False);
_InitialEquity = 1000000;
_MaxPosition = 100;
_DoPositionSizing = 0;
_DayGap = abs(TimeFrameGetPrice("O",inDaily,0)-TimeFrameGetPrice("C",inDaily,-1));
_SECTION_BEGIN("Product Settings");
SetPositionSize(1, spsShares);
SetOption("MaxOpenPositions", 8);
SetOption("InitialEquity", _InitialEquity);
SetOption("FuturesMode", 1);
SetOption("CommissionMode", 3);
SetOption("CommissionAmount", 70);
RoundLotSize = 1;
//TXF_HOT
TickSize = 1;
MarginDeposit = 83000;
PS = 1;
PointValue = 200*PS;
DEC=0;
_SECTION_BEGIN("Background_Setting");
SetChartBkColor(1);
SetChartOptions(2,chartShowArrows|chartShowDates|chartWrapTitle);
SetChartBkGradientFill(1, 1, 1);
GraphXSpace = Param("Zoom/In Out", 100, -50, 150, 1);
dist = 5*ATR(12);
_SECTION_END();
_SECTION_BEGIN("Trading Rules");
barcomplete = BarIndex() < LastValue(BarIndex());
_SECTION_BEGIN("William's % R");
function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods ) );
}
//Plot( PercentR( Param("Periods", 12, 2, 100 ) ),_DEFAULT_NAME(),ParamColor("Color", ColorCycle ),styleOwnScale );
//Plot( -30,_DEFAULT_NAME(),colorGreen,styleOwnScale);
//Plot( -70,_DEFAULT_NAME(),colorGreen,styleOwnScale);
_SECTION_END();
Buy=Cross(PercentR(6),MA(PercentR(26),25)) AND barcomplete;
Short=Cross(MA(PercentR(26),25),PercentR(6)) AND barcomplete;
Buy = Cover = ExRem(Buy, Short);
Short = Sell = ExRem(Short, Buy);
Slippages1 = 5*TickSize;
Slippages2 = 5*TickSize;
BuyPrice = CoverPrice = C+Slippages1;
ShortPrice = SellPrice = C-Slippages2;
printf("\nBP %g",BuyPrice);
printf("\nSP %g",ShortPrice);
_SECTION_END();
_SECTION_BEGIN("Charts");
_N(Title = StrFormat(Name()+"- {{INTERVAL}} {{DATE}} \nOpen %g, Hi %g, Lo %g, Close %g (%.1f%%), Volume %g{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V));
PlotOHLC( O, H, L, C, "", IIf(C>O, colorRed, colorGreen), styleBar|styleNoLabel);
PlotShapes(IIf(Buy, 59, shapeNone), 7, 0, WMA(O, 1)-2*ATR(15), 6);
PlotShapes(IIf(Short, 60, shapeNone), 7, 0, WMA(O, 1)+2*ATR(15), 0);
_SECTION_END();
_SECTION_BEGIN("Index");
X = Param ("X - Left Up Corner", 1.55, 1, 3, 0.01);
Y = Param ("Y - Right Up Corner", 55, 30, 100, 1);
GfxSelectFont("Tahoma", Status("pxheight")/7*0.5 );
GfxSetTextAlign( 6 );
GfxSetTextColor( 2 );
GfxSetBkMode(0);
GfxTextOut( " "+C , Status("pxwidth")/X, Status("pxheight")/Y );
_SECTION_END();
參考看看吧~
頁:
[1]