Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged Approach does not interact with SMA

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Unmanaged Approach does not interact with SMA

    Hello,

    I am doing an unmanaged approach. My goal is to place a Long or Short order if SMA Fast and SMA Slow cross over each other.

    I used the following code but the orders are not placed:

    protected override void OnBarUpdate()
    {
    if (longEntry == null && shortEntry == null && !entrySubmitted && CurrentBar > BarsRequiredToTrade
    && Position.MarketPosition == MarketPosition.Flat)
    {

    if (State == State.Historical)
    oco = DateTime.Now.ToString() + CurrentBar + "entry";
    else
    oco = GetAtmStrategyUniqueId() + "entry";
    entrySubmitted = true;

    if (shortEntry == null && CrossBelow(smaFast, smaSlow, 1))
    SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Limit, 100, High[0] + EntryDistance * TickSize, 0, oco, "Short limit entry");


    if (longEntry == null && CrossAbove(smaFast, smaSlow, 1))
    SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, 100, Low[0] - EntryDistance * TickSize, 0, oco, "Long limit entry");
    }​

    Please see the full cs file attached. Can you please help me understand why orders are not placed when SMA Fast and SMA Slow cross over each other when I run this strategy?
    Attached Files

    #2
    Hello wyifei6688,

    I would suggest using a Print to see whats happening, you could do something like the following:

    Code:
    Print("shortEntry null=" + (shortEntry == null) + " CrossBelow= " + CrossBelow(smaFast, smaSlow, 1));
    if (shortEntry == null && CrossBelow(smaFast, smaSlow, 1))

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    66 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X