Profile Picture

Backtest runs out of money: Please warn me!

Posted By DrKoch 8 Years Ago
Message
Posted Friday July 31 2009
If my script tries to open more positions than starting capital allows the OpenPosition() call is ignored *silently* w00t

Sometimes this is fine.
But sometimes my strategy is designed to open all positions and everything else is a bug! Cool

I'd like to see some kind of warning message (optional, switchable) if RE's paper broker rejects my orders due to low capital.



www.finantic.de

Our Trading System at C2: Topaz
Posted Friday July 31 2009
Request noted on UserVoice

Posted Monday August 03 2009
When you don't have enough cash to fill the order, the paper broker sets the order state to rejected. If you override the OrderCancelled method of the symbol script class, it will be called when an order is cancelled or rejected. You can check the order state to see which happened. An order being cancelled is usually normal (you cancelled it explicitly, or the order timed out, or the PT/SL order was cancelled when the position was closed). The following code will output a warning if the order is rejected:

public override void OrderCancelled(Position position, Order order, string information)
{
   // This method is called when an order is cancelled or rejected
   if (order.OrderState == BrokerOrderState.Rejected)
   {
      OutputWarning("Order rejected: " + information);
   }
}

The information string gives the reason the order was rejected. In this case it says "Not enough cash to fill order."

The call to OpenPosition isn't ignored. The order is submitted, but won't be processed immediately (if you are just doing end of bar trading, then you submit an order at the end of a bar, and it gets processed during the next bar). So the call succeeds. There are errors that can prevent OpenPosition from submitting an order. In this case the Error property of the returned position will be non-null. Generally you should be checking for this when you call OpenPosition, something like this:

Position pos = OpenPosition(PositionType.Long, OrderType.Limit, BBL.Current);
if (pos.Error != null)
{
   OutputWarning(pos.Error);
}

Thanks,
Daniel
Posted Monday August 03 2009
Great!
Thanks a lot.


www.finantic.de

Our Trading System at C2: Topaz


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems