correct syntax for environment paths
correct syntax for environment paths
27 Aug 2021, 14:12
Hi,
I've only just started teaching myself how to write cBots - I'm trying out the sample code from
https://ctrader.com/forum/calgo-reference-samples/54
I'm getting the error "The name desktopFolder does not exist in the current context"
Here is my code:
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.IO;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
public class recordData : Robot
{
StreamWriter _fileWriter;
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
protected override void OnStart()
{
// Put your initialization logic here
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
var filePath = Path.Combine(desktopFolder, "cTraderOutput.txt");
//create file
_fileWriter = File.AppendText(filePath);
//file will be saved on each change
_fileWriter.AutoFlush = true;
}
protected override void OnTick()
{
// this happens every time a tick happens
fileWriter.WriteLine("A tick has happened at: " + Server.Time);
Print("written to file.");
}
protected override void OnBar()
{
//this happens every time a bar closes
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
I'm using cTrader 4.1 on windows 10. I'm guessing it's the environment filepath var that's the problem, I've rummaged around to the best of my ability but I can't find out what I should put in place of "desktopFolder" - please can anyone point me in the right direction as to what the correct syntax should be?
Many thanks in advance
John
ctid4201136
27 Aug 2021, 14:27
RE:
Sorry!
I've just noticed that I've left out a line of code from the sample setting the desktopFolder var!
Please ignore me! Problem solved!
*facepalm*
@ctid4201136