I didn't use my own Indicator() in my Strategy(), I added a print() at the beginning of the OnBarUpdate() in order to verify OnBarUpdate() is called when each bar is updated. Is there anything I have missed? Thanks.
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 trigger OnBarUpdate() to be called in Strategy()?
Collapse
X
-
How to trigger OnBarUpdate() to be called in Strategy()?
I had no problem to let OnBarUpdate() be called in Indicator(), but it looks like it is not called in Strategy(). Why?
I didn't use my own Indicator() in my Strategy(), I added a print() at the beginning of the OnBarUpdate() in order to verify OnBarUpdate() is called when each bar is updated. Is there anything I have missed? Thanks.Tags: None
-
Hi localappleseed, thanks for your post.
You can call the Update() method in any other method in your script to force the OnBarUpdate method to be called. OnBarUpdate should automatically be called for every bar on the chart once you enable the strategy (only if Calculate = OnBarClose). Can you give a test script that is not doing this?
I look forward to hearing from you.Chris L.NinjaTrader Customer Service
-
Hi, Chris, thanks for quick reply.
Here is the short script to verify OnBarUpdate() to be called.
namespace NinjaTrader.NinjaScript.Strategies
{
public class SampleLuke : Strategy
{
private string atmStrategyId = string.Empty;
private string orderId = string.Empty;
private bool isAtmStrategyCreated = false;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleATMStrategy;
Name = NinjaTrader.Custom.Resource.NinjaScriptStrategyNam eSampleATMStrategy;
// This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = false;
}
}
protected override void OnBarUpdate()
{
// Compares the primary bar's low price to the 5-minute bar's low price
Print("11111");
}
protected override void OnMarketDepth(MarketDepthEventArgs marketDepthUpdate)
{
// Print some data to the Output window
Print("The m22222");
}
}
}
Comment
-
Here is how I use Strategy().
From a active Chart, right click to select Strategies -> In Strategies Window, select Calculate = On Bar Close -> Nothing printed from Output Window.
Comment
-
Hi, Chris,
I tried two methods you suggested, so far no luck.
1) I added Update() in this method:
protected override void OnMarketDepth(MarketDepthEventArgs marketDepthUpdate)
{
Print("The m22222");
Update();
}
2) I tried to set Calculate = OnBarClose, (this is done only in GUI setup), also I tried to initialize it using code "CalculateOnBarClose=false",
None of them are working. CalculateOnBarClose is not defined in NT8. I saw it was used in NT7.
Thanks.
Comment
-
I am sure the data feed is working, I tried to use Indicator(0 which works as expected. It has output printed.
Comment
-
I compiled and applied your Test Strategy, still not working. So it looks like I didn't configure correctly.
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by andrewtrades, Today, 04:57 PM
|
1 response
5 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
3 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
436 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
7 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
||
Started by rocketman7, Today, 09:41 AM
|
5 responses
19 views
0 likes
|
Last Post Today, 03:33 PM |
Comment