Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Ninjatrader 8 help developpement
Collapse
X
-
Ninjatrader 8 help developpement
We re using ninja trader v8 and we re wondering if accessing close[0] is still the way to get current price for backtesting or real time data.Tags: None
-
Hello,
Thank you for the post.
Yes, this would still be the case. You can locate changes made to NinjaScript in the following document: http://ninjatrader.com/support/helpG...ng_changes.htm
I look forward to being of further assistance.
-
Ninjatrader 8 help developpement
Hello and thank you NinjaTrader_Jesse !
So,
I want to recover the price of the market in real time and test it in backtest following an intervale of 1 Ticks.
With a stopLoss definition and target has 1 and 2 ticks.
Here is the code I defined:
protect override void OnStateChange () {
**** If (state = state.configure) {
******* SetStopLoss (CalculationMode.Ticks, 2);
******* SetProfitTarget (CalculationMode.Ticks, 1);
**** }
}
protect override void OnBarUpdate () {
****** StatePrice = Close [0]; // current price in real time
****** Print ("current price =" + StatePrice);
}
Do you think my code is correct?
Comment
-
Hello ninintrade,
Thanks for the additional question.
This line has some misplaced capitalization "If (state = state.configure) {" where it should be: "if (State = State.Configure) {"
Other than that, your code looks correct for placing a static Profit Target and Stop Loss with 1 or two ticks difference in price since entry. You will still have to add entry methods to enter into the market, and you will have to assign the strategy to operate off of a single tick series or use Calculate.OnEachTick.
Please refer to the documentation below to check your syntax and to look further into using OnStateChange()
OnStateChange() - http://ninjatrader.com/support/helpG...tatechange.htm
Calculate - http://ninjatrader.com/support/helpG.../calculate.htm
Order Methods - http://ninjatrader.com/support/helpG...er_methods.htm
Please let me know if you have any questions on the material.
Comment
-
Hello
Thank you for answers
I would like to know how to update total net profit and display it in real time please ?
Comment
-
Hello ninintrade,
Thanks for the additional question.
So I may assist you further, could you elaborate if you are not referring to the information from the Accounts tab of the control center? You can view the Realized PnL and Unrealized PnL as it updates from there.
Accounts Tab - https://ninjatrader.com/support/help...counts_tab.htm
If you are referring to accessing these values in realtime from NinjaScript, you can use the OnAccountItemUpdate() override.
OnAccountItemUpdate() - https://ninjatrader.com/support/help...itemupdate.htm
Please let me know if I may be of further help.
Comment
-
Ninjatrader 8 help developpement
Hello NinjaTrader_Jim,
Thanks for the previous answer!
Also, I would like to know the meanings of:
MarketPosition.Flat
MarketPosition.Long
MarketPosition.Short
Even referring to the help guide, I didn't quite understand their function.
Comment
-
Hello ninintrade,
Thanks for writing back.
Those are property values for the MarketPosition property. They represent being in a long, short or flat market position. (You can read more about market positions here.)
You can use these property values to check the position of the strategy through the Position object. Referencing the MarketPosition from Position is as follows:
This will tell you if the strategy is in a flat position before executing any code within the if statement.Code:if (Position.MarketPosition == MarketPosition.Flat)
Please let me know if you have any additional questions.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment