How to reference another Symbol in an indicator?

Created at 21 Jan 2021, 04:00
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!
JA

jackhpfilerrowson

Joined 26.11.2020

How to reference another Symbol in an indicator?
21 Jan 2021, 04:00


Is there a way to reference the current GbpUsd price in this indicator where GbpUsd is in brackets?

 

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ATRPIPWithEMA : Indicator
    {

        private SimpleMovingAverage High;
        private SimpleMovingAverage Low;
        private double C;
        private double Volume;
        private double VolumeUsd;
        private double lot;
        private double Lot;

        protected override void Initialize()
        {
            High = Indicators.SimpleMovingAverage(Bars.HighPrices, 1);
            Low = Indicators.SimpleMovingAverage(Bars.LowPrices, 1);
            C = High.Result.LastValue - Low.Result.LastValue;
            Volume = (0.57 * High.Result.LastValue) / C;
            VoluemUsd = Volume * (GbpUsd)
            lot = 100000 * High.Result.LastValue;
            Lot = Volume / lot;
        }
        public override void Calculate(int index)
        {
            if (index == 0)
                DisplayPositionSizeRiskOnChart();
        }
        private void DisplayPositionSizeRiskOnChart()
        {
            string text = " Lot " + " = " + Math.Round(Lot, 2);
            ChartObjects.DrawText("Lot", text, StaticPosition.TopLeft, Colors.FloralWhite);
        }
    }
}


@jackhpfilerrowson
Replies

firemyst
21 Jan 2021, 04:59

Here is some sample code off the top of my head on how to reference another symbol within the current one:

 

Symbols.GetSymbol(MarketData.GetBars(Bars.TimeFrame, "GBPUSD").SymbolName);

 


@firemyst

jackhpfilerrowson
21 Jan 2021, 12:36

RE:

firemyst said:

Here is some sample code off the top of my head on how to reference another symbol within the current one:

 

Symbols.GetSymbol(MarketData.GetBars(Bars.TimeFrame, "GBPUSD").SymbolName);

 

Thanks, ill give it a go 


@jackhpfilerrowson

... Deleted by UFO ...

... Deleted by UFO ...