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 rhyminkevin, Today, 04:58 PM
|
3 responses
51 views
0 likes
|
Last Post
by Anfedport
Today, 05:24 PM
|
||
Started by iceman2018, Today, 05:07 PM
|
0 responses
5 views
0 likes
|
Last Post
by iceman2018
Today, 05:07 PM
|
||
Started by lightsun47, Today, 03:51 PM
|
0 responses
7 views
0 likes
|
Last Post
by lightsun47
Today, 03:51 PM
|
||
Started by 00nevest, Today, 02:27 PM
|
1 response
14 views
0 likes
|
Last Post
by 00nevest
Today, 03:48 PM
|
||
Started by futtrader, 04-21-2024, 01:50 AM
|
4 responses
50 views
0 likes
|
Last Post
by futtrader
Today, 03:01 PM
|
Comment