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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    62 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    134 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X