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 Hwop38, 05-04-2026, 07:02 PM
        0 responses
        161 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        311 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        245 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        350 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        179 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Working...
        X