No new Buy after Applystop ending trade

Hi all Amibroker fans,

When a sell signal is given by the hit of an applystop there is no new buy after that occurred.

In the simplied code you could see the buy signal and the test signal which are exactly the same, but the Buy shows only the first signal and redundant signals are removed by the Buy = ExRem(Buy, Sell) function.

There is no regular Sell function (Sell=0), only a take profit stop and a take loss stop.

After the applystop generates an sell signal sell==3 there is no new buy signal but there are losts of new buy oppertunities when test == 1.

Please turn on the intrepertation window for easy testing yourself.

Can anyone PLEASE help me to solve this problem ?

// Please Put "ON" interpertation window 

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

SetTradeDelays(0,0,0,0); // No delays

DEMA10  = DEMA((Open+Close)/2,10);          // DOUBLE EXPONENTIAL MOVING AVARGE MIDDLE OPEN AND CLOSE
SellVol	= IIf ( (H==L), 0, V*(H-C)/(H-L) ); // SellING Volume
AvgVol  = MA  (Volume,30);                  // MOVING AVAREGE VOLUME LAST 30 DAYS 
DayPctSellVol = SellVol / Volume;           // TODAY'S SELLING VOLUME IN PERCENT	


Buy  = DayPctSellVol > 0.9 AND avgVol > 500000 AND Close < DEMA10; // Selling vol > 90%, Avg > 50000, Close < DEMA10
Test = DayPctSellVol > 0.9 AND avgVol > 500000 AND Close < DEMA10; // same as buy but repeating signal for test purpose

Sell = 0; 

// Exit only by ApplyStop and not with regular sell rule.

ApplyStop( stopTypeLoss, stopModePercent, 15 );   // 15% max loss from EntryPrice
Equity(1,0);// check quotes every bar
ApplyStop( stopTypeProfit, stopModePercent, 2 );  // 2% profit target from EntryPrice
Equity(1,0);// check quotes every bar

Buy  = ExRem (Buy, Sell);
Sell = ExRem (Sell, Buy);

EntryPrice = ValueWhen(Buy,Close);
ExitPrice = ValueWhen(Sell,Close);

printf ("DayPctSellVol:  "+NumToStr(DayPctSellVol*100,1.2)+"\n");
printf ("AvgVol:  "+NumToStr(AvgVol,1.0)+"\n");
printf ("EntryPrice:  "+NumToStr(EntryPrice,1.2)+"\n");
printf ("ExitPrice:    "+NumToStr(ExitPrice,1.2)+"\n");
printf ("Buy:     "+NumToStr(Buy,1.0)+"\n");
printf ("Test:     "+NumToStr(Test,1.0)+"\n");
printf ("Sell:     "+NumToStr(Sell,1.0)+"\n");
printf ("Result:    "+NumToStr(((ExitPrice/Entryprice)-1)*100,1.2)+" Procent"+"\n");

PlotShapes(Buy*shapeUpArrow,colorBrightGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
Plot(DEMA10,"DEMA10",colorYellow);

image
First Buy

image
Sell=0 AplyStop = true.

image
Next Buy oppertunity. Test==1 Buy signal is not 1. Why ?

Your code simply is incorrect.
Who told you to apply Equity() function two times (besides only required for stop output in chart of your code)?
Also you do not need ExRem.
ALso there is no NumToStr within printf required.

Simply follow documentation (manual, knowledge base).

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

SetTradeDelays(0,0,0,0); // No delays

DEMA10  = DEMA((Open+Close)/2,10);          // DOUBLE EXPONENTIAL MOVING AVARGE MIDDLE OPEN AND CLOSE
SellVol	= IIf(H==L, 0, V*(H-C)/(H-L) ); // SellING Volume
AvgVol  = MA(Volume,30);                  // MOVING AVAREGE VOLUME LAST 30 DAYS 
DayPctSellVol = SellVol / Volume;           // TODAY'S SELLING VOLUME IN PERCENT	

BuyPrice = Close;
Buy  = Ref(DayPctSellVol > 0.9 AND avgVol > 500000 AND Close < DEMA10, -0); // Selling vol > 90%, Avg > 50000, Close < DEMA10
//Test = DayPctSellVol > 0.9 AND avgVol > 500000 AND Close < DEMA10; // same as buy but repeating signal for test purpose

Sell = 0; 

// Exit only by ApplyStop and not with regular sell rule.
ApplyStop( stopTypeLoss, stopModePercent, 15 );   // 15% max loss from EntryPrice
ApplyStop( stopTypeProfit, stopModePercent, 2 );  // 2% profit target from EntryPrice


if ( Status("action" ) == actionIndicator ) {
	// EQUITY to be called just ONE time !!
	// for ApplyStop chart output
	Equity(1,0);// check quotes every bar

	EntryPrice = ValueWhen(Buy,Close);
	ExitPrice = ValueWhen(Sell,Close);

	printf ("DayPctSellVol:  %1.2f\n", DayPctSellVol*100);
	printf ("AvgVol:  %1.0f\n", AvgVol);
	printf ("EntryPrice:  %1.2f\n",EntryPrice);
	printf ("ExitPrice:    %1.2f\n",ExitPrice);
	printf ("Buy:     %1.0f\n",Buy);
	//printf ("Test:     %1.0f\n",Test);
	printf ("Sell:     %1.0f\n",Sell);
	printf ("Result:    %1.2f%%\n",(ExitPrice/Entryprice-1)*100);

	PlotShapes(Buy*shapeUpArrow,colorBrightGreen,0,Low);
	PlotShapes((Sell>0)*shapeDownArrow,colorRed,0,High);
	Plot(DEMA10,"DEMA10",colorYellow);
}

@rola I suggest also to read the comments section on the Equity() function documentation.

By the way, IMO reading the documentation comments and studying any provided code examples is always a good practice to improve our AFL knowledge.

Hi rola,
I too stuck in the same issue like can't initiate new buy,Have u got any solution?

Unfortunately i don't have the solution either. On screen in plot it works correctly, but i miss buy options after an applystop.

@Prasanna,

Do you have a valid AmiBroker License? If not you are not allowed to post in this section of the forum.