Data Extract

Created at 06 Oct 2012, 12:20
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!
RO

romiko

Joined 26.09.2012

Data Extract
06 Oct 2012, 12:20


Hi,

 

I have a robot to extract data, but the problem is I cannot get the correct OPEN, CLOSE, HIGH, LOW, VOLUME.

 

Date,Time,Open,High,Low,Close,Volume

2011-10-06,010000,1.33473,1.33473,1.33473,1.33473,0

2011-10-06,020000,1.33383,1.33383,1.33383,1.33383,0

2011-10-06,030000,1.33432,1.33432,1.33432,1.33432,0

2011-10-06,040000,1.33383,1.33383,1.33383,1.33383,0

2011-10-06,050000,1.33403,1.33403,1.33403,1.33403,0

 

How can I get the correct HLOC?

 

Here is my code:

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.IO;

namespace cAlgo.Robots
{
    [Robot]
    public class DataExtract : Robot
    {
        StreamWriter _fileWriter;
    	
        protected override void OnStart()
        {
  			var symbol = Symbol.Code;
			var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);  
			var filePath = Path.Combine(desktopFolder, symbol + ".csv"); 
			
			bool isExistingFile = File.Exists(filePath);
			_fileWriter = File.AppendText(filePath);//creating file
			
			if(!isExistingFile)
				_fileWriter.WriteLine("Date,Time,Open,High,Low,Close,Volume");
			
			_fileWriter.AutoFlush = true;//file will be saved on each change
        }
        
        protected override void OnBar()
        {
            int last = MarketSeries.OpenTime.Count - 1;
    		var openTime = MarketSeries.OpenTime[last];
       		Print("Time = {0} extracted",openTime);

			//Extract Date,Time,Open,High,Low,Close,Volume
			var date = MarketSeries.OpenTime[last].ToString("yyyy-MM-dd");
			var time = MarketSeries.OpenTime[last].ToString("HHmmss");	
			double close = MarketSeries.Close[last];
			double high = MarketSeries.High[last];
			double low = MarketSeries.Low[last];
			double open = MarketSeries.Open[last];
		    var volume = 0;
			_fileWriter.WriteLine("{0},{1},{2},{3},{4},{5},{6}", date, time, open, high, low, close, volume);
        }
        
        protected override void OnStop()
        {
        	_fileWriter.Close();
        }
    }
}




@romiko
Replies

romiko
06 Oct 2012, 13:36

Fixed

I have it working now :)

 

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.IO;

namespace cAlgo.Robots
{
    [Robot]
    public class DataExtract : Robot
    {
        StreamWriter _fileWriter;
    	
        protected override void OnStart()
        {
  			var symbol = Symbol.Code;
			var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);  
			var filePath = Path.Combine(desktopFolder, symbol + ".csv"); 
			
			bool isExistingFile = File.Exists(filePath);
			_fileWriter = File.AppendText(filePath);//creating file
			
			if(!isExistingFile)
				_fileWriter.WriteLine("Date,Time,Open,High,Low,Close,Volume");
			
			_fileWriter.AutoFlush = true;//file will be saved on each change
        }
        
        protected override void OnBar()
        {
    		var openTime = MarketSeries.OpenTime[MarketSeries.OpenTime.Count-2];
       		Print("Time = {0} extracted", openTime);

			//Extract Date,Time,Open,High,Low,Close,Volume
			var date = MarketSeries.OpenTime[MarketSeries.OpenTime.Count-2].ToString("yyyy-MM-dd");
			var time = MarketSeries.OpenTime[MarketSeries.OpenTime.Count-2].ToString("HHmmss");	
			double close = MarketSeries.Close[MarketSeries.Close.Count-2];
			double high = MarketSeries.High[MarketSeries.High.Count-2];
			double low = MarketSeries.Low[MarketSeries.Low.Count-2];
			double open = MarketSeries.Open[MarketSeries.Open.Count-2];
		    var volume = 0;
			_fileWriter.WriteLine("{0},{1},{2},{3},{4},{5},{6}", date, time, open, high, low, close, volume);
        }
        
        protected override void OnStop()
        {
        	_fileWriter.Close();
        }
    }
}




@romiko

joeatbayes
22 Dec 2014, 03:07

I Think your volume level will always return 0 in the output field.        I have published something similar at /algos/cbots/show/591  but I don't want tick volume from   MarketSeries.TickVolume.Last(1).    I want actual units transacted.  Since any tick could represent a value from a fractional lot to several lots it seems that there is a huge difference in the actual value of money transacted for any tick move.    I think it makes more sense to record total units traded during the bar.      The theory is that a 200 million $ traded during a bar that dropped 10 pips is more meaningful as momentum input than  2000 traded with the same drop during the same duration.   


@joeatbayes