Probleme MarketData GetSymbol

Created at 02 May 2017, 12:40
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!
TR

tradermatrix

Joined 24.07.2012

Probleme MarketData GetSymbol
02 May 2017, 12:40


I build a cbot with several symbol
for example
The robot opens a buy position and automatically opens a reverse stop order (shell)
The robot opens the requested position ... eg gbpusd.
And it opens the stop order gbpusd but provided that the instance is GBPUSD ..
If the instance is EURUSD the buy gbpusd position opens but not the stop order shell
Someone can illuminate my lantern ...
 

Piece of code

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 SamplecBot : Robot
    {


        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("Distance Pips LimitOrder", DefaultValue = 40)]
        public int PipsAway { get; set; }

        private Symbol _symbol1;

        private void InitializeSeries1(string symbolCode)
        {
            _symbol1 = MarketData.GetSymbol("GBPUSD");

        }


        protected override void OnStart()
        {

            InitializeSeries1("GBPUSD");
            Positions.Opened += OnPositionOpened;
        }

        protected override void OnTick()
        {
            var position = Positions.Find("Sample", Symbol);
            var volumeInUnits = Symbol.QuantityToVolume(Quantity);
            var cBotPositions = Positions.FindAll("Sample");

            if (cBotPositions.Length >= 1)
                return;

            ExecuteMarketOrder(TradeType.Buy, _symbol1, volumeInUnits, "Sample", 80, 40);


        }

        private void OnPositionOpened(PositionOpenedEventArgs positionClosedEventArgs)
        {
            var openedPosition = positionClosedEventArgs.Position;

            if (openedPosition.Label != "Sample" || openedPosition.SymbolCode != Symbol.Code)
                return;

            CreatePendingOrder(openedPosition);
        }
        private void CreatePendingOrder(Position position)
        {
            DateTime exp = MarketSeries.OpenTime.LastValue.AddHours(12);

            var volumeInUnits = Symbol.QuantityToVolume(Quantity);

            {
                var sellOrderTargetPrice = Symbol.Bid - PipsAway * Symbol.PipSize;

                PlaceStopOrder(TradeType.Sell, _symbol1, volumeInUnits * 2, sellOrderTargetPrice, "Sample2", 20, 70, exp);




            }

        }
    }
}

 


@tradermatrix
Replies

... Deleted by UFO ...

tradermatrix
02 May 2017, 13:32

RE:

Super lucian
A small error and serious consequences but thanks to your help I will be able to modify my cbot.
thanks again

 

lucian said:

in line 55 , try to use: 

 if (openedPosition.Label != "Sample" || openedPosition.SymbolCode != _symbol1.Code)

instead of:

 if (openedPosition.Label != "Sample" || openedPosition.SymbolCode != Symbol.Code)

 

 


@tradermatrix