I am currently building a NinjaScript Strategy which I am testing in BarReplay Mode.
In the strategy I have these lines under the OnBarUpdate() method (the _crosslong, _macdthreshold.. etc. conditions are being initialized beforehand):
var _enterlong = _crosslong && _macdthresholdlong && _stochlong && timefilter;
if (_enterlong)
{
Print("All long entry conditions met! Attempting to enter long...");
}
var _entershort = _crossshort && _macdthresholdshort && _stochshort && timefilter;
if (_entershort)
{
Print("All short entry conditions met! Attempting to enter short...");
}
followed by these lines which I have copy pasted from the SampleAtmStrategy:
// LONG ENTRY
if (_enterlong && orderId.Length == 0 && atmStrategyId.Length == 0)
{
isAtmStrategyCreated = false; // reset atm strategy created check to false
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.Market, Low[0], 0, TimeInForce.Day, orderId, _ATMstrategy, atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
isAtmStrategyCreated = true;
lastTradeBar = CurrentBar;
});
}
//SHORT ENTRY
....
Now, when I see all my conditions begin met (I have the indicators plotted on the Chart via State.DataLoaded), the Output window prints "All long entry conditions met! Attempting to enter long..."
But still, it doesn't open a position.
However, when I replace the _entershort in the entry conditions with only _crosslong for example, it will execute trades.
I've tried everything to debug, using Print methods and even enabled TraceOrders, but somehow it doesn't submit orders, when using the _enterlong variable.
Any idea what might be causing this?
Cheers,
totalnewb (fitting, I know)
Comment