Closes above BuyPrice

I was wondering if there is a possible way to count number of close > buy price before sell


BuyPrice = Open;                           
SellPrice=Open; 
Buy 	= 	Cross(RSI(14), 60);

for(bar=0; bar < BarCount; bar++)
{
	C1	=	IIf(C > BuyPrice, C1 = 1, 0);
}

Sell	=	C1 >= 5;

Please help to find the counter of close bars above buyprice

SellPrice=Open; 
Buy 	= 	Cross(RSI(14), 60);

Buy_Price = ValueWhen(Buy, Open);

Count = SumSince(Buy, Close > Buy_Price);

Sell	=	Count >= 5;

Thanks this worked, but still I think there is something missing
I have set to trade on next day open, so please check the screen shot why sell arrow get delayed so much ?

SetTradeDelays(1,1,1,1);                  	
RoundLotSize = 1; 
 
BuyPrice = Open;                           	// Buy stocks at the open of the bar following the signal 
SellPrice=Open;                             // Sell stocks at the open of the bar following the signal 
Short=Cover=0; 
 
// Simulation rules 
 
Filter 	= 	1;

Buy 	= 	Cross(RSI(14), 60);

Buy_Price = ValueWhen(Buy, Ref(Open,1), 1);
Count 	= SumSince(Buy, Close > Buy_Price);

Sell	        =	Count >= 5;

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

SetPositionSize((100 / MAXOP), spsPercentOfEquity );

PlotShapes( BUY*shapeUpArrow, colorWhite, 0, L, -15); 
PlotShapes( Sell*shapeDownArrow, colorYellow, 0, H, -35);

ERROR

Sell = Count == 5;

@awilson it does not wroked. still the problem remains same

Start debugging your code by placing a Plot of your Buyprice and count

@Siraj did you try to debug your code with an exploration?

In this case, an exploration of the calculated variables will clearly show you why the code does not do what you expect: Count is reset to 0 at every additional signal (a cross of RSI over 60).
Comment out both the ExRem() calls to clearly see it in the exploration.

This seems a tricky situation: you are setting the Sell based on Buy and ExRem does not know about it until you have set it...

(By the way, what happens to your P&L if, unfortunately, after you buy the price will go down and never return over the BuyPrice, or does it only 4 times)?

@beppe
By commenting out Exrem it shows new buy signals, but it kills the whole purpose of Exrem.
The reason I am using exrem is that I need not want to have another trade untill the initial trade is stoped out.
The whole idea is to count, how many times close price is above the buyprice and once it reaches the count we shoudl exit the trade.

Still looking for satisfactory solution

you need to do it without exrem using for loop..

2 Likes

can u show us code example

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