Topics

Forum Topics not found

Replies

cerana
21 Sep 2015, 17:08

 

 

 

 

 

 

 

 

 

 

 

 

Instead null!! Symbol.UnrealizedNetProfit : if all positions a form of currency.

 

 

 

 

 

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using cAlgo.API.Requests;
using System.Threading;
using System.Timers;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class profit : Robot
    {
        [Parameter(DefaultValue = 100.0)]
        public double Parameter { get; set; }



        protected override void OnTick()
        {
            int a = 0;
            int b = 0;

            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
21 Sep 2015, 16:39

Or :instead position.Pips: . Symbol.UnrealizedNetProfit >Parameter                                                                                                                                    


@cerana

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
20 Sep 2015, 16:37

Paul!       

Thank you very much!                                                                                                                                                                                          


@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:
rkokerti said:

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
24 Nov 2012, 20:59

Thank you!


@cerana

cerana
30 Oct 2012, 11:24

RE:
admin said:

namespace cAlgo.Robots { [Robot] public class SampleMultiplePositions : Robot { private readonly List _listPosition = new List();

 

 

Error: Using the generic type 'System.Collections.Generic. List<T>' requires 1 type arguments

@cerana

cerana
22 Oct 2012, 14:44

 

Hy!

 

I would like to ask something:

I would like to create an indicator for a Scalper robot, which from the open positions separatly shows the number of the sell and buy positions.

In this case how can I use the count method or property?


@cerana