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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    89 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X