choose specific Symbol or Symbols
choose specific Symbol or Symbols
12 Oct 2018, 22:08
Hi Panagiotis,
I use below loop in version 3.0 cTrader:
1
foreach (var position in Positions)
to loop trough positions and execute on them.
is there a api based way to filter the positions by a certain Symbol or Symbols ?
so the cAlgo would just edit/close/open posiitons on the selected Symbol and leave anything else alone ?
Replies
RezaNoorimotlagh
15 Oct 2018, 15:04
RE: choose specific Symbol or Symbols
Dear Panagiotis,
I currently use version 3.0 cTrader. After running this code, The cTrader genarates the following error.
Code:
foreach (var position in Positions.@where(x => x.SymbolCode == "EURUSD"))
Error:
Error CS1061: 'cAlgo.API.Positions' does not contain a definition for 'where' and no extension method 'where' accepting a first argument of type 'cAlgo.API.Positions' could be found (are you missing a using directive or an assembly reference?)
Thanks,
Reza
@RezaNoorimotlagh
PanagiotisCharalampous
15 Oct 2018, 15:10
Hi Reza,
There is an @ in the code. Is this the reason? If not then make sure you reference LINQ. To do so just add
using System.Linq;
is the using section.
Best Regards,
Panagiotis
@PanagiotisCharalampous
RezaNoorimotlagh
15 Oct 2018, 20:21
Hi Panagiotis,
The @ be add to the code after saving by cTrader (I don't know why?!!?). You can see in below codes that are befor and after saving: After the build the code, cTrader genarates this error; (Error CS1061: 'cAlgo.API.Positions' does not contain a definition for 'where' and no extension method 'where' accepting a first argument of type 'cAlgo.API.Positions' could be found (are you missing a using directive or an assembly reference?)
Befor Saveing:
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 CVSecondEdition : Robot { protected override void OnTick() { foreach (var position in Positions.where(x => x.SymbolCode == "EURUSD")) { Print("Symbol: {0}", position.SymbolCode); Print("The current symbol has pip size of: {0}", MarketData.GetSymbol(position.SymbolCode).PipSize); Print("SL: {0}", position.StopLoss); } } } }
After Saving:
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 CVSecondEdition : Robot { protected override void OnTick() { foreach (var position in Positions.@where(x => x.SymbolCode == "EURUSD")) { Print("Symbol: {0}", position.SymbolCode); Print("The current symbol has pip size of: {0}", MarketData.GetSymbol(position.SymbolCode).PipSize); Print("SL: {0}", position.StopLoss); } } } }
Regards,
Reza
@RezaNoorimotlagh
PanagiotisCharalampous
16 Oct 2018, 09:49
Ηi noorimotlagh.reza,
It should be Where and not where. c# is a case sensitive language.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
15 Oct 2018, 10:10
Hi noorimotlagh.reza,
Here it is
Best Regards,
Panagiotis
@PanagiotisCharalampous