OL
Crashed in OnTick with NullReferenceException
20 Apr 2014, 22:03
Hi
Can someone tell me what's wrong whit this code?
protected override void OnStart()
{
ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "Test");
}
protected override void OnTick()
{
var position = Positions.Find("Test");
ClosePosition(position);
}
Thanks
Replies
Old Account
22 Apr 2014, 23:08
RE:
Researcher said:
If there is no such position on tick the Find() method returns null. Try this code:
protected override void OnTick() { var position = Positions.Find("Test"); if (position != null) ClosePosition(position); }
Thank you !!!
@Old Account

Researcher
22 Apr 2014, 00:18
If there is no such position on tick the Find() method returns null. Try this code:
protected override void OnTick() { var position = Positions.Find("Test"); if (position != null) ClosePosition(position); }@Researcher