get Symbol.Bid from another symbol

Created at 12 Sep 2019, 12:45
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!
swingfish's avatar

swingfish

Joined 25.06.2016

get Symbol.Bid from another symbol
12 Sep 2019, 12:45


i have a bot that makes changes to multiple positions, to calculate values i would need to get the Ask/Bid Price from the symbol the position is actually on .. 

 

any idea how to do this? 

                        foreach (var pos in Positions)
                        {
                            if (pos.TradeType == TradeType.Buy)
                            {
                                TslP = Symbol.Bid - (Symbol.PipSize * Tsl);
                            }
                            else
                            {
                                TslP = Symbol.Ask + (Symbol.PipSize * Tsl);
                            }

                            ModifyPositionAsync(pos, TslP, 0, true);

                        }

this does work but only if the bot runns on the same symbol

 


@swingfish
Replies

PanagiotisCharalampous
12 Sep 2019, 12:56

Hi Mario,

Here is an example

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 NewcBot : Robot
    {
        Symbol _gbpjpy;

        protected override void OnStart()
        {
            _gbpjpy = Symbols.GetSymbol("GBPJPY");
        }

        protected override void OnTick()
        {
            Print("GBPJPY Bid: " + _gbpjpy.Bid);
            Print("GBPJPY Ask: " + _gbpjpy.Ask);
        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous