Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
New Bar type: Dollar Bars
Collapse
X
-
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
-
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
599 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
344 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
558 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
557 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment