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

Can OnMarketData(MarketDataEventArgs e) reference TWO instruments bid-ask?

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

    Can OnMarketData(MarketDataEventArgs e) reference TWO instruments bid-ask?

    Help! Getting an error that my var "does not exist in current context"

    I've added a second instrument, and used "BarsInProgress" to parse out the bid-asks. Can you tell what is wrong? It works if I remove the "if(BarsInProgress ==0)", but that defeats the ability to get the bid-asks of each instrument separately.


    protected override void Initialize()
    {
    Add(Symbol2, BarsPeriod.Id, BarsPeriod.Value);
    }
    protected override void OnMarketData(MarketDataEventArgs e)
    {
    if (e.MarketData.Ask == null || e.MarketData.Bid == null)
    return;

    if (BarsInProgress == 0) {
    double aAsk=e.MarketData.Ask.Price;
    double aBid=e.MarketData.Bid.Price;
    }

    SpreadHigh.Set( Qty1* aAsk ); // throws error "The name 'aAsk" does not exists in the current context"
    SpreadLow.Set( Qty1* aBid ); // throws error "The name 'aBid" does not exists in the current context"
    Last edited by chrisflow; 05-24-2013, 10:28 PM. Reason: Clarifying my question better

    #2
    Based on what you posted, I'm not sure where you are accessing aAsk from ?!!!

    Anyways, if it is within the same indicator/strategy...

    Declare your aAsk/bid in the #variables region..

    double aAsk;

    Then in OnMarketData


    if (BarsInProgress == 0) {
    aAsk=e.MarketData.Ask.Price;
    aBid=e.MarketData.Bid.Price;
    }

    Then wherever your other code resides (within this strat/ind), should work... I hope





    Originally posted by chrisflow View Post
    Help! Getting an error that my var "does not exist in current context"

    I've added a second instrument, and used "BarsInProgress" to parse out the bid-asks. Can you tell what is wrong? It works if I remove the "if(BarsInProgress ==0)", but that defeats the ability to get the bid-asks of each instrument separately.


    protected override void Initialize()
    {
    Add(Symbol2, BarsPeriod.Id, BarsPeriod.Value);
    }
    protected override void OnMarketData(MarketDataEventArgs e)
    {
    if (e.MarketData.Ask == null || e.MarketData.Bid == null)
    return;

    if (BarsInProgress == 0) {
    double aAsk=e.MarketData.Ask.Price;
    double aBid=e.MarketData.Bid.Price;
    }

    SpreadHigh.Set( Qty1* aAsk ); // throws error "The name 'aAsk" does not exists in the current context"
    SpreadLow.Set( Qty1* aBid ); // throws error "The name 'aBid" does not exists in the current context"

    Comment


      #3
      If this is all within OnMarketData


      Code:
      if (BarsInProgress == 0) {
      double aAsk=e.MarketData.Ask.Price;
      double aBid=e.MarketData.Bid.Price;
      } [I][B]<---aAsk, aBid DIE here with the closing brace } [/B][/I]
      
      SpreadHigh.Set( Qty1* aAsk ); // throws error "The name 'aAsk" does not exists in the current context"
      SpreadL

      Comment


        #4
        That worked

        Thank you that did the trick!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by frankthearm, Today, 09:08 AM
        7 responses
        29 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by NRITV, Today, 01:15 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by maybeimnotrader, Yesterday, 05:46 PM
        5 responses
        25 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by quantismo, Yesterday, 05:13 PM
        2 responses
        18 views
        0 likes
        Last Post quantismo  
        Started by adeelshahzad, Today, 03:54 AM
        5 responses
        33 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X