COCO研究院

 找回密碼
 註冊
搜索
查看: 3901|回復: 13

半自動的趨勢線交易要如何做?

[複製鏈接]
發表於 13-10-25 09:02 | 顯示全部樓層 |閱讀模式
人工定2點連成一條趨勢線,以多單來說,沒跌破就續抱,跌破就賣出,這要怎麼做到呢?
發表於 13-10-25 10:05 | 顯示全部樓層
發表於 13-10-25 12:28 | 顯示全部樓層
用兩條線 年賺八成
類似這種的嗎?!

 樓主| 發表於 13-10-25 13:54 | 顯示全部樓層
不是2條線喔,是一條線
發表於 13-10-25 16:34 | 顯示全部樓層
123.png
程式碼只有一行, 填入兩點的時間和價格即可.

value1= TL_New(Date,0908,8329,Date,1142,8291);




評分

參與人數 2金錢 +3 收起 理由
solo + 2 按一個讚
lwhuang + 1 按一個讚

查看全部評分

 樓主| 發表於 13-10-25 17:09 | 顯示全部樓層
Help找不到TL_New這個function耶
 樓主| 發表於 13-10-25 17:11 | 顯示全部樓層
我google的結果, 是TS的函數,有amibroker的嗎?
發表於 13-10-28 18:00 | 顯示全部樓層
斜率去算,就能知道當日的趨勢線價格

手動畫點就知道A點價格 & B點價格,也能知道A <==> B 距離。

斜率 = (A - B)  / 距離

因為我不懂amibroker,所以只會笨方法...。
 樓主| 發表於 13-10-28 20:23 | 顯示全部樓層
lcc0809 發表於 13-10-28 18:00
用斜率去算,就能知道當日的趨勢線價格

手動畫點就知道A點價格 & B點價格,也能知道A  B 距離。

這個不是笨方法,是好複雜的方法...要是真的沒有簡單法,可能只有這樣了

發表於 13-10-29 03:22 | 顯示全部樓層
本帖最後由 joshsmi 於 13-10-29 04:04 編輯
googleandy 發表於 13-10-25 16:34
程式碼只有一行, 填入兩點的時間和價格即可.

value1= TL_New(Date,0908,8329,Date,1142,8291);

What's that Power Language junk got to do with AmiBroker????

The same can be done in AmiBroker with simple functions either with AFL or in dll plugin.

Here is AFL equivalent to that TS trendline function

// Copyright joshsmi, Oct 2013

function dntn2dt( dn, tn )
{
// Datenum() + Timenum() to DateTime()
  
return DateTimeConvert( 2, dn, tn );
}

function TL_New( dn1, tn1, startval, dn2, tn2, endval )
{
// trendline function
    dt      =
DateTime();
    bi      =
BarIndex();

    startdt = dt == dntn2dt( dn1, tn1 );
    enddt   = dt == dntn2dt( dn2, tn2 );

    x0      =
LastValue( ValueWhen( startdt, bi ) );
    x1      =
LastValue( ValueWhen( enddt, bi ) );
    y0      =
LastValue( ValueWhen( startdt, startval ) );
    y1      =
LastValue( ValueWhen( enddt, endval ) );

    Line    =
LineArray( x0, y0, x1, y1, 1, True );

   
return Line;
}

Plot( C, "C", colorWhite, styleCandle );
Plot( TL_New( 1131028, 090000, L, 1131028, 130500, L ), "Trend line", colorRed );

And this is how it looks





評分

參與人數 3金錢 +6 收起 理由
shonyu + 2 太強了
lwhuang + 2 太強了,吸收中
googleandy + 2 太強了

查看全部評分

發表於 13-10-29 04:08 | 顯示全部樓層
本帖最後由 joshsmi 於 13-10-29 04:19 編輯

If you want to use buy, sell, short, cover signals on drawn trendlines
then you can also use Study() function. See in the manual.


su = Study( "SU", GetChartID() );// drawn support trendline, see manual on how to connect
Buy = LLV( C, 20 ) > su AND AlmostEqual( C, su, 10000 ); //10000 -> equal max. 0.1%

評分

參與人數 3金錢 +5 收起 理由
f29825604 + 1 感謝分享
lwhuang + 2 太強了
googleandy + 2 太強了

查看全部評分

發表於 13-11-14 12:35 | 顯示全部樓層
推一個................讚~~
發表於 13-11-14 19:43 | 顯示全部樓層
本帖最後由 joshsmi 於 13-11-14 19:49 編輯

Here is and advanced version using range markers and keystrokes.

So for Support trend line you press and hold key "L" and then choose two range markers via mouse double-click to draw red support trendline. Then you de-activate range markers on right side of chart and press and hold key "H" and then choose two new range markers to draw green resistance trend  line.

If you want to preserve drawn trend lines after restart of AmiBroker then use persistent variables instead of static variables.



// Copyright joshsmi, Oct 2013
// don't distribute this code without permission

Version( 5.55 );

function TL_New( dn1, tn1, startval, dn2, tn2, endval )
{
// trendline function
    dt      =
DateTime();
    bi      =
BarIndex();

    startdt = dt ==
DateTimeConvert( 2, dn1, tn1 );
    enddt   = dt ==
DateTimeConvert( 2, dn2, tn2 );

    x0      =
LastValue( ValueWhen( startdt, bi ) );
    x1      =
LastValue( ValueWhen( enddt, bi ) );
    y0      =
LastValue( ValueWhen( startdt, startval ) );
    y1      =
LastValue( ValueWhen( enddt, endval ) );

    Line    =
LineArray( x0, y0, x1, y1, 1, True );

   
return Line;
}

RequestTimedRefresh( 1 );

tn      =
TimeNum();
dn      =
DateNum();
Chartid =
NumToStr( GetChartID(), 1.0, False );

if ( ParamTrigger( "Clear trend-line(s)", "CLICK HERE" ) )
   
StaticVarRemove( Chartid + "TL_new*" ); // or use persitentvarremove, see link below

// using RANGE MARKERs via mouse double-click!
// read here http://www.amibroker.com/guide/h_charting.html?
startdn =
ValueWhen( BeginValue( dn ) == dn, dn );
starttn =
ValueWhen( BeginValue( tn ) == tn, tn );
enddn   =
ValueWhen( EndValue( dn ) == dn, dn );
endtn   =
ValueWhen( EndValue( tn ) == tn, tn );


// alternatively to static variables you can use persistent varaibles to preserve lines after restart of AB
// read here http://www.amibroker.org/userkb/2007/04/24/persistent-variables/
if ( LastValue( startdn ) != dn[0] && LastValue( starttn ) != tn[0] )
{
   
if ( GetAsyncKeyState( 76 ) < 0 ) // press and hold key "L" and choose range markers
    {
        
StaticVarSet( Chartid + "TL_new start dn Low", startdn );
        
StaticVarSet( Chartid + "TL_new start tn Low", starttn );
        
StaticVarSet( Chartid + "TL_new end dn Low", enddn );
        
StaticVarSet( Chartid + "TL_new end tn Low", endtn );
    }

   
if ( GetAsyncKeyState( 72 ) < 0 ) // press and hold key "H" and choose range markers
    {
        
StaticVarSet( Chartid + "TL_new start dn High", startdn );
        
StaticVarSet( Chartid + "TL_new start tn High", starttn );
        
StaticVarSet( Chartid + "TL_new end dn High", enddn );
        
StaticVarSet( Chartid + "TL_new end tn High", endtn );
    }
}

startdnL =
Nz( StaticVarGet( Chartid + "TL_new start dn Low"  ) );
starttnL =
Nz( StaticVarGet( Chartid + "TL_new start tn Low" ) );
enddnL   =
Nz( StaticVarGet( Chartid + "TL_new end dn Low" ) );
endtnL   =
Nz( StaticVarGet( Chartid + "TL_new end tn Low" ) );

startdnH =
Nz( StaticVarGet( Chartid + "TL_new start dn High"  ) );
starttnH =
Nz( StaticVarGet( Chartid + "TL_new start tn High" ) );
enddnH   =
Nz( StaticVarGet( Chartid + "TL_new end dn High" ) );
endtnH   =
Nz( StaticVarGet( Chartid + "TL_new end tn High" ) );

Plot( C, "", colorWhite, styleCandle );
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.2f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

if ( LastValue( startdnL ) != 0 )
   
Plot( TL_New( startdnL, starttnL, L, enddnL, endtnL, L ), "\nSU Trend line", colorRed );

if ( LastValue( startdnH ) != 0 )
   
Plot( TL_New( startdnH, starttnH, H, enddnH, endtnH, H ), "\nRE Trend line", colorBrightGreen );

發表於 13-11-14 20:03 | 顯示全部樓層
本帖最後由 joshsmi 於 13-11-14 21:24 編輯

Here is another updated code to manually draw multiple AFL code trend lines





// Copyright joshsmi, Oct 2013

Version( 5.55 );

function TL_New( dn1, tn1, startval, dn2, tn2, endval )
{
// trendline function
    dt      =
DateTime();
    bi      =
BarIndex();

    startdt = dt ==
DateTimeConvert( 2, dn1, tn1 );
    enddt   = dt ==
DateTimeConvert( 2, dn2, tn2 );

    x0      =
LastValue( ValueWhen( startdt, bi ) );
    x1      =
LastValue( ValueWhen( enddt, bi ) );
    y0      =
LastValue( ValueWhen( startdt, startval ) );
    y1      =
LastValue( ValueWhen( enddt, endval ) );

    Line    =
LineArray( x0, y0, x1, y1, 1, True );

   
return Line;
}

RequestTimedRefresh( 1 );

tn      =
TimeNum();
dn      =
DateNum();
Chartid =
NumToStr( GetChartID(), 1.0, False );

TLnumLow  =
ParamStr( "Input Support TL number", "1" );
TLnumHigh =
ParamStr( "Input Resistance TL number", "1" );

if ( ParamTrigger( "Clear trend-line(s)", "CLICK HERE" ) )
   
StaticVarRemove( Chartid + "TL_new*" ); // or use persitentvarremove, see link below

// using RANGE MARKERs via mouse double-click!
// read here http://www.amibroker.com/guide/h_charting.html?
startdn =
ValueWhen( BeginValue( dn ) == dn, dn );
starttn =
ValueWhen( BeginValue( tn ) == tn, tn );
enddn   =
ValueWhen( EndValue( dn ) == dn, dn );
endtn   =
ValueWhen( EndValue( tn ) == tn, tn );


// alternatively to static variables you can use persistent varaibles to preserve lines after restart of AB
// read here http://www.amibroker.org/userkb/2007/04/24/persistent-variables/
if ( LastValue( startdn ) != dn[0] && LastValue( starttn ) != tn[0] )
{
   
if ( GetAsyncKeyState( 76 ) < 0 ) // press key "L" and choose range markers
    {
        
StaticVarSet( Chartid + "TL_new start dn Low" + TLnumLow, startdn );
        
StaticVarSet( Chartid + "TL_new start tn Low" + TLnumLow, starttn );
        
StaticVarSet( Chartid + "TL_new end dn Low" + TLnumLow, enddn );
        
StaticVarSet( Chartid + "TL_new end tn Low" + TLnumLow, endtn );
    }

   
if ( GetAsyncKeyState( 72 ) < 0 ) // press key "H" and choose range markers
    {
        
StaticVarSet( Chartid + "TL_new start dn High" + TLnumHigh, startdn );
        
StaticVarSet( Chartid + "TL_new start tn High" + TLnumHigh, starttn );
        
StaticVarSet( Chartid + "TL_new end dn High" + TLnumHigh, enddn );
        
StaticVarSet( Chartid + "TL_new end tn High" + TLnumHigh, endtn );
    }
}

Plot( C, "", colorWhite, styleCandle );
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.2f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

for ( i = 1; i <= 10; i++ ) // 10 trend lines each
{
    startdnL =
Nz( StaticVarGet( Chartid + "TL_new start dn Low" + i ) );
    starttnL =
Nz( StaticVarGet( Chartid + "TL_new start tn Low" + i ) );
    enddnL   =
Nz( StaticVarGet( Chartid + "TL_new end dn Low" + i ) );
    endtnL   =
Nz( StaticVarGet( Chartid + "TL_new end tn Low" + i ) );

    startdnH =
Nz( StaticVarGet( Chartid + "TL_new start dn High" + i ) );
    starttnH =
Nz( StaticVarGet( Chartid + "TL_new start tn High" + i ) );
    enddnH   =
Nz( StaticVarGet( Chartid + "TL_new end dn High" + i ) );
    endtnH   =
Nz( StaticVarGet( Chartid + "TL_new end tn High" + i ) );

   
if ( LastValue( startdnL ) != 0 )
    {
        TLlow = TL_New( startdnL, starttnL,
L, enddnL, endtnL, L );
        
Plot( TLlow, "\nSU Trend line " + i, colorRed, styleLine | styleNoRescale );
        
PlotText( "No." + i, BarCount + 10, LastValue( TLlow ), colorRed );
    }

   
if ( LastValue( startdnH ) != 0 )
    {
        TLhigh = TL_New( startdnH, starttnH,
H, enddnH, endtnH, H );
        
Plot( TLhigh, "\nRE Trend line " + i, colorBrightGreen, styleLine | styleNoRescale );
        
PlotText( "No." + i, BarCount + 10, LastValue( TLhigh ), colorBrightGreen );
    }
}



評分

參與人數 1金錢 +2 收起 理由
lwhuang + 2 太強了

查看全部評分

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

本版積分規則

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

GMT+8, 24-12-23 13:07

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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