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

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 Waxavi, Today, 02:10 AM
    0 responses
    3 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by TradeForge, Today, 02:09 AM
    0 responses
    7 views
    0 likes
    Last Post TradeForge  
    Started by Waxavi, Today, 02:00 AM
    0 responses
    2 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by elirion, Today, 01:36 AM
    0 responses
    4 views
    0 likes
    Last Post elirion
    by elirion
     
    Started by gentlebenthebear, Today, 01:30 AM
    0 responses
    4 views
    0 likes
    Last Post gentlebenthebear  
    Working...
    X