open a new operation in a new instance

Created at 26 Mar 2020, 09:06
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!
LU

luca.tocchi

Joined 25.03.2020

open a new operation in a new instance
26 Mar 2020, 09:06


hi how can i do this?

I have an open position on an instance, when this operation reaches the stop loss or take profit, the bot must open another operation in another instance

what is the code to do this?


@luca.tocchi
Replies

PanagiotisCharalampous
26 Mar 2020, 09:24

Hi Luca,

You can use Position.Closed event to monitor when a position is closed and take an appropriate action. See below an example

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            Positions.Closed += Positions_Closed;
        }

        private void Positions_Closed(PositionClosedEventArgs obj)
        {
        }

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

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

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

luca.tocchi
26 Mar 2020, 09:57

RE:

PanagiotisCharalampous ha detto:

Ciao Luca,

possibile utilizzare l'evento Position.Closed per tracciae quando un posizione parte chiuso e imprevedibile un'azione. Sotto vedi un esempio

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            Positions.Closed += Positions_Closed;
        }

        private void Positions_Closed(PositionClosedEventArgs obj)
        {
        }

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

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

Migliori saluti

Panagiotis 

Comi a noi su Telegram

 

Thanks! ok i use the event closed position. but to open a random instance, at the beginning of the program, without a condition occurring?


@luca.tocchi

PanagiotisCharalampous
26 Mar 2020, 13:47

Hi Luca,

To open a position at the start of the cBot use the OnStart() method.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous