Topics
26 Jun 2019, 11:52
 0
 1100
 1
Replies

YMYMYM
08 Jul 2019, 19:11

RE:

Thanks Panagiotis.  It worked exactly as I wanted.  Basically closes all open positions and pending orders in a specific chart only.  Grateful for help!

 

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ClosePositionsOrders : 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.Where(x => x.SymbolName == Symbol.Name))
                {
                    ClosePosition(position);
                }

            foreach (var order in PendingOrders.Where(x => x.SymbolCode == Symbol.Name))
            {
                CancelPendingOrder(order);
            }
            Stop();

        }

    }
}

 


@YMYMYM

YMYMYM
05 Jul 2019, 18:43

RE:

Hi Panagiotis, if I might seek your help again. Will it be possible to add another line so that it also Cencels all Pending Orders in the same symbol/chart at the same time when open positions r closed?  I use grid  strategy.  After your help I am able to csuccessfully closed all open positions in a chart but for the pending orders I have to do it manually.  I tried to play around with coding but no success.  

Regards

{
  foreach (var order in PendingOrders)
  {
  CancelPendingOrder(order);
  }

  

 

Hi amarnadeem1,

See below

using System;
using cAlgo.API;
using System.Linq;
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.Where(x => x.SymbolName == Symbol.Name))
                {
                    ClosePosition(position);
                }

        }

    }
}

Best Regards,

Panagiotis

 


@YMYMYM

YMYMYM
05 Jul 2019, 15:13

Thanks a lot Panagiotis for quick help.  Works perfectly.  Appreciate it!  

 

@YMYMYM