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
Current current price bar in historical testing
Collapse
X
-
Current current price bar in historical testing
I am trying to set up a strategy that moves stop loss prices as the price increases but when I view in debug mode, the value Close[CurrentBar], does not change but I can see that the value of CurrentBar is increasing. The code is in the OnBarUpdate() method. -
Hello mww1615,
Series use barsAgo values for indexes.
0 bars ago would be the current bar.
Using Close[CurrentBar] would return the close price of the first bar on the chart not the current bars close. This wouldn't change because that bar is already closed.
Below is a public link to the help guide on Close.
Chelsea B.NinjaTrader Customer Service
-
I am trying to backtest a strategy with changing stop losses and when I check the value of CurrentBar, it increases each time thru so I assumed close[CurrentBar] would be getting the price that was currently being evaluated on the chart. Here is the code I am trying to run to change the stop loss price based on how much the price has increased. Can you please give me a suggestion of how I can do this.
if (Position.MarketPosition == MarketPosition.Long)
{
double p = Close[CurrentBar];
if ( Close[CurrentBar] >= (entry_price + 6 * TickSize) && controlOne)
{
SetStopLoss("stopOrder", CalculationMode.Price, Position.AveragePrice, true);
controlOne = false;
}
else if (Close[CurrentBar] >= (entry_price + 12 * TickSize) && !controlOne)
{
SetStopLoss("stopOrder", CalculationMode.Price, Position.AveragePrice + 4* TickSize, true);
}
}
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by alifarahani, Today, 09:40 AM
|
3 responses
15 views
0 likes
|
Last Post Today, 12:47 PM | ||
Started by RookieTrader, Today, 09:37 AM
|
4 responses
17 views
0 likes
|
Last Post
by RookieTrader
Today, 12:46 PM
|
||
Started by PaulMohn, Today, 12:36 PM
|
0 responses
4 views
0 likes
|
Last Post
by PaulMohn
Today, 12:36 PM
|
||
Started by love2code2trade, 04-17-2024, 01:45 PM
|
4 responses
40 views
0 likes
|
Last Post Yesterday, 10:31 PM | ||
Started by junkone, Today, 11:37 AM
|
3 responses
23 views
0 likes
|
Last Post Today, 12:23 PM |
Comment