the following code is to enter order when price cross SMA, taking the value of quantity from Chart trader panel. But somehow neither EnterLong nor EnterShort gets executed, which means these "if CrossAbove/Below" condition never get triggered although in reality price did cross over SMA. Not sure why. Can you help me out here? (is it because the InvoleAsync was not used correctly? )
thanks !
=================================================
protected override void OnBarUpdate()
{
ChartControl.Dispatcher.InvokeAsync((Action)(() => {
Account a = ChartControl.OwnerChart.ChartTrader.Account;
quantity = ChartControl.OwnerChart.ChartTrader.Quantity;
// Print("chart trader quantity is " + quantity );
if (CurrentBar < BarsRequiredToTrade)
return;
if (CrossAbove(Close[0], smaSlow, 1))
{
EnterLong(quantity, "Long Entry");
}
else
if (CrossBelow(Close[0], smaSlow, 1))
{
EnterShort(quantity,"Short Entry");
}
}));
}
Comment