Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by nleitman, Yesterday, 11:46 AM
    9 responses
    26 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by cmtjoancolmenero, 04-25-2024, 03:58 PM
    18 responses
    105 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by kujista, Yesterday, 12:39 AM
    5 responses
    17 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by Mindset, Yesterday, 06:19 AM
    2 responses
    15 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by bubblegum, 03-18-2024, 10:41 AM
    4 responses
    51 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X