Help needed with take profit robot
30 Jan 2013, 14:32
Hi,
My goal is quite simple. I want to code a robot that will close out (and hence take profit) from profitable positions. Then automatically re-open the same position afterwards.
The problem I am having is that the API seems to expect the use of a Symbol object. But the Symbol object is read-only.
This is what I've got so far.... (based on an API sample)
// -------------------------------------------------------------------------------
//
// This code is a cAlgo API sample.
//
// This robot is intended to be used as a sample and does not guarantee any particular outcome or
// profit of any kind. Use it at your own risk.
//
// All changes to this file will be lost on next application start.
// If you are going to modify this file please make a copy using the "Duplicate" command.
//
// This robot closes all profitable positions of the current account.
//
// -------------------------------------------------------------------------------
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot]
public class SampleTakeNetProfits : Robot
{
protected override void OnStart()
{
foreach (var position in Account.Positions)
{
if (position.NetProfit > 0 )
{
string posSymbol = position.SymbolCode;
int posVolume = position.Volume;
Trade.Close(position);
// It does not like the next line... it expects a Symbol object.
Trade.CreateBuyMarketOrder(posSymbol,posVolume); } } } } }

admin
30 Jan 2013, 16:42
Hello,
The robot will use the symbol that it is attached to, for creating new orders. Therefore, you cannot use any symbol.
The syntax should be:
View the API Reference for the syntax: /api/internals/itrade
The ability to use other symbols is in the list for future implementation.
@admin