COCO研究院

 找回密碼
 註冊
搜索
查看: 2124|回復: 2

各位大大,請問這個威廉指標策略如何寫?

[複製鏈接]
發表於 14-2-26 14:38 | 顯示全部樓層 |閱讀模式
因為威廉指標沒有內建所以參考爬文的結果如下:
_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 ) ) ;

可是,發現有些買進訊號並沒有在正常的位置。請問是否有哪位可以告訴我錯在哪裡。


發表於 14-2-26 19:37 | 顯示全部樓層
你的MA好像畫錯了?
MA( P, Periods )
MA( PercentR( periods ) , 25 )
發表於 14-2-26 20:07 | 顯示全部樓層
本帖最後由 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金錢 +2 收起 理由
Winson + 2 受教了

查看全部評分

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-11-3 06:52

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |