Amibroker intraday checking
大家好,我是一個trading新手請多多指教。我現在學習用Amibroker寫策略及backtest。我的入市high level logic (HSI)是:
- 每日開市時如果見到三枝大陽燭當日就只做Buy,見到三枝陰燭就只做sell
- 再見到連續三枝陽燭就入市, 見到兩枝陰燭就平倉
請問在Amibroker coding 如果將策略分在每一日測試?
本帖最後由 zaqimon 於 14-4-20 08:23 編輯
tn = TimeNum();
//tn = IIf(tn > 170000, tn-240000, tn); // shift T+1 TimeNum for 24hr trading
begin_bar = 0;
count_bar = 0;
TodayBS = 0;
for(i=1; i<BarCount; i++)
{
if(tn < tn)
{
begin_bar = i;
count_bar = 0;
}
if(i-begin_bar < 3)
{
if(C > O)
{
++count_bar;
}
else if(C < O)
{
--count_bar;
}
}
if(count_bar == 3)
{
TodayBS = 1; // Today Buy only
}
else if(count_bar == -3)
{
TodayBS = -1; // Today Short only
}
}
大概這樣寫吧
不過我沒測試過
你自己試試看
zaqimon 發表於 14-4-20 08:05 static/image/common/back.gif
大概這樣寫吧
不過我沒測試過
你自己試試看
zaqimon,
this code will do the same as your code but is shorter and faster and without loop. ;-)
bars = 3;
dn = Datenum();
newday= dn != Ref( dn, -1 );
brssince = BarsSince( newday ) == bars-1;
sumdn = Sum( dn == Ref( dn, -1 ), bars-1 ) == bars -1;
Buy = ValueWhen( brssince, Sum( C > O, bars ) ) == bars AND sumdn;
Short = ValueWhen( brssince, Sum( C < O, bars ) ) == bars AND sumdn;
PlotShapes( Buy*shapeUpArrow, colorpalegreen, 0, L, -45 );
PlotShapes( Short*shapedownArrow, colorOrange, 0, H, -45 );
本帖最後由 joshsmi 於 14-4-20 23:52 編輯
joshsmi 發表於 14-4-20 23:45 static/image/common/back.gif
zaqimon,
this code will do the same as your code but is shorter and faster and without loop. ;-)
for comparison
tn = TimeNum();
//tn = IIf(tn > 170000, tn-240000, tn); // shift T+1 TimeNum for 24hr trading
begin_bar = 0;
count_bar = 0;
TodayBS = 0;
for ( i = 1; i < BarCount; i++ )
{
if ( tn < tn )
{
begin_bar = i;
count_bar = 0;
}
if ( i - begin_bar < 3 )
{
if ( C > O )
{
count_bar++;
}
else
if ( C < O )
{
count_bar--;
}
}
if ( count_bar == 3 )
{
TodayBS = 1; // Today Buy only
}
else
if ( count_bar == -3 )
{
TodayBS = -1; // Today Short only
}
}
Buy = todaybs == 1;
Short = todaybs == -1;
PlotShapes( buy*shapeUpArrow, colorGreen, 0, L, -30 );
PlotShapes( short*shapedownArrow, colorRed, 0, h, -30 );
本帖最後由 tszwun 於 14-4-21 15:49 編輯
真的謝謝,原來可以這樣.....請想再問一下,如果我想debug program..用其他language可以output/prompt message做breakpoint, 請問amibroker有沒有類似function?
本帖最後由 zaqimon 於 14-4-21 20:44 編輯
function dout(str)
{
if(USE_DOUT)
{
if(Status("action") == actionIndicator)
{
_TRACE("["+_DEFAULT_NAME()+"] "+str);
}
else
{
_TRACE(""+str);
}
}
}存檔為dout.afl放到Include資料夾內
使用方式
USE_DOUT = True; // True / False
#include_once <dout.afl>
...
dout("hello");
dout(Close);
...
我習慣用DebugView來查看output
打開下面設定即可
Tools > Preferences > AFL > _TRACE() output : 選擇External 本帖最後由 joshsmi 於 14-4-22 23:18 編輯
tszwun 發表於 14-4-21 15:42 static/image/common/back.gif
真的謝謝,原來可以這樣.....請想再問一下,如果我想debug program..用其他language可以output/prompt mess ...
The new editor will get new features including debugger and so on in the future.
Just follow development log http://www.amibroker.com/devlog/
As for now see http://www.amibroker.org/userkb/ ... ions/debugging-afl/
頁:
[1]