So I have this code that sell short when two conditions are met:
This short the stock at market price at the next red candle.
I want to re-short (if I take a win) when the price goes above the "high of the day follow by a red candle" (condition 1 and 2).
With the same criteria as in condition 1 and 2.
What the code does now is to re-short again after the first red candle without the stock making a new high of day.
Can you help answer these questions from other members on futures io?
You could probably have a new variable that always saves the high of the current candle if it is higher than the high of the previous one. You could then build a condition around that for your entries. For example, lets say your candle N is a bear candle and the high of candle N-1 equals your variable, then you have an entry signal.
Thank you, however my problem with that way to write the code is that once the position is covered, and the price has not gone over HOD again, the condition is still valid, so it will re-short below HOD. It should only short once below HOD. For a second short the stock needs to break HOD again.
Well, I see I have phrased my idea incorrectly. You would probably want to set an initial high to a variable and only if any successing candle has a high that is higher than that variables value, save the new high to the variable.
So maybe declare a variable "HOD" and set it to the high of the opening candle. Then, if any successing high is higher than the current value saved to your variable "HOD", set the variable to that new highs value. So basically do not compare candle N to candle N-1 like I said in my first post, but instead, compare the high of candle N to the value of "HOD" variable. Hope this makes more sense.
That way, it should only consider a new high of day where there is an orange arror in the picture below.
Hi, well this is the part of the code I'm struggeling with, how to save the high of the high of the day, and make the code code execute again if a value is above that high. Also for the first short, it needs to execute without even though there hasn't been a high that is saved, as its the first high of the day. The code needs to reset each day.
The way I define the high of the day, is as seen in the code is when the red candle follow the green candle (which is the HOD).