Price

Created at 24 Jan 2018, 21:12
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!
DelFonseca's avatar

DelFonseca

Joined 25.06.2017

Price
24 Jan 2018, 21:12


Good evening,

how can I for example have the EURUSD chart and through "ChartObjects.DrawText" have the current USDJPY price indication in the chart ?

Thank you


@DelFonseca
Replies

PanagiotisCharalampous
25 Jan 2018, 12:24

Hi DelTrader,

See an example below

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            var USDJPY = MarketData.GetSymbol("USDJPY");
            var name = "myObject";
            var low = MarketSeries.Low.LastValue;
            var text = USDJPY.Ask.ToString();
            var xPos = MarketSeries.Low.Count;
            var yPos = low;
            var vAlign = VerticalAlignment.Bottom;
            var hAlign = HorizontalAlignment.Right;
            ChartObjects.DrawText(name, text, xPos, yPos, vAlign, hAlign, Colors.Red);
        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous

DelFonseca
25 Jan 2018, 20:24

RE:

Panagiotis Charalampous said:

Hi DelTrader,

See an example below

using System;
(...)

Best Regards,

Panagiotis

HI Panagiotis,

Thank you, thank you so much !! You're awesome !! Cheers


@DelFonseca

DelFonseca
25 Jan 2018, 23:04

Helo again,

I have 2 problems now, im trying calculate Bid-Ask to get single result but i cant. And im trying Create if structure but i cant.

The problem with operators '-' and '>', because they cant be apllied in operands of type 'string'.

Can you help me?

The structure:

 

        protected override void OnTick()
        {
            var Symbol1MarketData = MarketData.GetSymbol(Symbol1);
            var Symbol2MarketData = MarketData.GetSymbol(Symbol2);
            var Symbol3MarketData = MarketData.GetSymbol(Symbol3);

            var Symbol1Low = MarketSeries.Low.LastValue;
            var Symbol2Low = MarketSeries.Low.LastValue;
            var Symbol3Low = MarketSeries.Low.LastValue;

            var Symbol1Bid = Symbol1MarketData.Bid.ToString();
            var Symbol2Bid = Symbol2MarketData.Bid.ToString();
            var Symbol3Bid = Symbol3MarketData.Bid.ToString();

            var Symbol1Ask = Symbol1MarketData.Ask.ToString();
            var Symbol2Ask = Symbol2MarketData.Ask.ToString();
            var Symbol3Ask = Symbol3MarketData.Ask.ToString();
            
            var Symbol1Result = Symbol1Bid - Symbol1Ask;
            var Symbol2Result = Symbol2Bid - Symbol2Ask;
            var Symbol3Result = Symbol3Bid - Symbol3Ask;

            if (Symbol1Result > Symbol2Result > Symbol3Result)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits);
            }
        }

 


@DelFonseca

PanagiotisCharalampous
26 Jan 2018, 10:13

Hi DelTrader,

See below a correct way to write this function

        protected override void OnTick()
        {
            var Symbol1MarketData = MarketData.GetSymbol("EURUSD");
            var Symbol2MarketData = MarketData.GetSymbol("USDJPY");
            var Symbol3MarketData = MarketData.GetSymbol("EURGBP");

            var Symbol1Low = MarketSeries.Low.LastValue;
            var Symbol2Low = MarketSeries.Low.LastValue;
            var Symbol3Low = MarketSeries.Low.LastValue;

            var Symbol1Bid = Symbol1MarketData.Bid;
            var Symbol2Bid = Symbol2MarketData.Bid;
            var Symbol3Bid = Symbol3MarketData.Bid;

            var Symbol1Ask = Symbol1MarketData.Ask;
            var Symbol2Ask = Symbol2MarketData.Ask;
            var Symbol3Ask = Symbol3MarketData.Ask;

            var Symbol1Result = Symbol1Bid - Symbol1Ask;
            var Symbol2Result = Symbol2Bid - Symbol2Ask;
            var Symbol3Result = Symbol3Bid - Symbol3Ask;

            if (Symbol1Result > Symbol2Result && Symbol2Result > Symbol3Result)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, 1000);
            }
        }

Let me know if this helps,

Best Regards,

Panagiotis


@PanagiotisCharalampous

DelFonseca
26 Jan 2018, 19:58

RE:

Panagiotis Charalampous said:

Hi DelTrader,

See below a correct way to write this function

        protected override void OnTick()
        {
         (...)
        }

Let me know if this helps,

Best Regards,

Panagiotis

Perfect!! You'r the guy !! Thank you so much. Im trying creating Triangular Arbitrage Bot. Thank you so much !!!


@DelFonseca