PLEASE HELP!!!

Created at 13 Apr 2020, 01:39
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!
MA

mahnas2869

Joined 13.04.2020

PLEASE HELP!!!
13 Apr 2020, 01:39


Hi.. I'm trying for a long time now to find a way to get historical Ask data, which along with the Bid it can include historical spreads to a file, and i couldn't find it anywhere.. Is it possible at all? i saw there's a market depth with ask data but i couldn't get it from there too..


So there anyone who can help? that would be very much appreciated.. I'm looking for an historical spreads, not the OnTick current Bid and Ask, or spread value.. Like the past Ask data [As the default on MarketSeries.O/H/L/C[x] is bid price so i need the Ask price] of the last week, on say 1 minute TF or Hourly or whatever..
 


Thanks ahead! And have a nice day..


@mahnas2869
Replies

PanagiotisCharalampous
13 Apr 2020, 09:06

Hi mahnas2869,

You can get both Bid and Ask prices in backtesting, hence you can calculate the spread as well. See 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; }

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

        protected override void OnTick()
        {
            Print("Ask: " + Symbol.Ask);
            Print("Bid: " + Symbol.Bid);
            Print("Spread: " + Math.Round(Symbol.Ask - Symbol.Bid, Symbol.Digits));
        }

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

 

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

YC1186
28 Jul 2020, 19:04

RE:

PanagiotisCharalampous said:

Hi mahnas2869,

You can get both Bid and Ask prices in backtesting, hence you can calculate the spread as well. See 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; }

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

        protected override void OnTick()
        {
            Print("Ask: " + Symbol.Ask);
            Print("Bid: " + Symbol.Bid);
            Print("Spread: " + Math.Round(Symbol.Ask - Symbol.Bid, Symbol.Digits));
        }

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

 

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi.. That's the code for the current BidAsk, i meant for the Historical Spreads..


@YC1186

ap11
29 Jul 2020, 15:11

Run following code in Backtesting using Tick Data from Server
You will get .csv file with tick data history.

[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
public class NewcBot : Robot
{
    private StringBuilder sb = new StringBuilder();

    protected override void OnTick()
    {
        sb.AppendLine(string.Format("{0},{1},{2}", Time.ToString("dd.MM.yyyy HH:mm:ss.fff"), Bid, Ask));
    }

    protected override void OnStop()
    {
        var filePath = string.Format("c:\\temp\\{0}.csv", SymbolName);
        File.WriteAllText(filePath, sb.ToString());
    }
}

 


@ap11

YC1186
24 Dec 2020, 23:52

RE:

Hi.. Thanks and sorry for the late reply.. So how do i do that? Running this code on backtesting? And how far back i cab go?..

Thanks..

 

 

AndreiPisarev said:

Run following code in Backtesting using Tick Data from Server
You will get .csv file with tick data history.

[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
public class NewcBot : Robot
{
    private StringBuilder sb = new StringBuilder();

    protected override void OnTick()
    {
        sb.AppendLine(string.Format("{0},{1},{2}", Time.ToString("dd.MM.yyyy HH:mm:ss.fff"), Bid, Ask));
    }

    protected override void OnStop()
    {
        var filePath = string.Format("c:\\temp\\{0}.csv", SymbolName);
        File.WriteAllText(filePath, sb.ToString());
    }
}

 

 


@YC1186

PanagiotisCharalampous
28 Dec 2020, 08:55

Hi YC1186,

So how do i do that? Running this code on backtesting?

Yes

 And how far back i cab go?..

As far as your broker provides history for.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous