AF
Announcement
Collapse
No announcement yet.
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.
See the NinjaScript Editor Youttube,
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
-
below is the code that i've used to solve the problem: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:
Above can be the "starting" capital for your strategy. Risk percent is how much you are going to allocate to each trade. Leverage, is the leverage that you are using during your live trading.Code:AccountSize = 50000; RiskPercent = 0.2; Leverage = 40;
Then to get current account value (available funds for the next trade):
This may not be exactly what you are looking for but it has all the information for you to get started. You cannot do this in Strategy Builder, you will have to unlock the code and manually plug the above variables under OnBarUpdate.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.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
61 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
134 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|

Comment