Topics
Forum Topics not found
Replies
cerana
21 Sep 2015, 15:49
using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class profit : Robot { [Parameter(DefaultValue = 100.0)] public double Parameter { get; set; } protected override void OnTick() { int? a = null; int? b = null; foreach (var position in Positions) a++; foreach (var position in Positions) if (position.Pips > Parameter) b++; if (a == b) foreach (var position in Positions) { ClosePosition(position); } } } }
@cerana
cerana
17 Sep 2015, 06:36
Why is this not working? (Visual Studio: OK)
using System.Linq; using System.Xml.Serialization; using System.Collections.Generic; using System.Data.OleDb; using System.Data; using System.Data.Common; using System.Data.Odbc; namespace cAlgo.Robots { [Robot(AccessRights = AccessRights.FullAccess)] public class Algoritmus_ceranae : Robot { protected override void OnStart() { string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= E:\\adatbaz.mdb"; double total = 0; int count = 0; string mySelectQuery = "Select*FROM árfolyamok"; OleDbConnection myConnection = new OleDbConnection(myConnectionString); OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection); myConnection.Open(); OleDbDataReader myDataReader = null; myDataReader = myCommand.ExecuteReader(); while (myDataReader.Read()) { count += myDataReader.GetInt32(0); }
Manage references: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Data.dll
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Data.dll
@cerana
cerana
02 Jun 2013, 15:15
This is good.
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.IO; //********** Export to file
namespace cAlgo.Robots
{
[Robot]
public class ExportToMSExcel : Robot
{
//-----------------------------------------------------------------
// Add Parameters here (if any)
//-----------------------------------------------------------------
// Add variables here (if any)
private Position _cposition;
private Position _position; //********** Export to file
StreamWriter _fileWriter; //********** Export to file
//-----------------------------------------------------------------
protected override void OnStart()
{
// Add your logic here
//********** Export to file ********************
var name = GetType().ToString(); // returns cAlgo.Robot.ClassName
var Classname = name.Substring(name.LastIndexOf('.') + 1); // returns ClassName
var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
var filePath = Path.Combine(desktopFolder, Symbol.Code+Classname+".xls");
_fileWriter = File.AppendText(filePath);
_fileWriter.AutoFlush = true;
_fileWriter.WriteLine("Symbol"+" "+"Nr.OpenPos"+" "+"ID"+" "+"ShortDate"+" "+"Date"+" "+"DayName"+" "+"Entry/ExitTime"+" "+
"Volume"+" "+"Type"+" "+"Entry/ExitPrice"+" "+"TakeProfit"+" "+"StopLoss"+" "+"Equity"+" "+"Balance"+" "+"Profit");
//****************************************
}
//-----------------------------------------------------------------
protected override void OnBar()
{
// Add your logic here (OnBar / OnTick)
}
//-----------------------------------------------------------------
protected override void OnPositionOpened(Position openedPosition)
{
_position = openedPosition;
// Add your logic here (if any)
ExportOnOpened(); //********** Export to file
}
//-----------------------------------------------------------------
protected override void OnPositionClosed(Position closedPosition) //********** Export to file
{
// Add your logic here (if any)
_cposition = closedPosition;
string _Symbol = Symbol.Code.ToString();
string _ID = _cposition.Id.ToString();
string _ShortDate = Convert.ToString(Server.Time.Year+"-"+Server.Time.Month);
string _Date = Convert.ToString(Server.Time.Year+"-"+Server.Time.Month+"-"+Server.Time.Day);
string _DayName = Server.Time.DayOfWeek.ToString();
string _ExitTime = Convert.ToString(Server.Time);
string _Equity = Account.Equity.ToString();
string _Balance = Account.Balance.ToString();
string _Positions = Account.Positions.Count.ToString();
string _Profit = closedPosition.GrossProfit.ToString();
string _ClosePrice = Symbol.Ask.ToString();
_fileWriter.WriteLine(_Symbol+" "+_Positions+" "+_ID+" "+_ShortDate+" "+_Date+" "+_DayName+" "+_ExitTime+" "+_ClosePrice+" "+_Equity+" "+_Balance+" "+_Profit);
}
//-----------------------------------------------------------------
protected override void OnStop() //********** Export to file
{
// Add your logic here (if any)
_fileWriter.Close();
}
//-----------------------------------------------------------------
private void ExportOnOpened() //********** Export to file
{
string _Symbol = Symbol.Code.ToString();
string _ID = _position.Id.ToString();
string _ShortDate = Convert.ToString(Server.Time.Year+"-"+Server.Time.Month);
string _Date = Convert.ToString(Server.Time.Year+"-"+Server.Time.Month+"-"+Server.Time.Day);
string _DayName = Server.Time.DayOfWeek.ToString();
string _EntryTime = _position.EntryTime.ToString();
string _Volume = _position.Volume.ToString();
string _Type = _position.TradeType.ToString();
string _EntryPrice = _position.EntryPrice.ToString();
string _TakeProfit = _position.TakeProfit.ToString();
string _StopLoss = _position.StopLoss.ToString();
string _Equity = Account.Equity.ToString();
string _Balance = Account.Balance.ToString();
string _Positions = Account.Positions.Count.ToString();
_fileWriter.WriteLine(_Symbol+" "+_Positions+" "+_ID+" "+_ShortDate+" "+_Date+" "+_DayName+" "+_EntryTime+" "+_Volume+" "+_Type+" "+_EntryPrice+" "+_TakeProfit+" "+_StopLoss+" "+_Equity+" "+_Balance);
}
}
}
@cerana
cerana
02 Jun 2013, 14:31
RE:
Hi PCWalker!
I wrote a code that export Backtest data to Excel.
You can find it here: /algos/robots/show/201
I know it is not an add-in, but maybe helps you.
Bad!
Good?
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.IO; //********** Export to file
namespace cAlgo.Robots
{
[Robot]
public class ExportToMSExcel : Robot
{
//-----------------------------------------------------------------
// Add Parameters here (if any)
//-----------------------------------------------------------------
// Add variables here (if any)
private Position _position;
private Position _cposition; //********** Export to file
StreamWriter _fileWriter; //********** Export to file
//-----------------------------------------------------------------
protected override void OnStart()
{
// Add your logic here
//********** Export to file ********************
var name = GetType().ToString(); // returns cAlgo.Robot.ClassName
var Classname = name.Substring(name.LastIndexOf('.') + 1); // returns ClassName
var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
var filePath = Path.Combine(desktopFolder, Symbol.Code+Classname+".xls");
_fileWriter = File.AppendText(filePath);
_fileWriter.AutoFlush = true;
_fileWriter.WriteLine("Symbol"+" "+"Nr.OpenPos"+" "+"ID"+" "+"ShortDate"+" "+"Date"+" "+"DayName"+" "+"Entry/ExitTime"+" "+
"Volume"+" "+"Type"+" "+"Entry/ExitPrice"+" "+"TakeProfit"+" "+"StopLoss"+" "+"Equity"+" "+"Balance"+" "+"Profit");
//****************************************
}
//-----------------------------------------------------------------
protected override void OnBar()
{
// Add your logic here (OnBar / OnTick)
}
//-----------------------------------------------------------------
protected override void OnPositionOpened(Position openedPosition)
{
_position = openedPosition;
// Add your logic here (if any)
ExportOnOpened(); //********** Export to file
}
//-----------------------------------------------------------------
protected override void OnPositionClosed(Position closedPosition) //********** Export to file
{
// Add your logic here (if any)
_cposition = closedPosition;
string _Symbol = Symbol.Code.ToString();
string _ID = _cposition.Id.ToString();
string _ShortDate = Convert.ToString(Server.Time.Year+"-"+Server.Time.Month);
string _Date = Convert.ToString(Server.Time.Year+"-"+Server.Time.Month+"-"+Server.Time.Day);
string _DayName = Server.Time.DayOfWeek.ToString();
string _ExitTime = Convert.ToString(Server.Time);
string _Equity = Account.Equity.ToString();
string _Balance = Account.Balance.ToString();
string _Positions = Account.Positions.Count.ToString();
string _Profit = closedPosition.GrossProfit.ToString();
string _ClosePrice = Symbol.Ask.ToString();
_fileWriter.WriteLine(_Symbol+" "+_Positions+" "+_ID+" "+_ShortDate+" "+_Date+" "+_DayName+" "+_ExitTime+" "+_ClosePrice+" "+_Equity+" "+_Balance+" "+_Profit);
}
//-----------------------------------------------------------------
protected override void OnStop() //********** Export to file
{
// Add your logic here (if any)
_fileWriter.Close();
}
//-----------------------------------------------------------------
private void ExportOnOpened() //********** Export to file
{
string _Symbol = Symbol.Code.ToString();
string _ID = _position.Id.ToString();
string _ShortDate = Convert.ToString(Server.Time.Year+"-"+Server.Time.Month);
string _Date = Convert.ToString(Server.Time.Year+"-"+Server.Time.Month+"-"+Server.Time.Day);
string _DayName = Server.Time.DayOfWeek.ToString();
string _EntryTime = _position.EntryTime.ToString();
string _Volume = _position.Volume.ToString();
string _Type = _position.TradeType.ToString();
string _EntryPrice = _position.EntryPrice.ToString();
string _Equity = Account.Equity.ToString();
string _Balance = Account.Balance.ToString();
string _Positions = Account.Positions.Count.ToString();
_fileWriter.WriteLine(_Symbol+" "+_Positions+" "+_ID+" "+_ShortDate+" "+_Date+" "+_DayName+" "+_EntryTime+" "+_Volume+" "+_Type+" "+_EntryPrice+" "+_Equity+" "+_Balance);
}
}
}
@cerana
cerana
21 Sep 2015, 17:08
Instead null!! Symbol.UnrealizedNetProfit : if all positions a form of currency.
@cerana