生猛海鮮 發表於 09-12-15 19:38

哇靠,寫蝦米,看攏某。{:4_142:}

綠茶妹 發表於 09-12-15 20:21

希望能有更多AB達人,
才能讓高手不寂寞。
michael大真是太神了。

hkcarnby 發表於 09-12-25 18:14

網上有沒有利佛摩操盤手法的ab程式?

綠茶妹 發表於 09-12-26 20:07

李佛摩爾用突破法,
請問有詳細的公式嗎?
這樣子才能轉成AB程式。

TrendRover 發表於 10-1-5 21:45

回復 36# 綠茶妹


   
從海洋 Multichart ZONE copy paste a doc file .

只有TS CODE 不知這是不是LIVERMORE 精神 還沒詳細讀CODE.

我不太熟AB CODING 就靠你們了 .
    這些日子 AB C# RE OQ MC 在一個月內 SURVEY 完 眼睛都快 更老花了
    AB manual 是K 不下了 晚個幾個月再回頭 K
    以前 對 MC 觀念是 BUG 一堆 ( SOMEBODY POST in forum somewhere )
    不知現在是否依然故我 ??

綠茶妹 發表於 10-1-5 21:54

本帖最後由 綠茶妹 於 10-1-5 09:55 PM 編輯

謝謝分享!
ab的範例我覺得不夠多,
尤其是交易策略的部份。
我現在看到的afl程式都只是單一的程式,有點像畫圖功能。
但是自動回測的範例好少。

hkcarnby 發表於 10-1-5 23:06

這個file黃金鼠大大懂不懂轉成ab?

黃金鼠 發表於 10-1-6 12:53

耳朵好癢,有人叫我。
我不會轉成AB。我會看圖說故事。
下面註解的中文字是我寫的。


{
{這種符號是註解}
Livermore Market Method Signal
Ref: Chapters VIII & IX of "How to Trade in Stocks", Jesse L. Livermore

v1 ghkramer - 5Oct03
v1.1 ghkramer - 11Oct03, Added switch to deactive Rule 10 logic
===============
Program Overview

This program classifies price action into the following states based upon
rules in Ref:

- Up Trend
- Natural Rally
- Secondary Rally
- Down Trend
- Natural Reaction
- Secondary Reaction

State change is determined by a user specified threshold of price change.
The program also determines a number of pivot points:

- Peak Up Trend Price
- Peak Natural Rally Price
- Bottom Down Trend Price
- Bottom Natural Reaction Price
- Key Price (requires two stocks, i.e., 2 or more data streams (Rule 7), not yet implemented)

This program may be used as a basis for a number of studies:
- trend paint bars,
- pivot price indicator lines
- strategies (trend following and/or breakout/breakdown)

For a detailed explanation of the system see Ref.



This program reflects the author's interpretation of Livermore's writing.
There is no guarantee the this program accurately or fully incorporates
Livermore's Market Key system.
}


input: PtsPctATR(0), Threshold(6), ATRLength(14), TradeTrends(1);
{輸入變成有4個,要最佳化時可以用這個變數來跑。}
{ PtsPctATR: 0 for Threshold in points,
1 for Threshold in Percent
2 for Threshold in multiples of ATR

Threshold: in Points (if PtsPct = 0)
in Percent (if PtsPct = 1)
in ATR Multiples (if PtsPct = 2)

ATRLength(14) : only used when PtsPctATR = 2

TradeTrends: 1 = Trade Up and Down Trends only
0 = Long for Up Trends and Rallies, Short for Dn Trends and Reactions

Note: Livermore's system used a threshold of 6 points for stocks priced over $30.
This is the default (PtsPctATR = 0, Threshold = 6).

}

var:
{內部變數}
SecondaryRally(0), NaturalRally(0), UpTrend(0),
SecondaryReaction(0), NaturalReaction(0), DnTrend(0),
DnTrendBL(0), NaturalRallyBL(0), {BL = Black Line}
UpTrendRL(0), NaturalReactionRL(0), {RL = Red Line}
InSecRally(false), InNatRally(false), InUpTrend(false),
InSecReact(false), InNatReact(false), InDnTrend(false),
ResumeUpTrend(false), ResumeDnTrend(false),
MA10(0), Thresh(0), HalfThresh(0),
UseRule10(false), {set to true to use Livermore's Rule 10, note: system may become unstable}
Debug(false); {set to true for output}



{initialization}
{初始化部份}
if (CurrentBar = 1) then
begin
if (PtsPctATR = 0) {use Points} then
begin
Thresh = HalfThresh ;
HalfThresh = Thresh/2;
{HalfThresh的數值等於HalfThresh除以2}
end;
SecondaryRally = Close;
NaturalRally = Close;
UpTrend = Close;
SecondaryReaction = Close;
NaturalReaction = Close;
DnTrend = Close;
{然後這一串變數,都初始化為今天的收盤價}
end;


if (CurrentBar <= 21) then {initialization continued}
begin
MA10 = Average(Close, 10);
{MA10的數值為今天的10日收盤平均價}
if (CurrentBar = 21) then
begin
if (MA10 > MA10) then {assume UpTrend}
{奇怪了..MA10和MA10 有何不同?看不懂}
begin
InUpTrend = true;
{這種情況下,我們設InUpTrend為"真",即突破的上升趨勢}
UpTrend = C;
end
else {assume DnTrend}
begin
InDnTrend = true;
DnTrend = C;
end;
end;
end
else {Main}
begin {calc current Threshold if required}
if (PtsPctATR = 1) then {use Percent change Thresh, calc on every bar }
begin
Thresh = Threshold*Close/100;
HalfThresh = Thresh/2;
end
else if (PtsPctATR = 2) then {use ATR multiples for Thresh, calc on every bar }
begin
Thresh = Threshold*AvgTrueRange(14);
{Thresh為Threshold乘上14天的ATR}
HalfThresh = Thresh/2;
end;


{Process by Current State}


{------Up Trend State-------}
if InUpTrend then
begin
if (Close > (NaturalReaction + Threshold)) then
NaturalReactionRL = NaturalReaction; {Rule 4b}
if ResumeUpTrend then {Rule 10 logic. Note: system becomes unstable if used}
begin
if (Close > (UpTrendRL + HalfThresh)) then
begin
ResumeUpTrend = false; {Rule 10a}
UpTrend = Close;
if Debug then print(date, Close, " Node 1", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close < (UpTrendRL - HalfThresh)) then {UpTrend Over, return to NaturalReaction}
begin
ResumeUpTrend = false;
InUpTrend = false; {Rule 10b}
InNatReact = true;
NaturalReaction = Close;
if Debug then print(date, Close, " Node 2", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end;
end
else if (Close < (UpTrend - Thresh)) then {start NaturalReaction}
begin {Rules 4a, 6a}
InUpTrend = false;
InNatReact = true;
NaturalReaction = Close;
UpTrendRL = UpTrend; {Pivot Pt, Rule 8}
ResumeUpTrend = false;
if Debug then print(date, Close, " Node 3", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close > UpTrend) then {remain in UpTrend, record higher price}
UpTrend = Close; {Rule 1, 4b, 6d}
end {InUpTrend}


{------Natural Rally State-------}
else if InNatRally then
begin
if (Close > (NaturalReaction + Threshold)) then
NaturalReactionRL = NaturalReaction; {Rule 4b}
if (Close > UpTrend) then {resume UpTrend}
begin {Rules 6d, 6f}
InUpTrend = true;
InNatRally = false;
UpTrend = Close;
if UseRule10 then ResumeUpTrend = true;
if Debug then print(date, Close, " Node 4", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close > (NaturalRallyBL + HalfThresh)) then {resume UpTrend}
begin {Rules 5a}
InUpTrend = true;
InNatRally = false;
UpTrend = Close;
if UseRule10 then ResumeUpTrend = true;
if Debug then print(date, Close, " Node 5", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close < DnTrend) then {start DnTrend}
begin {Rule 6b}
InNatRally = false;
InDnTrend = true;
DnTrend = Close;
NaturalRallyBL = Close; {rule 4d}
if Debug then print(date, Close, " Node 6", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close < (NaturalRally - Thresh)) then
begin
if (Close < NaturalReaction) then {start NaturalReaction}
begin {Rules 4d, 6b}
InNatRally = false;
InNatReact = true;
NaturalReaction = Close;
NaturalRallyBL = Close; {rule 4d} {Pivot Pt, Rule 9b}
if Debug then print(date, Close, " Node 7", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else {start SecondaryReaction}
begin {Rule 6h}
InNatRally = false;
InSecReact = true;
SecondaryReaction = Close;
if Debug then print(date, Close, " Node 8", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end;
end
else if (Close > NaturalRally) then {remain in NaturalRally, record higher price}
NaturalRally = Close; {Rule 3, 6c, 6d}
end {InNatRally}


{------Secondary Rally State-------}
else if InSecRally then
begin
if (Close > UpTrend) then {resume UpTrend}
begin {Rules 6d, 6f}
InUpTrend = true;
InSecRally = false;
UpTrend = Close;
if UseRule10 then ResumeUpTrend = true;
if Debug then print(date, Close, " Node 9", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close > (NaturalRallyBL + HalfThresh)) then {resume UpTrend}
begin {Rules 5a}
InUpTrend = true;
InSecRally = false;
UpTrend = Close;
if UseRule10 then ResumeUpTrend = true;
if Debug then print(date, Close, " Node 10", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close > NaturalRally) then {start NaturalRally}
begin {Rule 6g}
InSecReact = false;
InNatRally = true;
NaturalRally = Close;
if Debug then print(date, Close, " Node 11", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close < DnTrend) then {start DnTrend}
begin {Rule 6b}
InSecRally = false;
InDnTrend = true;
DnTrend = Close;
NaturalRallyBL = Close; {rule 4d} {Pivot Pt, Rule 9b}
if Debug then print(date, Close, " Node 12", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close > SecondaryRally) then {remain in SecondaryRally, record higher price}
SecondaryRally = Close; {Rule 3, 6g}
end {InSecRally}


{------Down Trend State-------}
else if InDnTrend then
begin
if (Close < (NaturalRally - Threshold)) then
NaturalRallyBL = NaturalRally; {Rule 4d}
if ResumeDnTrend then {Rule 10 logic. Note: system becomes unstable if used}
begin
if (Close < (DnTrendBL - HalfThresh)) then
begin
ResumeDnTrend = false; {Rule 10a}
DnTrend = Close; {Rule 2, 6b}
if Debug then print(date, Close, " Node 13", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close > (DnTrendBL + HalfThresh)) then {DnTrend Over, return to NaturalRally}
begin
ResumeDnTrend = false;
InDnTrend = false; {Rule 10c}
InNatRally = true;
NaturalRally = Close;
if Debug then print(date, Close, " Node 14", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end;
end
else if (Close > (DnTrend + Thresh)) then {start NaturalRally}
begin {Rules 4c, 6c}
InDnTrend = false;
InNatRally = true;
NaturalRally = Close;
DnTrendBL = DnTrend; {Pivot Pt, Rule 8}
ResumeDnTrend = false;
if Debug then print(date, Close, " Node 15", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close < DnTrend) then {remain in DnTrend, record lower price}
DnTrend = Close; {Rule 2, 6b}
end {InSecRally}


{------Natural Reaction State-------}
else if InNatReact then
begin
if (Close < (NaturalRally - Threshold)) then
NaturalRallyBL = NaturalRally; {Rule 4d}
if (Close < DnTrend) then {resume DnTrend}
begin {Rule 6b, 6e}
InDnTrend = true;
InNatReact = false;
DnTrend = Close;
if UseRule10 then ResumeDnTrend = true;
if Debug then print(date, Close, " Node 16", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close < (NaturalReactionRL - HalfThresh)) then {resume DnTrend}
begin {Rules 5b}
InDnTrend = true;
InNatReact = false;
DnTrend = Close;
if UseRule10 then ResumeDnTrend = true;
if Debug then print(date, Close, " Node 17", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close > UpTrend) then {start UpTrend}
begin {rule 6d}
InNatReact = false;
InUpTrend = true;
UpTrend = Close;
NaturalReactionRL = Close; {Rule 4b} {Pivot Pt, Rule 9c}
if Debug then print(date, Close, " Node 18", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close > (NaturalReaction + Thresh)) then
begin
if (Close > NaturalRally) then {start NaturalRally}
begin {Rules 4b, 6d}
InNatReact = false;
InNatRally = true;
NaturalRally = Close;
NaturalReactionRL = Close; {Rule 4b} {Pivot Pt, Rule 9c}
if Debug then print(date, Close, " Node 19", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else {start SecondaryRally}
begin {Rule 6g}
InNatReact = false;
InSecRally = true;
SecondaryRally = Close;
if Debug then print(date, Close, " Node 20", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end;
end
else if (Close < NaturalReaction) then {remain in NaturalReaction, record lower price}
NaturalReaction = Close; {Rules 3, 6a, 6b}
end {InNatReact}


{------Secondary Reaction State-------}
else if InSecReact then
begin
if (Close < DnTrend) then {resume DnTrend}
begin {Rules 6b, 6e}
InDnTrend = true;
InSecReact = false;
DnTrend = Close;
if UseRule10 then ResumeDnTrend = true;
if Debug then print(date, Close, " Node 21", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close < (NaturalReactionRL - HalfThresh)) then {resume DnTrend}
begin {Rules 5b}
InDnTrend = true;
InSecReact = false;
DnTrend = Close;
if UseRule10 then ResumeDnTrend = true;
if Debug then print(date, Close, " Node 22", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close > UpTrend) then {start UpTrend}
begin {Rule 6d}
InSecReact = false;
InUpTrend = true;
UpTrend = Close;
NaturalReactionRL = Close; {Rule 4b} {Pivot Pt, Rule 9c}
if Debug then print(date, Close, " Node 23", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close < NaturalReaction) then {start NaturalReaction}
begin {Rule 6h}
InSecReact = false;
InNatReact = true;
NaturalReaction = Close;
if Debug then print(date, Close, " Node 24", UpTrend, DnTrend, NaturalRally, NaturalReaction, UpTrendRL, DnTrendBL, NaturalRallyBL, NaturalReactionRL);
end
else if (Close < SecondaryReaction) then {remain in SecondaryReaction, record lower price}
SecondaryReaction = Close; {Rule 6h}
end {InSecReact}


{------Error State-------}
else
begin
{should not get here!!!}
if Debug then
print("Error in State Logic, Date: ", Date, " Time: ", Time);
end; {Error state}

end; {main}



{------Trading Logic-------}

{For TS 2000i only, non-op or delete for TS 6+ }
{
if (TradeTrends = 1) then
begin
if InUpTrend then
Buy next bar at open
else if (Marketposition = 1) then
ExitLong next bar at open;

if InDnTrend then
Sell next bar at open
else if (Marketposition = -1) then
ExitShort next bar at open;
end
else {Trade Trends, Rallies, and Reactions}
begin
if (InUpTrend or InNatRally or InSecRally) then
begin
Buy next bar at open;
ExitShort next bar at open;
end;

if (InDnTrend or InNatReact or InSecReact) then
begin
Sell next bar at open;
ExitLong next bar at open;
end;
end;

}
{ For TS 6+ versions}

if (TradeTrends = 1) then
begin
if InUpTrend then
Buy next bar at open
else if (Marketposition = 1) then
Sell next bar at open;

if InDnTrend then
Sell Short next bar at open
else if (Marketposition = -1) then
Buy to Cover next bar at open;
end
else
begin
if (InUpTrend or InNatRally or InSecRally) then
begin
Buy next bar at open;
Buy to Cover next bar at open;
end;

if (InDnTrend or InNatReact or InSecReact) then
begin
Sell Short next bar at open;
Sell next bar at open;
end;
end;


........
會寫的人加油...不會寫...
{:4_93:}

ivanlin 發表於 10-2-22 12:17

OMG, 有點給他嚇到的程式碼...這樣長

pyxf 發表於 11-3-27 10:49

好文章,要慢慢研究。thx

bbdcd 發表於 11-3-27 21:29

小娃多謝..謝謝,長期看小娃 + coco 的投資者

usana642 發表於 11-5-12 16:56

謝謝大大分享......

hsiao13 發表於 11-6-21 08:15

這篇文章具獨創性。AmiBroker的朋友一同討論。

hsiao13 發表於 13-5-23 00:22

這篇文章要慢慢研究。謝謝大大分享{:4_209:}

孤單飄零 發表於 13-5-30 18:05

來到coco才知道有這個,很感謝michael-knight大與小娃大願意分享,小弟會用心學習{:4_89:}
頁: 1 2 [3] 4
查看完整版本: 如何用AmiBroker做績效回測(作者 michael-knight)