Hopefully someone can help me out of this.
In the following code opening a long position if the current price is higher than the previous candle's High.
Then I set a profit target, and a stop loss. The profit target is static, so that works fine, but the stop loss is variable. I have set it to look for the lowest price of the last 5 candles, and set that as a stop loss. However, in my code, what it does is that it sets the stop loss based on the lowest price of the 5 candles before the trade candle, and fixes it at that value.
I want the stop to keep on moving with each candle, i-e, after each candle, it evaluates the lowest value of the last 5 candles and sets the stop as that....
Any ideas on what Im missing, or what I need to add to the following code to achieve that?