First Buy pop up not working

Hi Gurus

I am working with Buy/Sell Pop up signal .
sometimes ,first buy signal(popup) is not working where as Alert for the same signal is working.
Please Help . Below is my code

_SECTION_BEGIN( "Main" );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
SetChartOptions( 0, chartShowArrows | chartShowDates ); //Enable X-Axis (Date/Time Axis)

per = 0;
sec = 5;


Plot( Close, "Candles", colorDefault, styleCandle ); //Plot Candles

Plot( EMA( C, 20 ), "EMA20", colorYellow, styleThick );
Plot( EMA( C, 50 ), "EMA50", colorBlue, styleThick );
Buy=Sell=0;
Buy = Cross( EMA( Close, 20 ), EMA( Close, 50 ) );
Sell = Cross( EMA( Close, 50 ), EMA( Close, 20 ) );

PlotShapes( IIf( Buy, shapeSquare, shapeCircle ), colorGreen, 0, L, Offset = -10 );
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -20 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -15 );
PlotShapes( IIf( Sell, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 40 );
PlotShapes( IIf( Sell, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 50 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -45 );


sellsignal = LastValue( Sell );
buysignal = LastValue( Buy );

BuyPrice = ValueWhen( Buy, Close );
SellPrice = ValueWhen( Sell, Close );

sellcount = 0;
buycount = 0;

AlertIf( Sell, "", Name() + " Sellprice=" + SellPrice, 2 );
AlertIf( Buy, "", Name() + " Buyprice=" + BuyPrice, 1 );

if(LastValue(Sell)!=0  AND sellcount == 0 )
{
    PopupWindow( "sellprice=" + SellPrice, Name(), sec );
    Say( "sell Order Placed" );
    buycount = 0;
    sellcount = 1;
}

if(LastValue(Buy)!=0 AND buycount == 0 )
{
    PopupWindow( "buyprice=" + BuyPrice, Name(), sec );
    Say( "buyOrder Placed" );
    buycount = 1;
    sellcount = 0;
}

_SECTION_END();

@baru,

Only users with "Verified Badge" are allowed to post on this forum.

Search "Verified Badge" for more information on how to get verified.

Just now did and got Verified Badge.
I am quite new to the forum , Thanks for the information .

Regards,
baru

1 Like

Study LastValue().

I am sorry to ask again.
Last value gives the current/last value of the array .
Like LastValue(C) = current bar -Close value .

I am getting all signals for few runs/symbols.
For few I am not getting only one signal(buy or sell).
Do I have to keep a Set Delay or some thing like that ?

Regards,
baru

See this to help you debug

How do I debug my formula? - AFL Programming - AmiBroker Community Forum

sellcount = 0;
buycount = 0;

This method of counting will not work because those are local variables and AFL executes afresh each time.
AmiBroker Knowledge Base » When and how often AFL code is executed?

So either you can use static variables or functions like SumSince() etc depending on how you are counting to maintain state.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.