Usage of MarketData and Indicators outside the Robot
Usage of MarketData and Indicators outside the Robot
03 Oct 2020, 11:47
Hi,
I would like to create a class (preferably in a separate cs file) to get the current values of several indicators for different timeframes to be called then in the logic of the robot, but it seems I can use MarketData and Indicators only in the OnBar() or OnTick() or OnStart() methods (which have to be in the robot class).
Any suggestion?
Thanks in advance,
Massimo
Replies
danieljclsilva
13 Oct 2020, 05:29
Hi,
I have the same issue. I can pass the objects to the class, but I still don´t know how to execute/place orders inside this new class.
// MycBot.cs
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class MycBot : Robot
{
[...]
protected override void OnBar()
{
foreach (string GetSymbol in SymbolList)
{
var symbol = Symbols.GetSymbol(GetSymbol);
var symbolBars = MarketData.GetBars(TimeFrame, symbol.Name);
var _ATR = Indicators.AverageTrueRange(symbolBars, 14, MovingAverageType.Exponential);
var _ATRSMA = Indicators.SimpleMovingAverage(_ATR.Result, 100);
InsideBarBreakout InsideBarBreakout = new InsideBarBreakout(Server, symbol, symbolBars, _ATR, _ATRSMA, Label, PrmPercMotherBar);
InsideBarBreakout.EntrySignal();
}
}
[...]
}
}
// IsideBarBreakout.cs
namespace cAlgo.Strategies
{
class InsideBarBreakout
{
public IServer server;
public Bars symbolBars;
public Symbol symbol;
public string Label;
public bool InsideBar;
public bool IDNR4Pattern;
public bool LATRAboveSMA;
public InsideBarBreakout(IServer Getserver, Symbol GetSymbol, Bars GetBars, AverageTrueRange ATR, SimpleMovingAverage ATRSMA, string GetLabel, double PrmPercMotherBar)
{
server = Getserver;
symbol = GetSymbol;
symbolBars = GetBars;
Label = GetLabel;
var PercMotherBar = PrmPercMotherBar;
var _ATR = ATR;
var _ATRSMA = ATRSMA;
[...]
}
public void EntrySignal()
{
if (InsideBar && IDNR4Pattern && LATRAboveSMA)
{
[...]
// CS0103 C# The name does not exist in the current context
PlaceStopOrder(TradeType.Buy, symbol.Name, 1000, BuyPrice, Label, BuySL, null, server.Time.AddHours(22).AddMinutes(55));
PlaceStopOrder(TradeType.Sell, symbol.Name, 1000, SellPrice, Label, SellSL, null, server.Time.AddHours(22).AddMinutes(55));
}
}
}
}
Any suggestion?
@danieljclsilva
PanagiotisCharalampous
13 Oct 2020, 08:12
Hi danieljclsilva,
These methods are methods of the robot. You will need to pass the robot as a parameter and call it's methods inside the new class.
Best Regards,
Panagiotis
@PanagiotisCharalampous
... Deleted by UFO ...
PanagiotisCharalampous
05 Oct 2020, 08:05
Hi Massimo,
There are no restrictions on how you can use these objects. You can pass these objects to other classes as parameters.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous