Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need some help! L2 data in strategy

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

    Need some help! L2 data in strategy

    Hi guys and gals,

    Ive edited and rewrote my original post. I have been able to make this run perfect with the following setup, and the output displays 100% proper all of the time BUT this is not level 2, I have literally 9 different strategys I have been working on trying to get level two to do cumulative bid/ask to 1.3 ratio but for the life of me I can not do it and I have fallen off track. 1 minute chart, NQ, Calculate.OnEachTick; data resets on the beginnign of next bar, I will end up adding "do not buy/sell if ratio = 1 or 0 but I havent gotten that far yet.....

    Here is the code I have for L1, any insight on how to modify this to run off L2 data??? Any help wouold be appreciated, Im losing my mind....

    Here are the different segments associated with the bid/ask.

    public class NQGROBIDASK1 : Strategy
    {
    private MACD MACD1;
    private double cumulativeAskVolume = 0;
    private double cumulativeBidVolume = 0;​

    _______________________________

    protected override void OnMarketData(MarketDataEventArgs e)
    {
    if (e.MarketDataType == MarketDataType.Last)
    {
    double tradePrice = e.Price;
    double tradeVol = e.Volume;
    double bid = e.Bid;
    double ask = e.Ask;

    if (tradePrice >= ask)
    cumulativeAskVolume += tradeVol; // Buy at ask or higher
    else if (tradePrice <= bid)
    cumulativeBidVolume += tradeVol; // Sell at bid or lower
    }
    }
    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 1 || MACD1 == null)
    return;

    // Reset mumulative volumes at the start of each bar
    if (IsFirstTickOfBar)
    {
    cumulativeAskVolume = 0;
    cumulativeBidVolume = 0;
    }

    // alculate and pritn bid/ask ratio
    double totalVolume = cumulativeAskVolume + cumulativeBidVolume;

    Print("Bar " + CurrentBar + " - Ask/Bid Ratio: " + askBidRatio.ToString("F2") +​​
    Last edited by massgainstradingwi; 03-12-2025, 05:11 PM.

    #2
    I also have this at the bottom ofthe strategy, forgot.

    // Resset and print the reset state
    cumulativeAskVolume = 0;
    cumulativeBidVolume = 0;
    double resetRatio = 0; // Since totalVolume = 0 now
    Print("Bar " + CurrentBar + " - RESET - Ask/Bid Ratio: " + resetRatio.ToString("F0"));​

    Comment


      #3
      Well, it looks like I got the L2 to work, but in doing so it appears I lost the ability to have the MACD get its input. Below are the two areas where I believe the issue is occuring but I dont know at this point.... something so simple.... I'm racking my brain to figure out how to have it get its data but drawing a blank......

      }
      protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
      {
      if (marketDataUpdate.MarketDataType == MarketDataType.Last);

      __________________________________________________ _________________

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 1)
      return;​

      __________________________________________________ ____________________​

      Comment


        #4
        Hello,

        Thank you for your post.

        If you're trying to track changes in level 2 data, you will need to use OnMarketDepth(). OnMarketData() is for level 1 data.

        Comment


          #5
          Thanks Gaby - it was a simple error I continued to overlook..... made a mountain out of a mole hill of it.... thanks for your time.

          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