Topics
08 Sep 2016, 03:36
 4674
 13
Replies

sebnet
11 Sep 2016, 02:08

RE:

Ok, I am storing the SL and TP values on the comment field. Not the ideal solution but it works because it is done for my own trading.

cAlgo could easily solve this if they store the SL and TP values (in pips) as properties of the object, no matter if the position is yet modified or not, just as another descriptive fields. Then you have the real SL and TP expressed in prices (not pips) as the real values after the trade was updated.

Besides, it's better to have those values in pips instead of converted to prices, because we have to do some math to get back the value in pips.


@sebnet

sebnet
09 Sep 2016, 17:34

RE: Sample Code

Paul_Hayes said:

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DuplicateOrders : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            Positions.Opened += OnPositionOpened;
        }

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

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


        private void OnPositionOpened(PositionOpenedEventArgs args)
        {
            System.Threading.Thread.Sleep(5000);
            var p = args.Position;

            for (int i = 0; i < 2; i++)
            {
                if (p.Label != "duplicates")
                {
                    ExecuteMarketOrder(p.TradeType, this.Symbol, p.Volume, "duplicates", p.StopLoss, p.TakeProfit);
                }
            }
        }
    }
}

 

I think you should access the "this.Positions" collection to get the SL and TP because the args.Position is not updated after the Sleep.


@sebnet

sebnet
09 Sep 2016, 00:54

Great, thanks for the tip!


@sebnet

sebnet
12 Aug 2016, 16:51

I just found that the position price is moved to the average price of both positions. 


@sebnet