I am trying to check the number of bars between my last trade Exit and Entry of a Fresh Trade. Based on the numbers of days I want to add some filter to the new trade.
I tried this method but I cant use BarSince Cover condition to check that before Initialising Cover.
BarsSinceLastExit=BarsSince(Cover);
Short= if(BarsSinceLastExit < 20, (C < MA(C,20) AND C < Ref(LLV(20),-1)),(C< MA(20)));
Cover= C > MA(C,20);
Where, in the above chart, the first white candle will be the exit from the last trade and the first blue bar will be the entrance to a fresh trade. Something like that?
@vishaldalvi Your code is flawed and your "Short" condition is wrongly coded.
But more importantly please follow the rules of this forum and properly format code. It is so easy to type three little "backtick" lines, ``` and then put in your code, and then type in three more backticks.
The are the lower case of the key that has the "tilde" as the uppercase. Yes I know these are words most people do not use in their everyday conversation.
Others have written this description,
(`/~) The tilde key, since the name for the unshifted "grave accent" or "backtick" character is not widely known. (This may also go by the "squiggle key" or "the key next to the 1 with the squiggle on it" for people who don't know the name for "tilde" either; neither are commonly used outside of programming
I get your point...Apologies for the wrong codes. Below is the set of code I am trying.
BarsSinceLastExit=BarsSince(Cover);
Short= (BarsSinceLastExit > 20 AND (C < MA(C,20)) OR
(BarsSinceLastExit < 20 AND C < Ref(LLV(L,20),-1)) AND (C< MA(C,20)));
Cover= C > MA(C,20);
I am getting the error - " Variable used without having been initialized.
The issue I am facing is -
I have to check a variable BarSinceExit which is dependent on my Cover condition. And I need to use that same variable in my Short Trade condition. I am not able to use Cover condition to check Bars since the Exit.
Idea is to avoid too many signals back to back in a sideways market, hence I am adding a Filter on break below N bar low , if the new entry is within 20 bars from last trade Exit.
There's no reason that you can't assign your Cover variable before your Short, so you can at least start with something like this:
Cover= Cross(C, MA(C,20));
BarsSinceLastExit=BarsSince(Cover);
Short= (BarsSinceLastExit > 20 AND (C < MA(C,20)) OR
(BarsSinceLastExit < 20 AND C < Ref(LLV(L,20),-1)) AND (C< MA(C,20)));
Using the Cross() function (impulse signal) instead of the logical greater than operator (state signal) will help reduce the number of excess Cover signals that you have. However, you'll need to decide whether those excess signals are acceptable for purposes of counting bars.
In upper code there is one line from the other thread's code that needs to be changed because otherwise plotted LLV line in ownscale mode would be misleading. In other thread's code it wasn't because there it was slope condition line that needed to be in own scale mode.
So long story short... go to line 22 of upper code and change