Probleme MarketData GetSymbol
Probleme MarketData GetSymbol
02 May 2017, 12:40
I build a cbot with several symbol
for example
The robot opens a buy position and automatically opens a reverse stop order (shell)
The robot opens the requested position ... eg gbpusd.
And it opens the stop order gbpusd but provided that the instance is GBPUSD ..
If the instance is EURUSD the buy gbpusd position opens but not the stop order shell
Someone can illuminate my lantern ...
Piece of code
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class SamplecBot : Robot { [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)] public double Quantity { get; set; } [Parameter("Distance Pips LimitOrder", DefaultValue = 40)] public int PipsAway { get; set; } private Symbol _symbol1; private void InitializeSeries1(string symbolCode) { _symbol1 = MarketData.GetSymbol("GBPUSD"); } protected override void OnStart() { InitializeSeries1("GBPUSD"); Positions.Opened += OnPositionOpened; } protected override void OnTick() { var position = Positions.Find("Sample", Symbol); var volumeInUnits = Symbol.QuantityToVolume(Quantity); var cBotPositions = Positions.FindAll("Sample"); if (cBotPositions.Length >= 1) return; ExecuteMarketOrder(TradeType.Buy, _symbol1, volumeInUnits, "Sample", 80, 40); } private void OnPositionOpened(PositionOpenedEventArgs positionClosedEventArgs) { var openedPosition = positionClosedEventArgs.Position; if (openedPosition.Label != "Sample" || openedPosition.SymbolCode != Symbol.Code) return; CreatePendingOrder(openedPosition); } private void CreatePendingOrder(Position position) { DateTime exp = MarketSeries.OpenTime.LastValue.AddHours(12); var volumeInUnits = Symbol.QuantityToVolume(Quantity); { var sellOrderTargetPrice = Symbol.Bid - PipsAway * Symbol.PipSize; PlaceStopOrder(TradeType.Sell, _symbol1, volumeInUnits * 2, sellOrderTargetPrice, "Sample2", 20, 70, exp); } } } }
Replies
tradermatrix
02 May 2017, 13:32
RE:
Super lucian
A small error and serious consequences but thanks to your help I will be able to modify my cbot.
thanks again
lucian said:
in line 55 , try to use:
if (openedPosition.Label != "Sample" || openedPosition.SymbolCode != _symbol1.Code)instead of:
if (openedPosition.Label != "Sample" || openedPosition.SymbolCode != Symbol.Code)
@tradermatrix
... Deleted by UFO ...