Close all Profitable Positions

Close all Profitable Positions
05 Sep 2012, 16:20
This is a sample of how to close all profitable position in your account, from a cBot (cAlgo Robot)
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Robots { [Robot] public class CloseProfitablePositions : Robot { protected override void OnStart() { foreach (var position in Positions) { if (position.GrossProfit > 0) { ClosePosition(position); } } } } }
Replies
harry
01 Sep 2016, 03:37
RE: Close all Profitable Positions based on Pips Count
say we target 3 pips, we can
change the
if (position.GrossProfit > 0)
from provided sample code above into
if (position.pips > 3)
cmiimw :)
susantasaren said:
Hi,
Can you provide a code so that the trade closes automatically when a certain value of Pip is reached.
i.e like an auto Take Profit applies based on Pips as soon as we go into a trade.
Best Regards.
@harry
marlowmable
20 Jan 2017, 03:44
hedging cbot
Hi all,
Can anyone post a sample of hedging cbot..
I really apriciate it..,
thank you.
@marlowmable
kricka
20 Jan 2017, 14:57
Closing positions on pips
The Close Positions 2.0 can handle closing only positions that are in a certain profit or loss in pips. When the cBot is stopped it only closes the positions specified in the setup of the cBot.
Test it out, free to download here: Close Positions 2.0
@kricka
amanuel.pascher
28 Jan 2019, 00:35
multiple closes
I have a problem with the bot.
After it close one position perfectly it doesn't close the next position which was opened afterwards.
I have then to turn the bot off and on again before it closes also the next position.
How can I either automatically start the bot again or close more than just one position again and again?
Thak you for your help.
@amanuel.pascher
Panagiotis Charalampous
28 Jan 2019, 12:18
Hi Amanuel,
Depending on when you want to close the positions, you can move the code into OnBar or OnTick methods or even call it based on a custom interval using the Timer property. See below an example.
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Robots { [Robot()] public class CloseProfitablePositions : Robot { protected override void OnBar() { foreach (var position in Positions) { if (position.GrossProfit > 0) { ClosePosition(position); } } } } }
Best Regards,
Panagiotis
@PanagiotisCharalampous
Mr4x
05 Jan 2020, 04:50
Faster way to close all positions?
Hi,
Is there a faster way to close all positions than this code? When executing this against multiple positions that are open, it seems to close them one by one with half a second apart. When scalping this can turn a winning trade into a losing trade from the time lag, as I experienced the other day.
When you double click "Close All Positions" within cTrader it does actually close them all at the exact same time (or very close to), not one by one. Is there anyway cAlgo can do this? If not, can you write some code into a future version of cTrader which basically mimics the "Close All Positions" button?
Regards,
Mr4x
@Mr4x
Panagiotis Charalampous
07 Jan 2020, 09:22
RE: Faster way to close all positions?
Hi Mr4x,
Try using ClosePositionsAsync instead.
Best Regards,
Panagiotis
@PanagiotisCharalampous
Obiriec
12 Feb 2020, 16:56
RE:
admin said:
This is a sample of how to close all profitable position in your account, from a cBot (cAlgo Robot)
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Robots { [Robot] public class CloseProfitablePositions : Robot { protected override void OnStart() { foreach (var position in Positions) { if (position.GrossProfit > 0) { ClosePosition(position); } } } } }
Good morning Panagiotis, congratulations on your work here on this forum.
I apologize for my poor English, I am using google translator !!
I would like to know if it is possible to modify an existing cBot, which is used to close all positions of a specific currency pair (eg EURUSD) when these have reached a certain "break even" value and make sure that - - if the profit of all the open positions reaches the trigger and goes back, of course they close to reach the break even value --- but --- it would be very convenient if you could make sure that --- if once the trigger is reached, the profit continues to increase, you could move the trigger itself with a trail value, so everything follows the profit and when it comes back, the trail remains still.
A sort of Trailing Stop Loss for Break Even !!
The parameters that must be managed by the user, in addition to those used for managing the values, it should also be possible to enter the "label" (magic number) and the name of the currency pair in question.
I don't know if I'm asking for an impossible thing but I think I asked the right person the question.
Looking forward to your reply,
Yours sincerely.
Armando Brecciaroli
@Obiriec
Susanta Saren
19 Feb 2013, 23:35
Close all Profitable Positions based on Pips Count
Hi,
Can you provide a code so that the trade closes automatically when a certain value of Pip is reached.
i.e like an auto Take Profit applies based on Pips as soon as we go into a trade.
Best Regards.
@susantasaren