Profile Picture

System-level logic in the MySystem class

Posted By FlipFlop 8 Years Ago
Message
Posted Sunday June 14 2009
Hi,

What's the best way to perform system-level logic : send order, manage OrderFilled... My tradsing system operates on multiple symbols, and trading decisions will be taken on a global level.

The OpenPosition() is callable from the MySystem class, so I guess we can just call OpenPosition(usjpysymbol...). But what about the OrderFilled method ? I can't override this method in the MySystem class. Same for OrderCancelled ?

Also, how can I access the MySystem class from each MySymbolScript class ?

Thanks
Posted Sunday June 14 2009
The PositionManager has OrderFilled and OrderUpdated events.  You can subscribe to them in your system class like this:
public override void Startup()
{
// Perform initialization or set system wide options here
SystemData.Output.Clear();

PositionManager.OrderFilled += OrderFilled;
PositionManager.OrderUpdated += OrderUpdated;
}
public void OrderFilled(object sender, OrderFilledEventArgs e)
{

}
public void OrderUpdated(object sender, OrderUpdatedEventArgs e){
if (e.Order.OrderState == BrokerOrderState.Cancelled ||
e.Order.OrderState == BrokerOrderState.Rejected)
{
// Order cancelled or rejected (which is what causes SymbolScript.OrderCancelled to be called)
}
}

There is a TradingSystem property in the base SymbolScript class which will be set to the instance of your system class.  From the system class, you can access the symbol scripts with the SymbolScripts property, indexing it with either a symbol object or the name of a symbol.

double smaVal = SymbolScripts[symbol].SMA30.Current;

To open a position in your system class, you can call PositionManager.OpenPosition, passing it a PositionSettings object with the symbol set to the symbol you want to use, or you can use the symbol script methods like this: SymbolScripts[symbol].OpenPosition(...)

Thanks,
Daniel

Posted Tuesday June 23 2009
Hi,

I did what you suggest, it works pretty well, I can open and close symbol positions inside the MySystem class.

I still have one more question : I receive once in a while an order "Cancelled" event, the information field is set to "System cancelled". What does this error mean ? How can I know why this order has not been executed (I'm just doing a simulation, I don't send any order to a broker or paper broker).

Here is my OrderUpdated function, it is gonna print the following message when an order is cancelled

"order Cancelled, msg:System cancelled"

      public void OrderUpdated(object sender, OrderUpdatedEventArgs e)

      {

            Console.WriteLine("--OrderUpdated: " + e.Position.ID);

            if (e.Order.OrderState != BrokerOrderState.Filled)

            {

                  Console.WriteLine("order " + e.Order.OrderState + ", msg:" + e.Information);

                 

            }

      }

 

Posted Tuesday June 23 2009
If you have any dependent orders, i.e. profit target, stop loss associated with the position, if the position is closed, the associated orders are cancelled. Ex: Open Position, profit target and stop loss orders are submitted. Profit target is hit, stop loss is automatically cancelled by the system.
Posted Tuesday June 23 2009
Hi,

It is not a dependent order, but just a Open Position order at market.
In which cases can we receive order cancelled for reason = "System cancelled"

billb (6/23/2009)
If you have any dependent orders, i.e. profit target, stop loss associated with the position, if the position is closed, the associated orders are cancelled. Ex: Open Position, profit target and stop loss orders are submitted. Profit target is hit, stop loss is automatically cancelled by the system.

Posted Tuesday June 23 2009
See this thread, starting with this post.

FlipFlop (6/23/2009)
Hi,

It is not a dependent order, but just a Open Position order at market.
In which cases can we receive order cancelled for reason = "System cancelled"

billb (6/23/2009)
If you have any dependent orders, i.e. profit target, stop loss associated with the position, if the position is closed, the associated orders are cancelled. Ex: Open Position, profit target and stop loss orders are submitted. Profit target is hit, stop loss is automatically cancelled by the system.



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems