Profile Picture

Adding to Position Not Working

Posted By paulged Last Year
Message
Posted Friday March 18 2016
Could someone explain me what is wrong in my code:

  if (OpenPositions.Count > 0)
   {
      foreach (Position pos in OpenPositions)
      {

       PositionManager posManager = new PositionManager(SystemData);
       posManager.AddToPosition(pos.ID ,1, OrderType.MarketOnOpen, 0, "");
       
      }
   }


I get this error:

A position with the specified ID (1) was not found.
 at RightEdge.Common.PositionManager.AddToPosition(String PosID, Int64 shares, OrderType orderType, Double price, String description)
 at MySymbolScript.Trade(List`1 orderedSymbolScripts) in c:\Users\Paul\Desktop\SymbolRanking\SymbolRanking.cs:line 204
 at MySystem.NewBar() in c:\Users\Paul\Desktop\SymbolRanking\SymbolRanking.cs:line 37
 at RightEdge.Common.Internal.SystemRunner.CallSystemNewBar(FrequencyNewBarEventArgs args)
 at RightEdge.Common.Internal.SystemRunner.ProcessBarEvents(IEnumerable`1 eventList)
 at RightEdge.Common.FrequencyManager.SendPendingBars()
 at RightEdge.Common.FrequencyManager.UpdateTime(DateTime dateTime)
 at RightEdge.Common.Internal.SystemRunner._tickGenerator_NewBar(Object sender, NewBarEventArgs e)
 at RightEdge.Common.TickGenerator.ProcessBar(NewBarEventArgs args)
 at RightEdge.Common.Internal.SystemRunner.ProcessBar(NewBarEventArgs newBars)
 at RightEdge.Shared.SystemWrapper.RunSystem(SystemData systemData, SharedSystemRunData runData, ServiceFactory brokerFactory)
 at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginSettings dataStoreSettings)
 at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginSettings dataStoreSettings)
 at RightEdge.Shared.TradingModuleWrapper.Run(String filename)
 at RightEdge.Shared.TradingModuleWrapper.RunSystem(SharedSystemRunData systemRunData)
 at RightEdge.SystemProgress.InitAndRunSystem()



Edited: Friday March 18 2016 by paulged
Posted Sunday March 20 2016
Don't create a new PositionManager.  There is already a PositionManager property on the symbol script, so simply do the following inside your loop:

PositionManager.AddToPosition(pos.ID, 1, OrderType.MarketOnOpen, 0, "");


Thanks,
Daniel
Posted Sunday March 20 2016
All sorted, thanks a lot mate!


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems