Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        559 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
        546 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