Hi! With the variable buy_signal I've created buy signals. I have the following rule after which I would want to generate buy and sell signals: if there are 3 consecutive BUY signals generated by buy_signal, at the third a BUY should be generated. Then, 4 periods later a SELL signals should be generated (see code below, variable 'wanted4'). The exact same should be with wanted6, but instead of 4 periods I would want that after 6 periods a SELL should be created after a BUY signal (see code below, variable 'wanted6').

The variables 'wanted4' and 'wanted6' in the following dataex correctly shows how the output should be:

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str3(buy_signal wanted4 wanted6)
"" "" ""
"" "" ""
"" "" ""
"" "" ""
"" "" ""
"" "" ""
"" "" "" 
"BUY" "" ""
"BUY" "" ""
"" "" "" 
"" "" ""
"" "" ""
"BUY" "" ""
"BUY" "" ""
"BUY" "BUY" "BUY"
"BUY" "" ""
"BUY" "" ""
"BUY" "" ""
"BUY" "SELL" ""
"BUY" "BUY" ""
"BUY" "" "SELL"
"BUY" "" "BUY"
"BUY" "" ""
"BUY" "SELL" ""
"BUY" "BUY" ""
"" "" ""
"BUY" "" ""
"BUY" "" "SELL"
"" "SELL" ""
"BUY" "" ""
"BUY" "" ""
"BUY" "BUY" "BUY"
"" "" "" 
"" "" ""
"" "" ""
"" "SELL" ""
"BUY" "" ""
"BUY" "" "SELL"
"BUY" "BUY" "BUY"
"" "" ""
"BUY" "" ""
"BUY" "" "" 
"BUY" "SELL" ""
"BUY" "BUY" ""
"" "" "SELL"
"BUY" "" ""
"BUY" "" ""
"BUY" "SELL" "BUY"
"" "" ""
"BUY" "" ""
"" "" "" 
"BUY" "" ""
"BUY" "" ""
"" "" "SELL"
"" "" "" 
"" "" ""
"BUY" "" ""
"" "" ""
"" "" ""
"" "" ""
"BUY" "" ""
"BUY" "" ""
"BUY" "BUY" "BUY"
"" "" ""
"" "" ""
"" "" "" 
"" "SELL ""
"BUY" "" ""
"BUY" "" "SELL"  
 end
Thank you very much in advance!