2021年3月30日 星期二

VCP pattern程式碼

 // VCP pattern(根據Minervini參數)

//目標是輕鬆找到緊縮到足以吸引購買的VCP pivot


//可調參數//////////////////////////////////////////////// /

{

Timeframe = 252; //一年內的交易。尋找成長股,通常是從新的ATH(all time high)開始

//上述概念也傾向於淘汰上方過多壓力overhead supply


VolTf= 50; // 50天的平均交易量(類似於大多數受IBD啟發的圖表)


//大多數良好的底部最多只能回撤30%。即使底部更深,也可能不是一個好選擇

//cheat pivots(3C patterns)會很接近底部

BaseLowerLimit= 0.7;


//Pivot length。最後一次收縮需要多長時間才能合格?

//如果再加上供應枯竭(dry-up),三天可能是絕對最少的時間

PivotLength= 5;


//Pivot的寬度多大才算得上Pivot? 6%似乎是高質量最終收縮的最佳選擇

//上限為10%

PVLimit= 0.10;

}


TickerName();


//過濾參數////////////////////////////////////////

{

//股票不應該再創新高,而是要接近新高

//基準的初始修正必須小於30%,但在動盪或熊市中可能會更大


//基本價格

//找到時間範圍內的最高價格

HighPrice = HHV(Cur , Timeframe);


//確保當前價格仍在基準範圍內,而在下方則不要過高

NearHigh  = Cur < HighPrice AND Cur  > BaseLowerLimit * HighPrice;


//平均交易量正在減少

//交易量必須收縮和/或低於平均水平,最好兩者都確保供應確實枯竭

//使用典型的50天平均值

Vma = MA(V, VolTf);//Volume moving average


//平均交易量線性回歸的負斜率應表明供應趨勢

VolSlope = LinRegSlope(Vma, VolTf);


//如果斜率為負,則交易量確實在減少

VolDecreasing = VolSlope < 0;



//Pivot質量

//最近幾天必須嚴格,<10%,如果可能的話,最好是小於6%,以便獲得緊密的進場點

//止損

//Pivot的高點應該在Pivot形成的第一天才能真正收縮

//低點可以出現在Pivot的任何位置

PivotHighPrice  = HHV(High, PivotLength);

//

SYNTAXhhv( ARRAY, periods )
RETURNSARRAY
FUNCTIONCalculates the highest value in the ARRAY over the preceding periods (periods includes the current day). HHV accepts periods parameter that can be constant as well as time-variant (array).
EXAMPLEThe formula "hhv( close, 4)" returns the highest closing price over the preceding four periods; "hhv( high, 8)" returns the highest high price over the preceding eight periods.

PivotLowPrice  = LLV(Low, PivotLength);

//

SYNTAXllv( ARRAY, periods )
RETURNSARRAY
FUNCTIONCalculates the lowest value in the ARRAY over the preceding periods (periods includes the current day). The function accepts periods parameter that can be constant as well as time-variant (array).
EXAMPLEThe formula "llv( close, 14 )" returns the lowest closing price over the preceding 14 periods.

PivotWidth     = (PivotHighPrice - PivotLowPrice)/Cur;

PivotStartHP   = Ref(High, -PivotLength +1);

//

SYNTAXRef( ARRAY, period )
RETURNSARRAY
FUNCTIONReferences a previous or subsequent element in a ARRAY. A positive period references "n" periods in the future; a negative period references "n" periods ago. The function accepts periods parameter that can be constant as well as time-variant (array).
EXAMPLEThe formula "ref( CLOSE, -14 )" returns the closing price 14 periods ago. Thus, you could write the 14-day price rate-of-change (expressed in points) as "C - ref( C, -14 )." The formula "ref( C, 12 )" returns the closing price 12 periods ahead (this means looking up the future)

IsPivot        = PivotWidth < PVLimit AND PivotHighPrice == PivotStartHP;


//現在,確保Pivot區域中的交易量確實變枯竭

//將初始值設置為true

VolDryUp = True;


//遍歷PivotLength天並確保交易量低於平均水平

for (i = 0; i < PivotLength; i++)

    VolDryup = VolDryup AND Ref(V, -i) < Ref(Vma, -i);

}


//過濾結果/////////////////////////////////////////////


Filter = NearHigh AND VolDecreasing AND IsPivot AND VolDryUp;


// EOF

沒有留言:

張貼留言