Hedge Scalping Bot Help

Created at 23 May 2017, 05:16
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!
DE

derekszyszka

Joined 15.10.2016

Hedge Scalping Bot Help
23 May 2017, 05:16


Would it be possible to creat a hedging bot the places a BUY and SELL stop within 5 pips if current price (for example) 

Once the either BUY or SELL position has been filled the bot automaticlly cancels the vice versa pending order and continues on with a preset TP and SL on the position that was filled..

Any insite would be helpfull.


@derekszyszka
Replies

Mikro
09 Jun 2017, 17:38

You can create these two Orders as pending Orders and subscribe to the ServerEvent if Orders are filled.

If one Order is filled you cancel the other an set your intended Stop-Levels. Like so:

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

namespace cAlgo
{
    [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.Opened += OnPositionOpened;
            PlaceStopOrder(TradeType.Buy, this.Symbol, 10000, Symbol.Ask + 15*Symbol.PipSize);
            PlaceStopOrder(TradeType.Sell, this.Symbol, 10000, Symbol.Bid - 15 * Symbol.PipSize);
        }

        protected override void OnTick()
        {
            
        }

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

        public void OnPositionOpened(PositionOpenedEventArgs args)
        {
            foreach (PendingOrder pOrder in PendingOrders)
            {
                CancelPendingOrderAsync(pOrder);
            }
            foreach (Position pos in Positions)
            {
                if (pos.TradeType==TradeType.Buy)
                {
                    ModifyPosition(pos, pos.EntryPrice - 15*Symbol.PipSize, pos.EntryPrice + 30*Symbol.PipSize);
                }
                else
                {
                    ModifyPosition(pos, pos.EntryPrice + 15*Symbol.PipSize, pos.EntryPrice - 30*Symbol.PipSize);
                }
            }
        }
    }
}

 


@Mikro