Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy occasionally blocks data

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

    Strategy occasionally blocks data

    Hello,
    I have a sporadic problem where a particular strategy sometimes blocks data from being received on all other charts. The if I disable the strategy, the charts would then be flooded with all the data that they should have been processing.

    I am using OnMarketData(MarketDataEventArgs e) routine from which I call every function in the strategy one the currentbar has changed. It also replace onbarupdate for me in this case as well.
    Is there anything I can look at to determine if I have locked threads of Files that would block Ninjatrader incoming market data and make it queue in line until the strategy is disable and then process as normal?





    if (Bars.Count <= 100)
    return;


    if(State ==State.Realtime )
    if (CurrentBar>100)
    if (CallOnce==false)
    {
    CallOnce=true;

    }
    if (State !=State.Realtime)
    return;

    try
    {
    if (BarsInProgress !=0)
    return;
    if (Sim22_VsaMaV1(Close, 50).IsValidDataPointAt(1) == false )
    return;
    else
    {
    Draw.Diamond(this,"sims"+ CurrentBar%10+1, false, 1,Sim22_VsaMaV1(Close, 50)[1], Brushes.Turquoise);
    }

    if ((ToTime(Time[0]) > 160000) && MarketPosition.Flat != Positions[TradeSeries].MarketPosition && Flatten ==false)
    {
    ExitLong();
    ExitShort();
    Flatten=true;
    }

    if (Time[0].Ticks >= startTime.Ticks && startBarIndex == 0)
    startBarIndex = CurrentBar;
    if (startBarIndex > 0 && startBarIndex == CurrentBar)
    Draw.Diamond(this,"Start Tag", false, 0, High[0] + TickSize, Brushes.Turquoise);


    /// THis Section different?
    if (lastBar != CurrentBar)
    { RealBars++;
    if(WeakHead.IsValidDataPoint(1))
    {
    Draw.TriangleDown(this,"WeakHead" + CurrentBar, false,1, High[1] + 3 * TickSize, Brushes.Purple);
    Draw.TriangleDown(this,"WeakHead2" + CurrentBar, false,1, High[1] + 5 * TickSize, Brushes.Purple);
    }
    if(WeakBottom.IsValidDataPoint(1))
    {
    Draw.TriangleUp(this,"WeakBottom" + CurrentBar, false,1, High[1] - 3 * TickSize, Brushes.Purple);
    Draw.TriangleUp(this,"WeakBottom2" + CurrentBar, false,1, High[1] - 5 * TickSize, Brushes.Purple);
    }
    Analyse();
    NewBarUpdate();

    volumeInfoL[lastarrayVal].Clear();
    lastarrayVal=activearray;

    if (activearray==19)
    {activearray=0;}
    else
    {activearray++;}

    lastBar = CurrentBar;
    volumeInfoC.Clear();
    //DrawZones();
    }
    // End Difference
    if (e.MarketDataType == MarketDataType.Ask)
    {
    askPrice = e.Price;

    return;

    }
    if (e.MarketDataType == MarketDataType.Bid)
    {
    bidPrice = e.Price;
    return;
    }
    if ( ChartControl == null || askPrice == 0 || bidPrice == 0)
    return;
    if (e.MarketDataType == MarketDataType.Last)
    {// Print(GetCurrentAsk() + " Using " + askPrice);
    double price = e.Price;
    long volume = e.Volume;

    if (!volumeInfoL[activearray].ContainsKey(price))
    volumeInfoL[activearray].Add(price, new VolumeInfoItem());

    VolumeInfoItem volumeInfoItem = volumeInfoL[activearray][price];

    if (price > LastSeen)
    { volumeInfoItem.up += volume;
    // Print("buy");
    }
    else
    { if (price <LastSeen)
    { volumeInfoItem.down += volume;
    //Print("sell");
    }
    else
    {
    if (price >bidPrice)
    {volumeInfoItem.up += volume;

    //Print("buy");
    }
    else
    {//Print("sell");
    volumeInfoItem.down += volume;
    }
    }
    }


    LastSeen=price;

    CreateFootPrint(); //thisone
    }
    }
    catch (Exception f)
    {
    // Outputs the error to the log
    Log(f.ToString(), NinjaTrader.Cbi.LogLevel.Error);
    Print("string Error" + f.ToString());
    throw;
    }
    }

    #2
    Hello richa61416,

    Is there anything I can look at to determine if I have locked threads of Files that would block Ninjatrader incoming market data and make it queue in line until the strategy is disable and then process as normal?
    No not specifically. Are you doing something in your logic which may lock the thread or need to wait for a return? I don't see anything that sticks out in what you provided.

    The only item I can see is that you are using try/catch, we generally suggest avoiding those in NinjaScript so that NinaTrader can accurately handle/log exceptions. You may want to try removing those items and re test the situation to see if anything else is reported.

    You will likely need to reduce the situation further to find the cause here. If you have a general way to reproduce the problem or if you know the general timeframe it takes to happen you could test this in various steps. Commenting out some logic for each test could help reduce what is happening to locate the offending code. Alternatively you could create a few copies and reduce each copies code more and more, then run one at a time to test each copy.

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    52 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X