PlotText结果在amibroker中重叠

时间:2015-06-16 14:58:06

标签: trading algorithmic-trading

我使用下面的代码

![priceatbuy=0; 
for( i = 0; i < BarCount; i++ ) 
{ 
if( priceatbuy == 0 && Buy\[ i \] ) 
priceatbuy = BuyPrice\[ i \]; 

PlotText("P" + priceatbuy, SelectedValue(BarIndex()), L\[SelectedValue(BarIndex())\] - ist\[SelectedValue(BarIndex())\], colorWhite);
if( priceatbuy > 0 && SellPrice\[ i \] < (priceatbuy - (0.027 * priceatbuy/100)) ) 
{ 
Sell\[ i \] = 1; 
SellPrice\[ i \] = (priceatbuy - (0.027 * priceatbuy/100)) ;
plotShapes(shapeDownArrow*sell, colorpink );
priceatbuy = 0; 
} 
else 
Sell\[ i \] = 0;
}][1] 

使用上面的plotText,当我打印变量&#34; priceatBuy&#34;时,我看到文本重叠,我无法正确看到该值。是因为SellPrice [i]和BuyPrice [i]返回了Plottext无法理解的其他值吗?如果我打印Sell [i]或Buy [i],它会正确打印。我可以知道如何正确获得这个值。

PFA图片

1 个答案:

答案 0 :(得分:0)

你的代码错了。

下面是一个正确的代码示例(循环只包含SL退出!所以你需要添加一些利润退出条件,否则你总是丢失退出。)

percent = 2.0; // percent SL
delay = 1; // buy entry bar delay

Buycond = Cross( MACD(), Signal() ); // buy when macd crosses above of signal line
Buy = Ref( Buycond, -delay );    
BuyPrice = Open;

Sell = 0;
SLlong = Null;
SLLineLong = Null; // array
for( i = delay; i < BarCount; i++ ) {
    // setting long SL line
    if( IsNull( SLlong ) && Buy[ i ] )
        SLlong = BuyPrice[ i ] * ( 1 - percent / 100 );  
    else { 
        Buy[ i ] = 0;
    }
    // no shape buy signal if SL not hit
    if( NOT IsNull( SLlong ) && BuyCond[ i ] )
        Buycond[ i ] = 0; 
    // if SL is reached exit and reset
    Sellsignal = L[ i ] < SLlong;
    if( NOT IsNull( SLlong ) && Sellsignal ) {
        Sell[ i ] = 1;
        SellPrice[ i ] = Min( O[ i ], SLlong );       
        SLlong = Null;
    } else
        Sell[ i ] = 0;
    //
    // for plotting SL line array is required
    SLLineLong[i] = SLlong;
}

// Chart pane section
if( Status( "action" ) == actionIndicator ) {
    SetBarsRequired( 10000, 10000 );
    SetChartOptions( 0, chartShowDates | chartShowArrows | chartWrapTitle );
    // Plot price
    Plot( C, "", colorDefault, GetPriceStyle() );
    // Plot SL line
    Plot( SLLineLong, "\nSL long", colorRed, styleLine | styleNoRescale );
    //
    // Plot Shapes
    dist = -12;
    PlotShapes( shapeUpArrow * Buycond, colorGreen, 0, L, dist );
    PlotShapes( shapeSmallCircle * Buy, colorGreen, 0, BuyPrice, 0 );
    PlotShapes( shapeDownArrow * Sell, colorPink, 0, H, dist );
    PlotShapes( shapeSmallCircle * Sell, colorPink, 0, SellPrice, 0 );
    //
    // Plot signal text
    fnt = "Arial";
    fntsize = 8;
    txtdist = 25 - dist;
    bi = Barindex();
    fvb = FirstVisiblevalue( bi );
    lvb = LastVisiblevalue( bi );

    PlotTextSetFont( "", fnt, fntsize, 0, 0, -1 ); 

    for( i = fvb; i <= lvb; i++ ) { // iterate through visible chart area only
        if( Buy[i] )  // plot text at signal occurences only
            PlotText( StrFormat( "BP@\n%g", BuyPrice[ i ] ), i, L[ i ], colorGreen, colorDefault, -txtdist + fntsize );
        if( Sell[i] )
            PlotText( StrFormat( "SP@\n%g", SellPrice[ i ] ), i, H[ i ], colorPink, colorDefault, txtdist );
    }
    //
    _N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}",
                           O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );    
}