Topics
28 Jan 2014, 17:41
 3105
 1
19 Jan 2014, 17:03
 2930
 4
12 Dec 2013, 14:48
 1969
 1
10 Sep 2013, 17:45
 5115
 6
Replies

Cerunnos
27 Mar 2014, 14:04

RE:

Hm, I think it should also work differently: For example the second robot (with live account?) is running normally - but in inactive mode. Only when a condition is met (eg value is read from a extern file), then within onTick () it will be switched to active "trading-mode" ...

 protected override void OnBar()
        {
           // read from file...

            if (!isAllowed_live)
                return;               

           // isAllowed_live == true
           // live trading-mode will be activated...

           ...
           ...

        }   

Balena said:

 

Is there a way to auto start a robot using code?

If not, how long till we will be able to use code to auto start robots?

 

 


@Cerunnos

Cerunnos
19 Mar 2014, 08:39

Hi, you need two different robots (for example myRobot_Demo & myRobot_Live) that run on different cAlgo instances. The code is basically the same, but with myRobot_Demo you set a flag (eg condition_ok) to true if the demo Robot makes profit. Now, if condition_ok == true, myRobot_Live is enabled and begins to trade. Hope that helps. You can also contact me in this matter via email: cerunnos32 @ gmx.at ...


@Cerunnos

Cerunnos
15 Mar 2014, 09:10

RE: RE:

You only need two different cAlgo instances on an operating system because the API does not allow for switching between accounts. That with the CPU should not matter, but you better inform at Scyware (support@scyware.com )...

Balena said:

Cerunnos said:

Hi. I'm using a parallel system consisting of a demo and live account. If the demo robot (seperate cAlgo instance) is successfull, a boolean variable will be set to true and the live robot will be unlocked. The communication between the robots is done over robolink (very simple - just a few lines of code are necessary), but you can also write a value into text file with StreamWriter and read it from the other robot with StreamReader. Hope that helps.

I currently tab between demo and live on the same cpu...

So if you don't mind sharing...

1. if I use the RobotLink will it work if I currently tab between demo and live on the same cpu; ie "cpu 1"?

2. do I have to run demo on "cpu 1", and live on "cpu 2"?

Thanks Again!

 

 

 


@Cerunnos

Cerunnos
14 Mar 2014, 22:59

Hi. I'm using a parallel system consisting of a demo and live account. If the demo robot (seperate cAlgo instance) is successfull, a boolean variable will be set to true and the live robot will be unlocked. The communication between the robots is done over robolink (very simple - just a few lines of code are necessary), but you can also write a value into text file with StreamWriter and read it from the other robot with StreamReader. Hope that helps.


@Cerunnos

Cerunnos
06 Mar 2014, 11:28

RE:

Spotware said:

We didn't block P/Invoke approach. Everything should work.

You can find such example on MSDN.

Thanks, but in my case it doesn't work within Calculate(). With Initialize() the message box appears...  

For example:

        [DllImport("user32.dll", CharSet=CharSet.Auto)]
        static extern int MessageBox(IntPtr hWnd, String text, String caption, int options);
        
        ...
             
        public override void Calculate(int index)
        {
        ...   
        if(ema_short.Result.HasCrossedAbove(ema_long.Result,0)...)
            {            
            var alertMessage = string.Format("EMA - CROSSING {0} ", Symbol.Code);
            MessageBox(IntPtr.Zero, alertMessage, "EMA - CROSSING", 0);                         }
           }
	...
        }

 


@Cerunnos

Cerunnos
25 Jan 2014, 10:09

RE:

/forum/calgo-support/2067

kodges said:

Prompt how to get data from an external source (network or file) for use in the trading robot. For example, such data as the date and time when the news of the economic calendar.

 

 


@Cerunnos

Cerunnos
21 Jan 2014, 16:00

I think because of the weekends you have to code:

if (Server.Time.Day > Trade_Day)
                {
                _TradeCount = 0;
                }                  

instead of

if (Server.Time.Day == _TradeDay + 1)
                _TradeCount = 0;

 


@Cerunnos

Cerunnos
21 Jan 2014, 11:24

Thanks, I would add:



 if( _ExpTime == Server.Time.Hour && PendingOrders.Count == 0 && !_PosOpend)
        _Counter = 0;

For my Robot I found a very easy solution:

OnTick()
{
....
if(PendingOrders.Count > 0)
   return;
....
....
}

 


@Cerunnos

Cerunnos
19 Jan 2014, 18:54

RE:

Exactly :-) Thanks for your help

MRSV said:

Something like this?

 

private int _TradeCount;
        private int _TradeDay;

        protected override void OnStart()
        {
            _TradeCount = 0;
        }

        protected override void OnTick()
        {

            bool _TradeOk = _TradeCount <= 2;

            if (Server.Time.Day == _TradeDay + 1)
                _TradeCount = 0;

            if (......&& _TradeOk)
            {
                _TradeDay = Server.Time.Day;
                ExecuteMarketOrder(TradeType.Buy, Symbol, 1000);
                _TradeCount = _TradeCount + 1;

            }


        }

 

 


@Cerunnos

Cerunnos
14 Jan 2014, 14:44

If I want to execute a function with 2 seconds delay to set a new SL, how can I code that. Should I use Timer class, or is there a better alternative?


@Cerunnos

Cerunnos
13 Jan 2014, 11:52

Even after the release of the new API it's not possible to use the DrawText function while backtesting??


@Cerunnos

Cerunnos
07 Jan 2014, 17:26

Parallels

Can it be that cAlgo together with Parallels (Windows 7 & Mac) makes Problems? The fan of my MacBook Pro (i5 CPU + 8MB RAM) is extremely loud after the start of cAlgo. A normal work is almost impossible ...


@Cerunnos

Cerunnos
05 Jan 2014, 00:59

Are you sure? You are adding the spread with a monetary amount. And does NetProfit not already include spread?


@Cerunnos

Cerunnos
04 Jan 2014, 23:14

RE: Simple

jeex said:

Thanks Researcher. Way simpler than i was thinking.

So to calculate the price level of the Break Even point BE:

 private double calcBE(Position p)
 {
            double totalCosts = Symbol.Spread + (p.GrossProfit - p.NetProfit);
            if (p.TradeType == TradeType.Buy)
                return p.EntryPrice + totalCosts;
            else
                return p.EntryPrice - totalCosts;
}

 

Your code includes commission only one way. Or not?


@Cerunnos

Cerunnos
30 Dec 2013, 14:08

Yes thank you, that's what I supposed. But actually you do not need a callback function, or not?

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
 
namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class NewRobot : Robot
    {
         
        private bool flag_robot_close = false;
        private bool breakeven_flag = false;
        private bool distance_1 = false;
         
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
 
                  
        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
        if (!flag_robot_close) // only manual positions
        {
            Print("Position #{0} was closed by hand", args.Position.Id);
            // code
            //
        }
        else
        {
            Print("Position #{0} was closed by robot", args.Position.Id);
            // code
            //
            flag_robot_close = false;
        }
        }
         
        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;
        }
 
        protected override void OnTick()
        {
            //......................
            //.......................
             
            Position myPosition = Positions.Find("myLabel");
             
            if (myPosition != null && breakeven_flag && distance_1) // some condition...
            {
               flag_robot_close = true;
               ClosePosition(myPosition);    //no callback -> position closed by robot 
            }

        }
 
      }
}

 


@Cerunnos

Cerunnos
28 Dec 2013, 10:37

That could be a simple solution for a semi-automatic system. But I'm not sure if the following code with the new API functions is working properly. I will test it next week ...
Note: SL / TP hits were not considered (/forum/cbot-support/1655).

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class NewRobot : Robot
    {
        
        private bool flag_robot_close = false;
        private bool breakeven_flag = false;
        private bool distance_1 = false;
        
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        
        private void PositionClosedByRobot(TradeResult tradeResult)
        { 
            if(tradeResult.IsSuccessful)
            flag_robot_close = true;
        }
        
        private void OnPositionsClosed(PositionClosedEventArgs args)

        {
        if (!flag_robot_close) // only manual positions
        {
            Print("Position #{0} was closed by hand", args.Position.Id);
            // code
            //
        }
        else
        {
            Print("Position #{0} was closed by robot", args.Position.Id);
            // code
            //
            flag_robot_close = false;
        }
        }
        
        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;
        }

        protected override void OnTick()
        {
            //......................
            //.......................
            
            Position myPosition = Positions.Find("myLabel");
            
            if (myPosition != null && breakeven_flag && distance_1) // some condition...
            ClosePositionAsync(myPosition,PositionClosedByRobot);    //callback -> position closed by robot        
        }

        protected override void OnStop()
        {
            
        }
    }
}

 


@Cerunnos

Cerunnos
28 Dec 2013, 00:01

SL / TP topic:

/forum/cbot-support/1655


@Cerunnos

Cerunnos
27 Dec 2013, 23:52

RE: But no...

jeex said:

No, things are not that simple. Cerunnos' way checks if the closed position was opened by hand. I want to check if a recently closed position is closed by hand.

So i want to activate a method

  • whenever any of the many positions is closed ( OnPositionsClosed )

and the method must determine:

  • if the position belongs to that robot (p.Label...)
  • if the position was closed
    • by hand, or
    • by the robot, or
    • because of a stoploss or takeprofit

Is there a way?

Maybe it works with a callback function: ClosePositionAsync(Position position, Action callback). The callback function is called if the position was closed by the robot (closed by hand -> no callback function is called). 


@Cerunnos

Cerunnos
27 Dec 2013, 22:48

else if :-)


@Cerunnos

Cerunnos
27 Dec 2013, 22:42

RE:

jeex said:

Is there a way to test if a trade was closed by the robot, or manually?

Use labels in your robot:

 

private void OnPositionsClosed(PositionClosedEventArgs args)
 {
        if (args.Position.Label == string.Empty) // only manual positions
        {
          Print("Manual Position #{0} was closed", args.Position.Id);
        }
        else (args.Position.Label == "myRobot")
        {
          Print("Robot Position #{0} was closed", args.Position.Id);
        }
 }

 


@Cerunnos