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 CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    167 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    88 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    128 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    208 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    185 views
    0 likes
    Last Post CarlTrading  
    Working...
    X