global variable
global variable
28 Apr 2020, 10:14
how do I put symbol as global variable?
var symbol must be taken from OnTick ()
protected override void OnStart()
{
Inizio:
RefreshData();
string EURUSD = Symbols[random.Next(Symbols.Count)];
Symbols.GetSymbol("EURUSD");
Print(EURUSD);
var symbol = MarketData.GetSymbol(EURUSD);
....
...
...
}
protected override void OnTick()
{
var position = Positions.Find("MyLabel");
if (position.TradeType == TradeType.Buy)
{
var newSLprice = Symbol.Ask - (Symbol.PipSize * 1);
if (newSLprice > position.StopLoss)
{
ModifyPosition(position, newSLprice, null);
}
}
else
{
var newSLprice = Symbol.Bid + (Symbol.PipSize * 1);
if (newSLprice < position.StopLoss)
{
ModifyPosition(position, newSLprice, null);
}
}
}
}
}
Thanks
Replies
luca.tocchi
28 Apr 2020, 11:14
RE:
PanagiotisCharalampous said:
Hi Luca,
See an example below
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 NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } Symbol _symbol; protected override void OnStart() { _symbol = Symbols.GetSymbol("EURUSD"); } protected override void OnTick() { // Put your core logic here } protected override void OnStop() { // Put your deinitialization logic here } } }
Best Regards,
Panagiotis
thanks
@luca.tocchi
PanagiotisCharalampous
28 Apr 2020, 11:10
Hi Luca,
See an example below
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous