Thank You
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
Strategy Analyzer - Next Bar
Collapse
X
-
Hello Silver13,
On each new bar, OnBarUpdate is triggered. You would need to wait for the next bar to close to know what the low of that bar will be.
To print the low after an order:
Code:private Order entryOrder; private bool triggerPrint; protected override void OnBarUpdate() { if (entryOrder == null) { entryOrder = EnterLong(); triggerPrint = true; } else if (entryOrder != null && Position.MarketPosition == MarketPosition.Long && triggerPrint == true) { Print(Low[0]); triggerPrint = false; } }
If Calculate is set to OnBarClose, this will print the low of the next bar. If Calculate is OnEachTick, this would be the Low after the first tick is received after the position has changed.Chelsea B.NinjaTrader Customer Service
-
Hello Silver13,
That sort of information you will have to extract on your own.
If to want to monitor how many time the next bar closes above or below the entry price, you will want to create your own logic to a) record the CurrentBar in which the strategy entered, and b) to see if the CurrentBar following the entry is greater than or less than the close of the entry bar.
As an example:
private int lastEntry;
Code:private int lastEntry; protected override void OnBarUpdate() { if (CurrentBars[0] < BarsRequiredToTrade ) return; if (Position.MarketPosition == MarketPosition.Flat) { EnterLong(Convert.ToInt32(DefaultQuantity1), @" LongPosition "); lastEntry = CurrentBar; } if (CurrentBar == lastEntry + 1) if(Close[0] > Close[1]) Print("Greater"); else if (Close[0] < Close[1]) Print("Less"); }
CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
Print() - https://ninjatrader.com/support/help...n-us/print.htm
Log() - https://ninjatrader.com/support/help.../en-us/log.htm
Read and Write to a text file - http://ninjatrader.com/support/forum...ead.php?t=3477JimNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jim View PostHello Silver13,
That sort of information you will have to extract on your own.
If to want to monitor how many time the next bar closes above or below the entry price, you will want to create your own logic to a) record the CurrentBar in which the strategy entered, and b) to see if the CurrentBar following the entry is greater than or less than the close of the entry bar.
As an example:
private int lastEntry;
Code:private int lastEntry; protected override void OnBarUpdate() { if (CurrentBars[0] < BarsRequiredToTrade ) return; if (Position.MarketPosition == MarketPosition.Flat) { EnterLong(Convert.ToInt32(DefaultQuantity1), @" LongPosition "); lastEntry = CurrentBar; } if (CurrentBar == lastEntry + 1) if(Close[0] > Close[1]) Print("Greater"); else if (Close[0] < Close[1]) Print("Less"); }
CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
Print() - https://ninjatrader.com/support/help...n-us/print.htm
Log() - https://ninjatrader.com/support/help.../en-us/log.htm
Read and Write to a text file - http://ninjatrader.com/support/forum...ead.php?t=3477
If I have a strategy builder custom strategy created for what happens if: I enter on a down close, and exit the next close - Can I see what the Fibonacci or other statistics are for what the next bar did, not just winning and losing trades, net profit, etc.
Comment
-
Hello Silver13,
Something complex like counting a number of bars or subtracting a saved bar number from CurrentBar is beyond the capabilities of the Strategy Builder and would need to be coded by hand.
The logic would likely be added to OnBarUpdate.
Below I am providing a public link to a forum post with helpful information about getting started with NinjaScript.
You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
That said, you would likely want to save the CurrentBar number when the event you are looking for occurs, that may also trigger an action such as placing an order.
Then you would want to create a for loop from the CurrentBar back to CurrentBar minus the saved bar number. For each bar in the loop, you can get the Close[barsAgo], High[barsAgo], Low[barsAgo], etc.Chelsea B.NinjaTrader Customer Service
Comment
-
Hello Silver13,
This looks like some probability statistics.
I can't assist with the math or logic, but I am happy to answer any questions you may have about NinjaScript if you decide to code this yourself.
This thread will remain open for any community members that would like to assist with the math or logic.
You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by WHICKED, Today, 12:56 PM
|
1 response
8 views
0 likes
|
Last Post Today, 01:17 PM | ||
Started by cre8able, Today, 01:16 PM
|
0 responses
1 view
0 likes
|
Last Post
by cre8able
Today, 01:16 PM
|
||
Started by chbruno, 04-24-2024, 04:10 PM
|
2 responses
47 views
0 likes
|
Last Post
by chbruno
Today, 01:15 PM
|
||
Started by WHICKED, Today, 12:45 PM
|
1 response
10 views
0 likes
|
Last Post Today, 01:08 PM | ||
Started by samish18, Today, 01:01 PM
|
0 responses
5 views
0 likes
|
Last Post
by samish18
Today, 01:01 PM
|
Comment