Reverse Position For All Open Trades?

Created at 12 Jun 2019, 04:51
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
BI

bitmext

Joined 12.06.2019

Reverse Position For All Open Trades?
12 Jun 2019, 04:51


Hello , wish you well.

 

First of all , I would like to thank you for your amazing platform. I hope you continue your excellent work.

 

I really like the feature of 'Reverse position' , However sometimes I open several at different entry points and I was wondering how do I Reverse all of them with one click? Instead of single handedly clicking reverse on each which can be quite frustrating in moving markets.

I only trade one pair at a time so there are no worries about other positions reversing.

 

My technical knowledge is very little so I thought this would be the right place to ask.

 

Thank you.


@bitmext
Replies

PanagiotisCharalampous
12 Jun 2019, 09:35

Hi bitmext,

Thanks for posting in our forum and for your nice feedback about the platform. There is no feature in the interface that would allow you to do so but you can achieve this by running a simple cBot. See the source code below

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ReversePositions : Robot
    {

        protected override void OnStart()
        {
            foreach (var position in Positions)
                position.Reverse();
            Stop();
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

bitmext
13 Jun 2019, 07:32

RE:

Panagiotis Charalampous said:

Hi bitmext,

Thanks for posting in our forum and for your nice feedback about the platform. There is no feature in the interface that would allow you to do so but you can achieve this by running a simple cBot. See the source code below

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ReversePositions : Robot
    {

        protected override void OnStart()
        {
            foreach (var position in Positions)
                position.Reverse();
            Stop();
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis

I have just tested this on my Demo Account and it works perfectly !

Exactly what I needed, Thank you very much.


@bitmext

office3131
15 Nov 2019, 05:13

I have several positions with different labels. When I use position.Reverse(); the labels are deleted, so I can`t use a command like var allposcheck = Positions.FindAll(Label)

How to keep the existing label of the position?

 


@office3131