Still happening in 2024. i have multiple instances running. when a position closes and the position_closed event fires, it triggers this method for all instances (although it does just close the actual trade)
I can tell because i receive the SMS's *freaked me out
In fact, i noticed this behaviour in Positions_Modified and Positions_Opened aswell
My fix
private void Positions_Closed(PositionClosedEventArgs obj){ //step: weird bug - do not fire for symbols that are not the same - picked this up in my sms's if(obj.Position.Symbol.Name.ToUpper() != Symbol.Name.ToUpper()) return;
It appears this is intended behavior because of the way the event is wired. It's wired this way because it's on the “Positions” collection, not the individual “Position”. The “positions” is all the positions, not just a singular one.
It occurs every time a position is closed. So it doesn't matter if a position is closed from a bot, a stop loss, a take profit, or someone manually closing it. That's why there's the “args” parameter is supplied so you can filter the event based on the symbol from the “positions” collection.
firemyst
17 Oct 2024, 01:40
( Updated at: 17 Oct 2024, 04:57 )
Depends on what you want.
You're getting the LastValue, which is value as of the moment it's taken in the current bar. As you know, values for the current bar can change depending on what the price does.
So at the beginning of the bar for example, the top band could be one value, but then if price really skyrockets and the band expands, the top band could end up being another value by the close of the bar.
If that's what you want, fine.
Perhaps what you want is the value of the previous bar when price closed? With Bollinger Bands, that shouldn't change. So instead of getting the .LastValue, you need to get .Last(1).
firemyst
04 Oct 2024, 14:47
( Updated at: 05 Oct 2024, 06:10 )
I don't believe there is, and think you'll have to keep track of it in your code.
Basically query the SL distance from whatever price you want, convert it to pips, and then save it in a variable before setting the SL property to true on the position.
firemyst
04 Oct 2024, 14:45
( Updated at: 05 Oct 2024, 06:09 )
You first have to extract them from the Zip file.
Once extracted, you should see a “.algo” file. You need to double click that to install.
Once installed, you should see them listed in “custom” submenu of the “indicators menu”. They'll be listed at the bottom until you restart cTrader and then they'll be listed in alphabetical order.
If that doesn't work, then you need to contact the developer as Panagiotis suggested
Hopefully you can get the latest version now and update to 5.0.38.
AGain, it's one of those things that people need to ask how much testing they do before releasing a version as this seems like something that should have been pretty straight forward and catching beforehand.
What's the spread on your US30 when you place the order?
On a few brokers, the spread is larger than the 2-point SL you set.
If you're doing this in a bot or indicator, you need to check the spread before placing your order. It's not a guarantee since the spread could hypothetically change at any given moment, but it's a good safety check
firemyst
23 Oct 2024, 00:39 ( Updated at: 23 Oct 2024, 04:59 )
RE: position_closed looping for all bot instances
J.Lo said:
It appears this is intended behavior because of the way the event is wired. It's wired this way because it's on the “Positions” collection, not the individual “Position”. The “positions” is all the positions, not just a singular one.
https://help.ctrader.com/ctrader-algo/references/Trading/Positions/Positions/#closed
It occurs every time a position is closed. So it doesn't matter if a position is closed from a bot, a stop loss, a take profit, or someone manually closing it. That's why there's the “args” parameter is supplied so you can filter the event based on the symbol from the “positions” collection.
@firemyst