- Joined
- 30 June 2021
- Posts
- 5
- Reactions
- 2
Question for Amibroker users:
I am coding a system to backtest.
One of the signals is a crossover of the K & D lines of the Stochastic RSI. I want the signal to be valid until the K reaches a certain threshold.
(E.g. There is a cross down in the overbought region (K>80) and this signal should be valid as long as K >50).
The code I have written:
stochrsishort = 0; // Initialise the variable used to store whether the signal is valid or not
stochrsishort = IIf(StochRSICrossDown,1,0); // Set value to 1 if there is a Cross Down from the Overbought region.
stochrsishort = IIf(Ref(stochrsishort,-1) == 1 AND SK > kShortThreshold,1,stochrsishort); // If the previous value was 1 AND K is still greater than threshold value, return 1
However, when I plot the value of stochrsishort, the signal stays open for MAX 1 bar, instead of staying at 1 as long as it is above the K threshold?
I am not sure what I have done wrong as the logic should be correct? (I have used the same logic in TradingView PineScript and it executes as intended.)
Thanks in advance for any help!
I am coding a system to backtest.
One of the signals is a crossover of the K & D lines of the Stochastic RSI. I want the signal to be valid until the K reaches a certain threshold.
(E.g. There is a cross down in the overbought region (K>80) and this signal should be valid as long as K >50).
The code I have written:
stochrsishort = 0; // Initialise the variable used to store whether the signal is valid or not
stochrsishort = IIf(StochRSICrossDown,1,0); // Set value to 1 if there is a Cross Down from the Overbought region.
stochrsishort = IIf(Ref(stochrsishort,-1) == 1 AND SK > kShortThreshold,1,stochrsishort); // If the previous value was 1 AND K is still greater than threshold value, return 1
However, when I plot the value of stochrsishort, the signal stays open for MAX 1 bar, instead of staying at 1 as long as it is above the K threshold?
I am not sure what I have done wrong as the logic should be correct? (I have used the same logic in TradingView PineScript and it executes as intended.)
Thanks in advance for any help!