Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Data leakage between charts?

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

    Data leakage between charts?

    I have a simple indicator for displaying the ask/bid/volume (my eyes are too bad to see the ChartTrader ask/bid) and counting down ticks remaining in bar as well as a couple of other calculated values in large text on the chart. In my setup I have 2 charts open ES and EURUSD.

    The problem I am having is that occasionally (once ever 10-30 seconds) ES data will appear on the EURUSD chart and vise versa. It is not critical in this use but I am concerned this may happen in other instances where it matters.

    Below is the OnBarUpdate method I am using:

    Code:
            protected override void OnBarUpdate()
            {
                //Add your custom indicator logic here.
                volume = Volume[0];
                double count=0, avgATR;
                string strCount="";
                
                if (CurrentBar<30) return;
                if (State == State.Historical) return;
                    
                volume = Volume[0];
                avgATR=EMA(ATR(atrPeriod),4)[1];
                
                if (IsFirstTickOfBar)
                {    playedAlert = false;
                    trend=0;
                    for (int i=1; i<=12; i++)
                        trend = trend + ZLEMA(21)[i]-EMA(20)[i];
                    trend = trend/avgATR;
                }
                
                // tick counter2
                if (BarsPeriod.BarsPeriodType == BarsPeriodType.Tick)
                {      // calculate the tick count value
                    count = BarsPeriod.Value - Bars.TickCount;
                    strCount=count.ToString()+" "+"Ticks";
                }
                else if (BarsPeriod.BarsPeriodType == BarsPeriodType.Volume)
                {    // calculate the volume count value
                    count = BarsPeriod.Value - volume;
                    strCount=count.ToString()+" "+"Volume";
                }
    
                a=GetCurrentAsk();                    
                av=(int)GetCurrentAskVolume();
                b=GetCurrentBid();
                bv=(int)GetCurrentBidVolume();        
    
                if (DisplayText)
                {    string v = "Ask/Bid:\n"+
                                a.ToString("F"+DecimalPlaces.ToString())+"-"+av.ToString().PadLeft(5,' ')+"\n"+
                                b.ToString("F"+DecimalPlaces.ToString())+"-"+bv.ToString().PadLeft(5,' ')+"\n\n"+
                                strCount+"\n";
                    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial Bold", FontSize) { Size = FontSize, Bold = true };
                    Draw.TextFixed(this,"BidAsk",v,TextPosition.TopRight,Brushes.White,myFont,Brushes.Transparent,Brushes.White,0);
                    if (Instrument.FullName=="EURUSD") Print("EURUSD Ask: "+a.ToString()+"   Ask Vol: "+av.ToString());
                }            
                
                if (DisplayAskLine) Draw.Ray(this,"AL", 30, a, 0, a, Brushes.Green);
                if (DisplayBidLine) Draw.Ray(this,"BL", 30, b, 0, b, Brushes.Red);            
    
                atr=avgATR;
                if (ATRMultiplier!=0) atr=ATRMultiplier * atr;
                NinjaTrader.Gui.Tools.SimpleFont myFont2 = new NinjaTrader.Gui.Tools.SimpleFont("Arial Bold", FontSize) { Size = FontSize, Bold = true };
                Draw.TextFixed(this, "ATR","ATR: "+atr.ToString("F2")
                                        + "\n"+"Trd: "+trend.ToString("F2")
                                        +"\n\n",TextPosition.BottomRight,Brushes.White,myFont2,Brushes.Transparent,Brushes.White,0);
                
                if (PlayAlertOnTicksLeft!=-1 && !playedAlert && count<PlayAlertOnTicksLeft)
                {    PlaySound(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+EndofBarAudio);
                    playedAlert=true;
                }
            }
    Below is the output window text showing the problem note the 2271 ES data on this EURUSD chart.

    EURUSD Ask: 1.06576 Ask Vol: 8
    EURUSD Ask: 1.06577 Ask Vol: 3
    EURUSD Ask: 1.06575 Ask Vol: 4
    EURUSD Ask: 1.06576 Ask Vol: 1
    EURUSD Ask: 2271 Ask Vol: 1129
    EURUSD Ask: 1.0658 Ask Vol: 9
    EURUSD Ask: 1.0658 Ask Vol: 1
    EURUSD Ask: 1.06575 Ask Vol: 9
    EURUSD Ask: 1.06576 Ask Vol: 8
    EURUSD Ask: 1.06576 Ask Vol: 2
    EURUSD Ask: 2270.75 Ask Vol: 319
    EURUSD Ask: 1.06577 Ask Vol: 1
    EURUSD Ask: 1.06576 Ask Vol: 1
    EURUSD Ask: 1.06576 Ask Vol: 2
    EURUSD Ask: 1.06577 Ask Vol: 1
    I have tried to use the Dispatcher and Lock thread to make sure there are no threading issues but that does not help. Any idea what I am doing wrong?

    #2
    Hello seahn, and thank you for your question. I noticed most of your variables are not prototyped inside your function scope. That is, your code is

    Code:
    [FONT=Courier New]
                a=GetCurrentAsk();   
                av=(int)GetCurrentAskVolume();
                b=GetCurrentBid();
                bv=(int)GetCurrentBidVolume();[/FONT]
    and not

    Code:
    [FONT=Courier New]
                [B]double [/B]a=GetCurrentAsk();   
                [B]double [/B]av=(int)GetCurrentAskVolume();
                [B]double [/B]b=GetCurrentBid();
                [B]double [/B]bv=(int)GetCurrentBidVolume();[/FONT]
    You will want to review the code where a, av, b, and bv are prototyped. If the keyword "static" appears near here, you will then need to remove this keyword, otherwise your charts will share memory.

    If you have reviewed this code and are confident it is local to the instance variable, please send a stripped down code sample to platformsupport[at]ninjatrader[dot]com, referencing attn:ninjatrader_jessicap and 11627624 in the subject line, and we will be happy to assist further.
    Jessica P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X