Saving to File

Created at 30 Aug 2012, 18:42
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!
ST

stefst

Joined 21.08.2012

Saving to File
30 Aug 2012, 18:42


Hey there,

 

Is it possible to save output, from a robotto a file? 

 

Cheers.


@stefst
Replies

admin
31 Aug 2012, 10:40

Hi

You can use the following example if you want to output data to a text file:

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

namespace cAlgo.Robots
{
    [Robot]
    public class WriteToFileExample : Robot
    {
        StreamWriter _fileWriter;
    	double avspread = 0;
    	double spreadnow = 0;
    	double sum = 0;
    	int ticker = 0;
		int once = 0;
    	int counter =0;
    	
        protected override void OnStart()
        {
			var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//getting location of user's Desktop folder  
			var filePath = Path.Combine(desktopFolder, "ServerTimeExample.txt"); 
			
			_fileWriter = File.AppendText(filePath);//creating file
			
			_fileWriter.AutoFlush = true;//file will be saved on each change
        }
        
        protected override void OnTick()
        {
			_fileWriter.WriteLine("Server Time: " + Server.Time);
        }
        
        protected override void OnStop()
        {
        	_fileWriter.Close();
        }
    }
}




@admin

Balena
16 Dec 2013, 23:08

RE: Hi

How can I reverse this and read from a text file in cAlgo...

ie...

1. I use the below to pull price data into "txt file A"

2. I pull data from "txt file A" to use in another 3 party application

3. I create "txt file B" from the 3rd party application

4. I pull variables from "txt file B" back into cAlgo to use as logic

 

I have step #1 below...

I need help with step #4

 

thanks!

 

admin said:

You can use the following example if you want to output data to a text file:

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

namespace cAlgo.Robots
{
    [Robot]
    public class WriteToFileExample : Robot
    {
        StreamWriter _fileWriter;
    	double avspread = 0;
    	double spreadnow = 0;
    	double sum = 0;
    	int ticker = 0;
		int once = 0;
    	int counter =0;
    	
        protected override void OnStart()
        {
			var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//getting location of user's Desktop folder  
			var filePath = Path.Combine(desktopFolder, "ServerTimeExample.txt"); 
			
			_fileWriter = File.AppendText(filePath);//creating file
			
			_fileWriter.AutoFlush = true;//file will be saved on each change
        }
        
        protected override void OnTick()
        {
			_fileWriter.WriteLine("Server Time: " + Server.Time);
        }
        
        protected override void OnStop()
        {
        	_fileWriter.Close();
        }
    }
}


 

 


@Balena