how do I store any particular entry price in a variable so it can be part of another calculation?
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
how to store an entry price in a variable?
Collapse
X
-
how to store an entry price in a variable?
is there a function to store an entry price in a variable that can be used for another calculation? For example, lets say I have an initial position in EURUSD at 1.5 and then I add to my position at 1.46 I want to hold on making any additional buys until price falls below(outside) the distance between my first entry and my second entry (.04) in order to keep from leveraging up too soon in a downturn.
how do I store any particular entry price in a variable so it can be part of another calculation?Tags: None
-
Hello ShruggedAtlas,
Thank you for the question.
This could be accomplished in a few ways, the most accurate being the use of the OnExecutionUpdate override and Order variables.
After defining a variable in the scope you wanted (private variable or local variable) you could use the value of either the Close price or the executions average fill price in your calculation. If you take a look at the examples in the following page you can see how the execution information can be used: https://ninjatrader.com/support/help...ub=onexecution
In a script where the calculation is needed in other areas such as OnBarUpdate, you may want to use a private Order variable like the following:
Code:private Order entryOrder; protected override OnBarUpdate() { if(entryOrder != null) { //do my calculation here Print(entryOrder.AverageFillPrice); } } protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId,DateTime time) { if (execution.Order.Name == "myEntryOrder") entryOrder = execution.Order; }
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by trilliantrader, 04-18-2024, 08:16 AM
|
4 responses
18 views
0 likes
|
Last Post Today, 10:33 PM | ||
Started by mgco4you, Today, 09:46 PM
|
1 response
7 views
0 likes
|
Last Post Today, 09:56 PM | ||
Started by wzgy0920, Today, 09:53 PM
|
0 responses
9 views
0 likes
|
Last Post
by wzgy0920
Today, 09:53 PM
|
||
Started by Rapine Heihei, Today, 08:19 PM
|
1 response
10 views
0 likes
|
Last Post Today, 08:30 PM | ||
Started by Rapine Heihei, Today, 08:25 PM
|
0 responses
10 views
0 likes
|
Last Post Today, 08:25 PM |
Comment