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 ezekilany, Today, 01:10 AM
|
0 responses
3 views
0 likes
|
Last Post
by ezekilany
Today, 01:10 AM
|
||
Started by usjavaburn, Today, 12:59 AM
|
0 responses
3 views
0 likes
|
Last Post
by usjavaburn
Today, 12:59 AM
|
||
Started by heatherjmarshalls, Today, 12:56 AM
|
0 responses
2 views
0 likes
|
Last Post Today, 12:56 AM | ||
Started by Nicholewatkinsi, Yesterday, 10:53 PM
|
0 responses
6 views
0 likes
|
Last Post Yesterday, 10:53 PM | ||
Started by dward123, 01-02-2024, 09:59 PM
|
4 responses
176 views
0 likes
|
Last Post
by Lancer
Yesterday, 09:27 PM
|
Comment