AF
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
Position size based on account size
Collapse
X
-
Position size based on account size
I'd like to include in my forex strategy a position size based on the account size (cash). I've found the AccountItem.TotalCashBalance instruction but i don't know how to use it, where i can put it in the strategy builder, etc, etc. I also have to include the value of the money that i buy. Thanks for help.
AFTags: None
-
Hello Alf63,
Thank you for your note.
Account items such as account balance are an advanced concept that would require custom coding outside the strategy builder.
If you'd like, I can have someone reach out with a list of third party developers that would be interested in building this into your strategy.
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
-
Hello Alf63,
May I confirm you'd like a list of third parties?
When you are ready to work in the NS editor to code yourself, the attached sample will buy x amount of micro lots based on FX account size, you may find this helpful.
More information on learning NinjaScript,
I would suggest watching the Strategy Wizard 301 which goes over using the wizard to create strategies.
Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Wizard.3:23 Strategy Wizard Overview7:...
See the NinjaScript Editor Youttube,
Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...
A link to our Help Guide with tutorials can be found below:
You will find Reference Samples online as well as some Tips and Tricks for both indicators and strategies:
Click here to see our NinjaScript Reference Samples:
Click here to see our NinjaScript Tips:
I look forward to your reply.Attached FilesLast edited by NinjaTrader_AlanP; 01-10-2018, 03:07 PM.Alan P.NinjaTrader Customer Service
Comment
-
Originally posted by Alf63 View PostI'd like to include in my forex strategy a position size based on the account size (cash). I've found the AccountItem.TotalCashBalance instruction but i don't know how to use it, where i can put it in the strategy builder, etc, etc. I also have to include the value of the money that i buy. Thanks for help.
AF
create these variables:
Code:AccountSize = 50000; RiskPercent = 0.2; Leverage = 40;
Then to get current account value (available funds for the next trade):
Code:[B]//this code will sum your "starting" capital with current profit/loss on the strategy. [/B] double total_fundUSD= AccountSize+Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Closes[1][0]) +SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit; [B]//this code will take the above account, and multiple it with "risk percent" to calculate how much funds you are going to use on the "next trade."[/B] double dummyQ = (((int)Math.Floor((total_fundUSD*RiskPercent)/3)) * Leverage); [B]//this code will normalize the above calculated volume by 1000's so that it's a even forex lot.[/B] fxToBuy = ((int)(dummyQ/1000))*1000; [B]//this code will print the amount for the lot you are going to buy[/B] Print(fxToBuy); [B]//this code will give you the current value for the account[/B] Print(total_fundUSD);
Good luck!
Comment
-
Hi, Re: BuyXMicroLotsOfFxPerAccountSize.zip (1.8 KB, 98 views), nothing happens when I run this strat as is.​
Comment
-
Hello trader3000a,
Thanks for your note.
When testing the example script shared on post number 4 on a 1-Minute EURUSD chart, I am seeing the strategy print out the account size and number of shares to buy to a NinjaScript Output window and place an order on the chart reflecting the number of shares to buy seen in the Output window.
Please see attached screenshot demonstrating this.
If you enable the script on a 1-Minute EURUSD chart that has live data populating on the chart, do you see the strategy behaving on your end similar to the screenshot attached?
Let me know if I may assist further.Brandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by algospoke, Yesterday, 06:40 PM
|
2 responses
20 views
0 likes
|
Last Post
by algospoke
Today, 07:04 PM
|
||
Started by ghoul, Today, 06:02 PM
|
3 responses
14 views
0 likes
|
Last Post Today, 06:43 PM | ||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
45 views
0 likes
|
Last Post
by jeronymite
Yesterday, 10:10 PM
|
||
Started by Barry Milan, Yesterday, 10:35 PM
|
7 responses
21 views
0 likes
|
Last Post Today, 06:16 PM | ||
Started by AttiM, 02-14-2024, 05:20 PM
|
10 responses
181 views
0 likes
|
Last Post
by jeronymite
Today, 06:11 PM
|
Comment