Accessing previous bid or ask price

Created at 28 May 2018, 03:37
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!
PO

pogostick

Joined 12.05.2018

Accessing previous bid or ask price
28 May 2018, 03:37


I would like to compare the current bid or ask price to the previous ticks' bid or ask price. How can I do that?

I would prefer to not use the previous bar's open, close, high, low, etc prices as I would like to compare price movement during the formation of a bar.

Thanks


@pogostick
Replies

PanagiotisCharalampous
29 May 2018, 16:41

Hi pogostick,

You can always keep the previous price in a variable. 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.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private double _previousAsk;
        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            if (_previousAsk > Symbol.Ask)
            {
                //do something
            }
            _previousAsk = Symbol.Ask;
        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous