Replies

dr.erick.rd
22 Aug 2024, 16:45

RE: RE: RE: I need help to close the reverse position after the reset

PanagiotisCharalampous said: 

dr.erick.rd said: 

PanagiotisCharalampous said: 

Hi there,

Please share the complete cBot code since it is not possible understand everything you are doing just from a snippet.

Best regards,

Panagiotis

Hello. The only thing I really want is for my cTrader account to only allow operations in one direction and when I open an operation, the ones in the opposite direction are closed. I used to have that type of account but now they all allow hedging.

Hi there,

Here is an example

using System;using System.Collections.Generic;using System.Linq;using System.Text;using cAlgo.API;using cAlgo.API.Collections;using cAlgo.API.Indicators;using cAlgo.API.Internals;namespace cAlgo.Robots{    [Robot(AccessRights = AccessRights.None)]    public class CloseOpposite : Robot    {        protected override void OnStart()        {            Positions.Closed += Positions_Closed;        }        private void Positions_Closed(PositionClosedEventArgs obj)        {            foreach (var position in Positions.Where(p => p.TradeType != obj.Position.TradeType))            {                position.Close();            }        }        protected override void OnTick()        {            // Handle price updates here        }        protected override void OnStop()        {            // Handle cBot stop here        }    }}

Best regards,

Panagiotis

Thank you very much, you saved me


@dr.erick.rd

dr.erick.rd
21 Aug 2024, 08:06 ( Updated at: 21 Aug 2024, 13:38 )

RE: I need help to close the reverse position after the reset

PanagiotisCharalampous said: 

Hi there,

Please share the complete cBot code since it is not possible understand everything you are doing just from a snippet.

Best regards,

Panagiotis

Hello. The only thing I really want is for my cTrader account to only allow operations in one direction and when I open an operation, the ones in the opposite direction are closed. I used to have that type of account but now they all allow hedging.


@dr.erick.rd