Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

New Bar type: Dollar Bars

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

    New Bar type: Dollar Bars

    Hi,

    I think you don't have it (yet), but, have you thought about creating Dollar Bars?
    Would it make sense?

    In his book - Advances in Financial Machine Learning, Marcos Lopez de Prado familiarises the reader with a number of ways of normalizing our financial time series data. Below I provide a couple of



    #2
    Hello artson,

    Yes you are able to create a custom bar type.

    Below is a link to some custom bar types in the User App Share.


    Are you planning to multiply the volume by the market price and accumulate this?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea!

      Yes, this is the idea

      In this paper I sent, it seems to be a better "price approach"
      Also it would make easier to compare 2 different instruments (ES, gold, oil.....)

      It's a first idea

      Comment


        #4
        Hello artson,

        I should also have included a to the help guide, which I am including below.


        Let me know if you have any questions as you develop your custom bar type.

        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          artson any progress on this new bar type? Thanks

          Comment


            #6
            Curious what happened with this or if anyone created dollar bars, tick imbalance bars, or tick run bars. Below are two Python snippets of code for tick imbalance bars and the other code is for tick run bars. Not the exact same thing as dollar bars but it offers up another way to consider visualizing the data.

            ## code to create tick imbalance bar
            weighted_sum_T = 7
            alpha = 0.9
            weighted_sum_prob = 0.3
            data["delta_p"] = data['open'].pct_change()
            imbalance = 2
            b_t = np.zeros(len(data["delta_p"]))
            b_t[0]=1
            indx = []
            T=0

            for i in range(1,len(data["delta_p"])):
            if data["delta_p"][i] == 0:
            b_t[i]=b_t[i-1]
            else:
            b_t[i] = np.abs(data["delta_p"][i])/data["delta_p"][i]
            T+=1
            if (abs(b_t.sum())>=imbalance):
            indx.append(i)
            weighted_sum_T = alpha*T + (1-alpha)*weighted_sum_T ### E(T)
            weighted_sum_prob = alpha*sum(x>0 for x in b_t)/(T) + (1 - alpha) * weighted_sum_prob
            imbalance = weighted_sum_T * abs(2*weighted_sum_prob-1)

            T = 0
            b_t = np.zeros(len(data["delta_p"]))



            final_data=pd.DataFrame()
            open =[]
            close=[]
            volume=[]
            for i in range(len(indx)-1):
            ind = (indx[i],indx[i+1])
            temp_data = data[ind[0]:ind[1]]
            open.append(temp_data['open'].iloc[0])
            close.append(temp_data['close'].iloc[-1])
            volume.append(temp_data['volume'].sum())

            final_data['open']=open
            final_data['close']=close
            final_data['volume']=volume​

            Tick Run Bars:

            weighted_sum_T = 7
            alpha = 0.9
            weighted_sum_prob = 0.3
            data["delta_p"] = data['open'].pct_change()
            imbalance = 2
            b_t = np.zeros(len(data["delta_p"]))
            b_t[0]=1
            indx = []
            T=0

            for i in range(1,len(data["delta_p"])):
            if data["delta_p"][i] == 0:
            b_t[i]=b_t[i-1]
            else:
            b_t[i] = np.abs(data["delta_p"][i])/data["delta_p"][i]
            T+=1
            theta = max(sum(x>0 for x in b_t), -sum(x<0 for x in b_t))
            if (theta >=imbalance):
            indx.append(i)
            weighted_sum_T = alpha*T + (1-alpha)*weighted_sum_T
            weighted_sum_prob = alpha*sum(x>0 for x in b_t)/(T) + (1 - alpha) * weighted_sum_prob
            imbalance = weighted_sum_T * max(1-weighted_sum_prob, weighted_sum_prob)

            T = 0
            b_t = np.zeros(len(data["delta_p"]))

            final_data=pd.DataFrame()
            open =[]
            close=[]
            volume=[]
            for i in range(len(indx)-1):
            ind = (indx[i],indx[i+1])
            temp_data = data[ind[0]:ind[1]]
            open.append(temp_data['open'].iloc[0])
            close.append(temp_data['close'].iloc[-1])
            volume.append(temp_data['volume'].sum())

            final_data['open']=open
            final_data['close']=close
            final_data['volume']=volume

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            605 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            351 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            560 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            561 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X