Strategy to only enter and exit after specific condition?

M

Mamba10

New member
Warehouse
How can tell a strategy to enter and exit a trade after three consecutive bars have closed under a certain condition. For example, if I want to make a strategy based moving average crossovers and I don't want it to enter the trade immediately after the crossover but I want it to enter the trade after three bars have closed under the condition I've set. How would that look like in terms of coding? Thanks!
 
T

tomsk

Well-known member
VIP
Here's a real simple way to code your buy condition for a 8/21 SMA crossover that triggered 3 bars ago (incl the current bar). Tweak it to suit your needs

Code:
def cond = Average(close,8) crosses above Average(close,21);
plot buy = cond[2];
 
Last edited:

Top