I've coded a few indicators but this is my first strategy. Please excuse me if my question feels basic.
What I'm trying to achieve ...in picture.
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).
If I use on "Initialise" :
That is not what I want since the stop stance will be impacted by the entry slippage from the market order, which is precisely what I want to avoid ...
Then I've tried to use on "OnBarUpdate" :
This takes the Close from the signal bar (bar 1) which is about the Open price from the entry bar (bar 2) ..but not quite on every single trade Worse than that, it creates a random behavior on my stops.
Could you please help me to simply code : set stoploss to real Open price from entry bar (without slippage impact from market entry order) - 10 ticks ??
That stoploss needs to be set once (just after entry) and should not be moved afterwards.
Try this...haven't tested but it should work. The problem is when using COBC = true which is the default, all code is executed at the open of the next bar. However, as you know the entry price is the open of the next bar but the stoploss is the close of the signal bar. So, what you can do to overcome this is to set the stop at the same time as you enter the market and then reset it at the close of the next bar. The only problem that I can think of is if the first bar is long enough to hit your stop before you can reset the stop. Maybe others have a better idea than this. Again, I haven't tested this but believe it will work.
put this in your variable declarations area.
put this in OnBarUpdate...also notice the parentheses I placed around (stp*TickSize). I notice you have the simulated parameter set to true. Be sure you know what that means before using it.
You can also look at the BarsSinceEntry() method instead of using the CurrentBar - longentrybar calculation...
The following user says Thank You to MWinfrey for this post:
Your code works as described! I believe it's the closest one can accomplish although it is in fact a handicap to keep the risk of the stoploss unproperly set on the signal bar while waiting for the next one. At the same time, I tried to play with COBC=False with no more success.
I used BarsSinceEntry since I manage too many separate orders that I can declare variables for. I build my position from multiple fractions of futures contracts via CFDs so I use a loop condition in OnBarUpdate instead.
I did read about the simulated parameter but it seems like I did not understand it right. Thanks for having put my attention on it ! That's part of education
The following user says Thank You to mea109 for this post: