Dear Sir, anyone can help me. Make Number Bar after entry Signal Buy. Thanks

#1
I want to display the number of days after Signal Buy comes out. In the Title and in the explorer. Please help, I've tried many times. But it hasn't worked yet. Thanks

This clue afl:

Hold Day forum amibroker.PNG

Code:
_SECTION_BEGIN("Hold Delay 1");
/////////////////////////////////////////////////////////////////////////////////////
/// @link https://forum.amibroker.com/t/how-do-i-check-the-number-of-bars-since-last-trade-exit-and-new-trade/5993/9
/// Code to set re-entry delay for Shorts occurring n-bars AFTER Cover
/// And adding filter if signal is in between reentry delay
/// by [email protected], May 2018
/////////////////////////////////////////////////////////////////////////////////////
SetBarsRequired( -2 );// set number of bars required (-2 is equal to sbrall -> all bars)

SetPositionSize( 100, spsShares );

reentrydelay = 20;// min. Short re-entry delay of n-bars since Cover signal
tradedelay = 0;// trade entry delay

// insert your Short, Cover signals here
per = 20;
ShortSignal = C < MA(C,per);
CoverSignal = C > MA(C,per);

myLL = Ref(LLV(L,20), -1);

Plot( MA( C, per ), "MA"+per, colorRed );
Plot( myLL, "LLV20", colorGold, styleOwnScale );

/////////////////////////////////////////////////////////////////////////////////////

// (un-)comment to remove/keep excessive signals
//ShortSignal = ExRem( ShortSignal, CoverSignal );
//CoverSignal = ExRem( CoverSignal, ShortSignal );

Buy = Sell = Short = Cover = 0;

if( tradedelay > 0 )    BuyPrice = SellPrice = ShortPrice = CoverPrice = O;
else                    BuyPrice = SellPrice = ShortPrice = CoverPrice = C;

maxbars = 0;
minbars = 1e9;
ShortSig = CoverSig = 0;
Shortentryprice = Coverexitbar = 0;
tradedelay = Min(tradedelay, Barcount-1);
for( i = tradedelay; i < BarCount; i++ ) {
    b = i - tradedelay;

    Shortreentrybar = Coverexitbar + reentrydelay;
    // if #bars below "bars since last exit" limit but C below LLV then Short
    ShortSignal1 = ShortSignal[ b ] && C[ b ] < myLL[ b ] && i < Shortreentrybar;
    // else only enter Short after min "bars since last exit"
    ShortSignal2 = ShortSignal[ b ] && i >= Shortreentrybar;
    
    if( (ShortSignal1 || ShortSignal2) && Shortentryprice == 0 ) {
        Short[ i ] = 1;
        Shortentryprice = ShortPrice[ i ];
        if( ShortSignal1 )
            ShortSig[ b ] = ShortSignal1;
        else
            ShortSig[ b ] = ShortSignal2;
        minbars[ i ] = maxbars[ i ] = (i - Coverexitbar);
        Coverexitbar = 0;   
    }     
    
    if( CoverSignal[ b ] && Shortentryprice > 0 ) {
        Cover[ i ] = 1;
        CoverSig[ b ] = CoverSignal[ b ];
        Coverexitbar = i;       
        Shortentryprice = 0;   
    }   
}

GraphXSpace = 8;

SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );
_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 ) );
_N( Title += StrFormat( EncodeColor(colorRed) + "\nCalculated Lowest re-entry delay: %g bars", SelectedValue(Lowest(minbars)) ));
_N( Title += StrFormat( EncodeColor(colorGreen) + "\nCalculated Highest re-entry delay: %g bars", SelectedValue(Highest(maxbars)) ));
Plot( C, "Close", ParamColor( "Color Price", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle(), 0, 1, 0, 0);

PlotShapes( ShortSig*shapeSquare, colorGreen, 0, H, 10 );
PlotShapes( Short*shapeStar, colorRed, 0, ShortPrice, 0 );

PlotShapes( CoverSig*shapeSquare, colorRed, 0, L, -10 );
PlotShapes( Cover*shapeStar, colorGreen, 0, CoverPrice, 0 );

bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );

fnt = "Arial Bold";
fntsize = 10;
txtdist = 50;

Hold1 = SelectedValue(HighestBars(maxbars));

PlotTextSetFont( "", fnt, fntsize, lvb, 0, -1 );
for ( i = fvb; i <= lvb; i++ ) {
    if ( Short[i] )
        PlotText( "Sell\nBars since Buy: " + (minbars[i]+tradedelay), i, H[ i ], colorRed, colorDefault, txtdist+fntsize );
    if ( Cover[i] )
        //PlotText( "Buy\n", i, L[ i ], colorGreen, colorDefault, -txtdist );
        PlotText( "Hold : " + ( BarCount-Coverexitbar), i, L[ i ], colorGreen, colorDefault,-txtdist );
}
_SECTION_END();
 

Similar threads