Topics
Replies
courquinpasisa
29 Aug 2018, 16:07
I have several robots that I test, and I want to create a new class whose role is to manage the orders executed by these robots and possibly to place a new order (hedging).
This new class can be used easily in my different robots.
Best regards,
@courquinpasisa
courquinpasisa
29 Aug 2018, 15:36
Hi Panagiotis,
The explanations you gave me allowed me to move forward in my project. But I have a problem again, I wish a method of my class sends an order on the market. Here is an example :
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, AccessRights = AccessRights.None)]
public class NewTest : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
public string TextReturn;
public Symbol eurUsd;
protected override void OnStart()
{
eurUsd = MarketData.GetSymbol("EURUSD");
MaClass3 GH = new MaClass3(2, 5, Symbol.Ask);
GH.ordre(eurUsd);
}
protected override void OnTick()
{
// Put your core logic here
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
public class MaClass3 : Robot
{
private int a { get; set; }
private int b { get; set; }
private int c { get; set; }
private Symbol EurUsd;
public MaClass3(int A, int B, double C)
{
a = A;
b = B;
c = C;
}
public void ordre(Symbol EU)
{
EurUsd = EU;
ExecuteMarketOrder(TradeType.Buy, EurUsd, 1000);
}
}
}
I'm trying to pass the "MarketData.GetSymbol" parameter but I have the same error message: Crashed in OnStart with NullReferenceException: The object reference is not set to an instance of an object.
Is it possible to use ExecuteMarketOrder in a method of my new class.
Thank you in advance.
@courquinpasisa
courquinpasisa
24 Aug 2018, 12:27
Hi Panagiotis,
Thank you for this explanation, it is now much clearer to me.
Best regards.
@courquinpasisa
courquinpasisa
24 Aug 2018, 12:14
A big thank you for this quick response.
I tried, and it works.
Could you explain to me why I can not use the functions of cAlgo.API in my new class.
Here is another example that returns the same error message.
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, AccessRights = AccessRights.None)]
public class NewTest : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
protected override void OnStart()
{
MaClass GH = new MaClass(2, 5, Symbol.Ask);
Print(GH.prix);
Print(GH.test());
}
protected override void OnTick()
{
// Put your core logic here
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
public class MaClass : Robot
{
public int a { get; set; }
public int b { get; set; }
public int c { get; set; }
public int resultat { get; set; }
public double prix { get; set; }
public bool val;
public MaClass(int A, int B, double C)
{
a = A;
b = B;
c = 12;
resultat = 0;
prix = C;
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Sell)
val = true;
else
val = false;
}
}
public int test()
{
resultat = a + b + c;
return resultat;
}
}
}
Anything in parameter is a solution, but is there another way of doing things.
Maybe by declaring my new class in another way, in order to use the functions of cAlgo.API?
@courquinpasisa
courquinpasisa
29 Aug 2018, 16:50
I did not think about this possibility.
I think it's a very good idea. I will rethink my new class as a basic class.
Thank you for this solution and for your exelent work on the forum.
Best regards.
@courquinpasisa