PlaceLimitteOrder

Created at 01 Jan 2019, 08:03
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!
KH

khemrathy

Joined 01.01.2019

PlaceLimitteOrder
01 Jan 2019, 08:03


How to constantly automate the cBot to re-enter PlaceLimiteOrder at orgianl price for exery existing position when its StopLoss is hit?


@khemrathy
Replies

PanagiotisCharalampous
02 Jan 2019, 11:50

Hi khemrathy,

Thanks for posting in our forum. See below an example on how to achieve this.

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 MarketAnalysis : Robot
    {
      
        protected override void OnStart()
        {
            Positions.Closed += Positions_Closed;
        }

        private void Positions_Closed(PositionClosedEventArgs obj)
        {
            if (obj.Reason == PositionCloseReason.StopLoss)
                PlaceLimitOrder(obj.Position.TradeType, Symbol, obj.Position.VolumeInUnits, obj.Position.EntryPrice);
        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous