bot help to close all positions

Created at 20 Sep 2015, 14:00
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!
WB

wbachusz

Joined 20.09.2015

bot help to close all positions
20 Sep 2015, 14:00


Hi,
Is there a bot that closes all positions when the profits from all items exceeds a given positive value, for example: <100, 200, etc.
Thank you for your help.

 


@wbachusz
Replies

wbachusz
20 Sep 2015, 14:01

RE:

wbachusz said:

Hi,
Is there a bot that closes all positions when the profits from all items exceeds a given positive value, for example: <100, 200, etc.
Thank you for help.

 

 


@wbachusz

ClickAlgo
20 Sep 2015, 20:50

Take a look at this:- http://rmmrobot.com/


@ClickAlgo

cerana
21 Sep 2015, 15:49

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class profit : Robot
    {
        [Parameter(DefaultValue = 100.0)]
        public double Parameter { get; set; }



        protected override void OnTick()
        {
            int? a = null;
            int? b = null;

            foreach (var position in Positions)
                a++;
            foreach (var position in Positions)
                if (position.Pips > Parameter)
                    b++;
            if (a == b)
                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }

        }

        
    }
}

                                                                                                                                                                                                                       


@cerana

cerana
21 Sep 2015, 16:39

Or :instead position.Pips: . Symbol.UnrealizedNetProfit >Parameter                                                                                                                                    


@cerana

cerana
21 Sep 2015, 17:08

 

 

 

 

 

 

 

 

 

 

 

 

Instead null!! Symbol.UnrealizedNetProfit : if all positions a form of currency.

 

 

 

 

 

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using cAlgo.API.Requests;
using System.Threading;
using System.Timers;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class profit : Robot
    {
        [Parameter(DefaultValue = 100.0)]
        public double Parameter { get; set; }



        protected override void OnTick()
        {
            int a = 0;
            int b = 0;

            foreach (var position in Positions)
                a++;
            foreach (var position in Positions)
                if (position.Pips > Parameter)
                    b++;
            if (a == b)
                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }







        }
    }
}

                                                                                                                                                                                                              


@cerana

moneybiz
21 Sep 2015, 21:29

RE:

cerana said:

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using cAlgo.API.Requests;
using System.Threading;
using System.Timers;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class profit : Robot
    {
        [Parameter(DefaultValue = 100.0)]
        public double Parameter { get; set; }



        protected override void OnTick()
        {
            int a = 0;
            int b = 0;

            foreach (var position in Positions)
                a++;
            foreach (var position in Positions)
                if (position.Pips > Parameter)
                    b++;
            if (a == b)
                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }
        }
    }
}

                                                                                                                                                                                                              

 

Why you don't close every position at once like this?

protected override void OnTick()
{
	foreach (var position in Positions.Where(p=> p.NetProfit > Parameter).ToArray())
	{
		ClosePosition(position);
	}
}

        

            

 


@moneybiz

wbachusz
21 Sep 2015, 23:22

RE:

                                                                                                                                  

thanks a lot!!! is what I mean, the program is working properly.


@wbachusz

alistadd
04 Feb 2016, 11:11

Hello, i'm new to this its not working for me can you please put exactly as soon as it gets to 5 dollars profit it closes all positions, i've tried changing parameters? sometimes it closes even it i change the 100 to 3.5 it will go to even 10 dollars profit and not even close please help, i just want to make 5 dollars and close all positions sometimes i have like 6 different currencys open its not working. I think something has been left out

 

using System;

using System.IO;

using System.Collections.Generic;

using System.Linq;

using System.Collections;

using cAlgo.API;

using cAlgo.API.Internals;

using cAlgo.API.Indicators;

using cAlgo.Indicators;

using cAlgo.API.Requests;

using System.Threading;

using System.Timers;

 

namespace cAlgo

{

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]

    public class profit : Robot

    {

        [Parameter(DefaultValue = 100.0)]

        public double Parameter { get; set; }

 

 

 

        protected override void OnTick()

        {

            int a = 0;

            int b = 0;

 

            foreach (var position in Positions)

                a++;

            foreach (var position in Positions)

                if (position.Pips > Parameter)

                    b++;

            if (a == b)

                foreach (var position in Positions)

                {

                    ClosePosition(position);

                }

 

 

 

 

 

 

 

        }

    }

}

 

 

can you please do it exactly for 5 dollars once hits 5 dollars profit for all positions open thankyou kindly

 

 


@alistadd

alistadd
04 Feb 2016, 11:13

I tried changing perameter to 5 dollars but doesn't work please help thanks


@alistadd

tradermatrix
05 Feb 2016, 12:11

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


namespace cAlgo.Robots
{
    [Robot()]
    public class LIQUIDATE : Robot
    {


        [Parameter("TotalProfit", DefaultValue = 100)]
        public double TotalProfit { get; set; }

        //////////////////////////////////////////////////// 

        // Do not forget the "-"
        [Parameter("TotalLoss", DefaultValue = -100)]

        public double TotalLoss { get; set; }

        protected override void OnStart()
        {



            string text = "★ Liquidate ★ By TradermatriX ★";

            base.ChartObjects.DrawText("★ Liquidate ★ By TradermatriX ★", text, StaticPosition.TopLeft, new Colors?(Colors.Lime));



        }
        protected override void OnTick()
        {


            var netProfit = 0.0;
            foreach (var openedPosition in Positions)
            {
                netProfit += openedPosition.NetProfit + openedPosition.Commissions;
            }
            ChartObjects.DrawText("a", netProfit.ToString(), StaticPosition.BottomRight, new Colors?(Colors.Lime));

            {
                if (Account.Equity - Account.Balance > TotalProfit || Account.Equity - Account.Balance < TotalLoss)
                {

                    foreach (var openedPosition in Positions)
                    {

                        ClosePosition(openedPosition);


                        foreach (var pendingOrder in PendingOrders)
                        {

                            CancelPendingOrder(pendingOrder);



                        }
                    }
                }
            }
        }
    }
}

alistadd said:

I tried changing perameter to 5 dollars but doesn't work please help thanks

 


@tradermatrix