Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

buy sell volume data and buy sell pressure

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

    buy sell volume data and buy sell pressure

    Dear NT team,

    I'm trying to get the buy sell volume and pressure data into my NT strategy, I'm using the existing indicator supplied in NT platform, but I get zero and NAN values. I have multiple dataseries in my strategy, I'm using the 30 seconds data series for buy sell data. Could you please check and let me know why I'm not able to get the values? I'm running my strategy realtime - Calculate = Calculate.OnEachTick;

    //code
    //Add a series seconds
    AddDataSeries(null, BarsPeriodType.Second, 30, MarketDataType.Last);

    Print("Buy Volume - " + BuySellVolume(BarsArray[2]).Buys[0]);
    Print("Sell Volume - "+ BuySellVolume(BarsArray[2]).Sells[0]);
    Print("Total Volume - "+ BuySellVolume(BarsArray[2]).Buys[0] + BuySellVolume(BarsArray[2]).Sells[0]);

    Print("Buy to Sell Ratio - "+ (BuySellVolume(BarsArray[2]).Buys[0]) / BuySellVolume(BarsArray[2]).Sells[0]);
    Print("Sell to Buy Ratio - "+ (BuySellVolume(BarsArray[2]).Sells[0]) / BuySellVolume(BarsArray[2]).Buys[0]);

    if(BuySellPressure(BarsArray[2]).BuyPressure[0] >= 70);
    {
    Print(Time[0].ToString());
    Print("Buy pressure is high - Enter LONG -"+ BuySellPressure(BarsArray[2]).BuyPressure[0]);
    }

    if(BuySellPressure(BarsArray[2]).SellPressure[0] >= 70);
    {
    Print(Time[0].ToString());
    Print("Sell pressure is high - Enter SHORT - "+ BuySellPressure(BarsArray[2]).SellPressure[0]);
    }

    //output
    2/13/2022 11:28:30 PM
    Buy pressure is high - Enter LONG -50
    2/13/2022 11:28:30 PM
    Sell pressure is high - Enter SHORT - 50
    Buy Volume - 0
    Sell Volume - 0
    Total Volume - 00
    Buy to Sell Ratio - NaN
    Sell to Buy Ratio - NaN

    Thankyou,
    Murali

    #2
    Hello radhmu978,

    Do you see the values if you call the indicator from the BarsInprogress of that series instead of passing the series to it?

    Code:
    if(BarsInProgress == 2)
    {
       Print("Sell pressure- "+ BuySellPressure().SellPressure[0]);
    }

    Comment


      #3
      let me try that and confirm

      Comment


        #4
        I tried that, still the same

        if(BarsInProgress == 2)
        {
        if(BuySellPressure().BuyPressure[0] >= 70);
        {
        Print(Time[0].ToString());
        Print("Buy pressure is high - Enter LONG -"+ BuySellPressure().BuyPressure[0]);
        }

        if(BuySellPressure().SellPressure[0] >= 70);
        {
        Print(Time[0].ToString());
        Print("Sell pressure is high - Enter SHORT - "+ BuySellPressure().SellPressure[0]);
        }

        Print("Buy Volume - " + BuySellVolume().Buys[0]);
        Print("Sell Volume - "+ BuySellVolume().Sells[0]);
        Print("Total Volume - "+ BuySellVolume().Buys[0] + BuySellVolume().Sells[0]);

        Print("Buy to Sell Ratio - "+ (BuySellVolume().Buys[0]) / BuySellVolume().Sells[0]);
        Print("Sell to Buy Ratio - "+ (BuySellVolume().Sells[0]) / BuySellVolume().Buys[0]);

        }

        //Output

        2/14/2022 9:31:00 PM
        Buy pressure is high - Enter LONG -50
        2/14/2022 9:31:00 PM
        Sell pressure is high - Enter SHORT - 50
        Buy Volume - 0
        Sell Volume - 0
        Total Volume - 00
        Buy to Sell Ratio - NaN
        Sell to Buy Ratio - NaN

        Comment


          #5
          Hello radhmu978,

          Please try adding the following line:

          Additionally, this indicator is a realtime indicator so we should see 0's in historical, to confirm you are running a forward realtime test to observe the prints is that correct?

          Code:
          if(BarsInProgress == 2)
          {
              BuySellPressure().Update();

          Comment


            #6
            my strategy is running on bar close, not on each tick. If i use the indicator inside my strategy, How do i make the indicator along to work on real time or on each tick? if i run the entire strategy real time, I get some fake signals and noise, that is the reason i'm running the strategy on bar close.

            Comment


              #7
              Hello radhmu978,

              The indicator you are using uses the incoming OnMarketData override to populate the data. That by default is not called in historical data so the indicator won't do any calculations. For this indicator to work in historical data you would need to use TickReplay. This indicator otherwise only works in realtime by using the OnMarketData override. The frequency of the plot is determined by the bar series being used, and the indicators logic works OnEachTick. To use this in your script you would need to switch your strategy to use OnEachTick calculation, indicators match the parents Calculate setting. If you need to simulate OnBarClose you could do something similar to to what the BuySellPressure does in its logic with the CurrentBar, you can view this indicators code in the NinjaScript editor.

              Comment


                #8
                I changed mt strategy to calculate on each tick, still the same results. BuySellPressure is always giving me 50, even after comparing the value >70, it still prints 50.

                2/15/2022 12:49:30 PM
                Buy pressure is high - Enter LONG -50
                2/15/2022 12:49:30 PM
                Sell pressure is high - Enter SHORT - 50
                Buy Volume - 0
                Sell Volume - 0
                Total Volume - 00
                Buy to Sell Ratio - NaN
                Sell to Buy Ratio - NaN

                Comment


                  #9
                  Hi Jesse,

                  I want to run the strategy real time and signals from indicator on bar close. If i run the indicators on each tick, I get fake signals. Is there a way to implement that?

                  Thanks,
                  Murali

                  Comment


                    #10
                    Hello radhmu978,

                    Can you clarify, were the results you provided from a realtime test? For historical that looks correct, OnEachTick would be needed but you also need to enable TickReplay and I don't see that in what you provided.

                    I want to run the strategy real time and signals from indicator on bar close. If i run the indicators on each tick, I get fake signals. Is there a way to implement that?
                    Are you asking how to keep using OnEachTick for the indicator and then also use OnBarClose for your strategy conditions? If so you can use IsFirstTickOfBar to simulate OnBarClose in that use case. https://ninjatrader.com/support/help...FirstTickOfBar

                    Comment


                      #11
                      Thank you Jesse, IsFirstTickOfBar really helps,

                      Q1 => is there a flag to identify the last tick as well , like IsLastTickOfBar to get the bar closing ? I trade with 1min chart for scalping, I want to close all the open position at the close of the bar, while running the strategy on each tick.

                      Q2 => I have multiple data series, Could you please give me some pointer to the API docs, I'm trying to understand how to lookback on the past bars in multiple data series scenarios. I'm trying to implement the pivotHigh & pivotLow by looking back on the historical bars


                      if(BarsInProgress == 2)

                      selectedBar = currentBar -2

                      If ( selectedBar > selectedBar+1 && selectedBar > selectedBar+2 &&
                      selectedBar > selectedBar-1 && selectedBar > selectedBar-2)

                      pivotHigh = true

                      If (selectedBar < selectedBar+1 && selectedBar < selectedBar+2 &&
                      selectedBar < selectedBar-1 && selectedBar < selectedBar-2)

                      pivotLow = true

                      Thankyou,
                      Murali

                      Comment


                        #12
                        Hello radhmu978,

                        Q1 => is there a flag to identify the last tick as well , like IsLastTickOfBar to get the bar closing ? I trade with 1min chart for scalping, I want to close all the open position at the close of the bar, while running the strategy on each tick.
                        No, the first tick of the bar is also what closes the previous bar.

                        I want to close all the open position at the close of the bar, while running the strategy on each tick.
                        That would require using IsFirstTickOfBar. The orders will show up on the new bar but there is no way to know the tick is a final tick in a bar to have submitted it before this point.

                        Q2 => I have multiple data series, Could you please give me some pointer to the API docs, I'm trying to understand how to lookback on the past bars in multiple data series scenarios. I'm trying to implement the pivotHigh & pivotLow by looking back on the historical bars
                        I can't tell from the code provided what the problem or question is however I do see you have lowercase currentBar which would not represent the BarsInProgress 2 CurrentBar. The lookback or BarsAgo works identically on secondary series but it does need to be relevant to that series. If you store a CurrentBar from the primary bars in progress that won't be relevant to the secondary series.

                        Comment


                          #13

                          Q2 => I have multiple data series, Could you please give me some pointer to the API docs, I'm trying to understand how to lookback on the past bars in multiple data series scenarios. I'm trying to implement the pivotHigh & pivotLow by looking back on the historical bars


                          <RM> Just to keep the question simple, I will use 1 min chart, just one data series. I want to navigate back to 3 recently closed bar, so that I get 2 recently closed bard on the left and right. Usign those bars I'm trying to calculate the pivots. My question is, How to navigate or lookback on the historical bar data in NT8. Could you please help me to understand that indexing concepts and bars lookback in NT8?

                          Comment


                            #14
                            Hello radhmu978,

                            Q2 => I have multiple data series, Could you please give me some pointer to the API docs, I'm trying to understand how to lookback on the past bars in multiple data series scenarios. I'm trying to implement the pivotHigh & pivotLow by looking back on the historical bars
                            You can read about working with multiple series in the following link.



                            <RM> Just to keep the question simple, I will use 1 min chart, just one data series. I want to navigate back to 3 recently closed bar, so that I get 2 recently closed bard on the left and right. Usign those bars I'm trying to calculate the pivots. My question is, How to navigate or lookback on the historical bar data in NT8. Could you please help me to understand that indexing concepts and bars lookback in NT8?
                            NInjaScript uses the BarsAgo field to determine what bar you wanted data from. If you wanted to get 3 bars back then you would use [3] with whatever series you want data from: Close[3] Open[3] Time[3] etc.

                            Comment


                              #15
                              Could you please give me some sample code snippet? I'm trying to get the historic BarData OHLC by looking back 3 or 4 period.

                              So, For DataSeries 1

                              if(BarInProgress == 1)
                              {
                              barIndex = 3 // get bar data 3 period back

                              double closePrice = Bars.GetClose(barIndex);
                              Print("Bar #" + barIndex + " closing price is " + closePrice);

                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              574 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X