Issue in Exrem function

#1
Hello experts....First of all, really wanted to thank every active member here. I have been a frequent visitor of this page and have learnt lot of new things from here. The way experts help novices like me with the code and then explain their logic is really appreciated.
I am still a novice and have a query with the below code -

Cond1 = Volume > EMA(Volume, 20) * 2;
Cond2 = Volume < EMA(Volume, 20) * 0.00003;
Buy= Cond1;
Sell= Cond2;
Buy = Exrem (Buy, Sell);
Sell = Exrem (Sell, Buy);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeHollowDownTriangle, shapeNone),colorRed, 0,H, Offset=-65);
Filter = Buy OR Sell ;
AddColumn(C,"Close");
AddColumn(H,"High");
AddColumn(L,"Low");
AddColumn( Buy, "Buy", 1, colorDefault, IIf( Buy, colorGreen, colorDefault ) );
AddColumn( Sell, "Sell", 1, colorDefault, IIf( Sell, colorRed, colorDefault ) );


I want to explore the stocks with volume > 2x of EMA Volume of last 20 candles. The issue is-
  1. If I am not putting the Exrem lines, I am getting the correct output, but then I am getting more than one signal per day whenever the condition is met (which I don't want).
  2. If I am putting the Exrem lines, I am not getting the correct output.
Request help on this issue. I am running this on hourly timeframe and using amibroker 6.2 version.
 

Romeo1998

Well-Known Member
#2
Sir @tradesuru Because you are using more than and less than in cond1 and cond2, it will be true for many bars, so we can count how many times it is true since newday.... and then stop at the first time it is true...
good luck :)
Code:
newday = DateNum()!=Ref(DateNum(),-1);

Cond1 = Volume > EMA(Volume, 20) * 2;
Cond2 = Volume < EMA(Volume, 20) * 0.00003;

c1 = SumSince(newday,cond1)==1;
c2 = SumSince(newday,cond2)==1;

Buy = c1;
Sell = c2;

Buy = Exrem (Buy, Sell);
Sell = Exrem (Sell, Buy); 

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeHollowDownTriangle, shapeNone),colorRed, 0,H, Offset=-65);
Filter = Buy OR Sell ;
AddColumn(C,"Close");
AddColumn(H,"High");
AddColumn(L,"Low");
AddColumn( Buy, "Buy", 1, colorDefault, IIf( Buy, colorGreen, colorDefault ) );
AddColumn( Sell, "Sell", 1, colorDefault, IIf( Sell, colorRed, colorDefault ) );
 

Similar threads