How to get ask price

Created at 10 Feb 2021, 23:41
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!
acnestis's avatar

acnestis

Joined 11.04.2019

How to get ask price
10 Feb 2021, 23:41


Hello! How to get ask price for previous bar (bar by index)?

I'm using following to get lower bid price for bar by index i.

barLow = Bars.LowPrices.Last(i);

So, how to get the lower ask price?


@acnestis
Replies

PanagiotisCharalampous
11 Feb 2021, 08:29

Hi robustby,

The ask price is not available. Bars are created using bid prices. To get ask prices you need to get the tick data using MarketData.GetTicks() and loop through the ticks to find the lowest for the bar's period.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

acnestis
11 Feb 2021, 10:17

RE:

PanagiotisCharalampous said:

Hi robustby,

The ask price is not available. Bars are created using bid prices. To get ask prices you need to get the tick data using MarketData.GetTicks() and loop through the ticks to find the lowest for the bar's period.

Best Regards,

Panagiotis 

Join us on Telegram

Thank you! Can you write some example how to use it?


@acnestis

... Deleted by UFO ...

PanagiotisCharalampous
11 Feb 2021, 10:56

Hi robustby,

Here is an example of how to load all ticks for the bars loaded on your chart.

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

        protected override void OnStart()
        {
            var ticks = MarketData.GetTicks();
            while (ticks[0].Time > Bars[0].OpenTime)
            {
                ticks.LoadMoreHistory();
                Print("Loaded till " + ticks[0].Time);
            }
            Print("Ticks loaded");
        }

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

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

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

acnestis
11 Feb 2021, 12:52

RE:

PanagiotisCharalampous said:

Hi robustby,

Here is an example of how to load all ticks for the bars loaded on your chart.

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

        protected override void OnStart()
        {
            var ticks = MarketData.GetTicks();
            while (ticks[0].Time > Bars[0].OpenTime)
            {
                ticks.LoadMoreHistory();
                Print("Loaded till " + ticks[0].Time);
            }
            Print("Ticks loaded");
        }

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

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

Best Regards,

Panagiotis 

Join us on Telegram

Thank you so much for the example. Can you check if I'm right? If I want to get lower Ask price I'm doing following:

            var ticks = MarketData.GetTicks();
            while (ticks[0].Time > Bars[0].OpenTime)
            {
                ticks.LoadMoreHistory();
                Print("Loaded till " + ticks[0].Time);

            }
            Print("Ticks loaded");

            int tickIndex = 1;
            int NumberOfTicks = 10000;
            double GetAskLow = ticks[0].Ask; //get last Ask tick in the left of chart
            for (int i = tickIndex; i < ticks.Count; i++)
            {
                if (ticks[i].Ask < GetAskLow)
                {
                    GetAskLow = ticks[i].Ask;
                }

            }
            Print("GetAskLow = ", GetAskLow);

Also, I have some questions:

1) If I want to use only last 10000 ticks, how better load it? Or if I want use ticks data for only 50 last bars at the chart?

2) I must use MarketData.GetTicks() & ticks.LoadMoreHistory() for every time when new tick appears? Please explain how it works.


@acnestis

PanagiotisCharalampous
11 Feb 2021, 14:59

Hi robustby,

Thank you so much for the example. Can you check if I'm right? If I want to get lower Ask price I'm doing following:

It seems correct to me

1) If I want to use only last 10000 ticks, how better load it? Or if I want use ticks data for only 50 last bars at the chart?

You should load until this condition is me e.g.

while (ticks.Count < 100000)

I must use MarketData.GetTicks() & ticks.LoadMoreHistory() for every time when new tick appears? Please explain how it works.

The list is not updated with every incoming tick. Therefore you should make the respective arrangements if this is something that is important for you i.e. add the new ticks to the list.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous