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 jxs_xrj, 01-12-2020, 09:49 AM
|
5 responses
3,289 views
1 like
|
Last Post
by jgualdronc
Today, 10:47 AM
|
||
Started by Touch-Ups, Today, 10:36 AM
|
0 responses
5 views
0 likes
|
Last Post
by Touch-Ups
Today, 10:36 AM
|
||
Started by geddyisodin, 04-25-2024, 05:20 AM
|
8 responses
61 views
0 likes
|
Last Post Yesterday, 10:45 AM | ||
Can someone turn this thinkscript into a ninjascript. 5PM CST OHL and Previous Day
by Option Whisperer
Started by Option Whisperer, Today, 09:55 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 09:55 AM | ||
Started by halgo_boulder, 04-20-2024, 08:44 AM
|
2 responses
24 views
0 likes
|
Last Post Today, 09:41 AM |
Comment