Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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 Tim-c, Today, 02:10 PM
|
1 response
7 views
0 likes
|
Last Post Today, 02:52 PM | ||
Started by Taddypole, Today, 02:47 PM
|
0 responses
2 views
0 likes
|
Last Post
by Taddypole
Today, 02:47 PM
|
||
Started by chbruno, 04-24-2024, 04:10 PM
|
4 responses
50 views
0 likes
|
Last Post
by chbruno
Today, 02:38 PM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
10 responses
399 views
1 like
|
Last Post
by beobast
Today, 02:35 PM
|
||
Started by lorem, Yesterday, 09:18 AM
|
5 responses
25 views
0 likes
|
Last Post Today, 12:29 PM |
Comment