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
2nd timeframe, Calculate.OnEachTick: but 2nd timeframe [0] is last historical candle
Collapse
X
-
-
Hi catinabag, thanks for your note.
Try turning on Tick Replay. (be sure to read "How to Enable Tick Replay") You will get historical ticks on the secondary series up until the point of the first real-time tick. Things like "IsFirstTickOfBar" work as expected on the historical to real time transition with tick replay on.
Please let me know if this does not resolve your inquiry.Chris L.NinjaTrader Customer Service
-
Hi, appreciate the email.
Actually, the "simple approach" as I interpreted your message did not work.
A simple approach based on your message:
1. I went to Control Center -> Tools -> Options -> Market Data -> <check Show Tick Replay>
2. I added the code: "if(IsFirstTickOfBar){ " with a "}" at the end, so that this statement encapsulates the entirety of OnBarUpdate().
**This didn't do anything at all.**
B. A more complicated approach
1. It seems I would have to reference the historical secondary timeframe data in OnBarUpdate() but then get the current data from OnMarketData().
2. Then, I would somehow combine these data into a single formula, and then *that* would be useful.
3. I have no idea where the entry and exit logic would reside since, presumably, OnMarketData() comes after OnBarUpdate() in the code, and all my entry/exit stuff is in OnBarUpdate().
So, I have the following questions:
(i) Did I get it right when I described what needs to be done via my "B" entry above?
(ii) Do you have any sample code that shows the approach in "B"?
(iii) I'm troubled to read that "Tick Replay" and OnMarketData() are very data intensive. Does this mean it will lead to a system crash?
Thank you!
Comment
-
In addition to my questions in the prior post, I thought it would be helpful to post a sample code and picture to illustrate the issue.
This simple code is plotting the High[0] of the five-minute datafeed.
namespace NinjaTrader.NinjaScript.Strategies
{
public class TEST2 : Strategy
{
private Series<double> test;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "TEST2";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.AdoptAccountPosition;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
AddPlot(Brushes.Blue, "StrategyPlot");
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 5);
}
else if (State == State.DataLoaded)
{
test = new Series<double>(this, MaximumBarsLookBack.Infinite);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1
|| CurrentBars[1] < 1)
return;
test[0] = Highs[1][0];
StrategyPlot[0] = test[0];
// Set 1
if (test[0] == 0)
{
EnterLongLimit(Convert.ToInt32(DefaultQuantity), (Close[0] + (-2 * TickSize)) , "");
}
// Set 2
if (test[0] == 100000)
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
}
// Set 3
}
#region Properties
public Series<double> StrategyPlot
{
get { return Values[0]; }
}
#endregion
Now, let's look at the picture. You'll see the orange plot is *5 minutes late* on the 1st through 4th minutes and 6th through 9th minutes of the chart.
Please take a look at the picture. I would like the orange line to be shifted five minutes to the left!
I would be very grateful if someone could please explain to me the simple solution to this problem. Thank you!1 Photo
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Padan, Today, 02:02 AM
|
0 responses
6 views
0 likes
|
Last Post
by Padan
Today, 02:02 AM
|
||
Started by bukowa, 11-09-2023, 06:07 PM
|
20 responses
406 views
0 likes
|
Last Post
by Adfra
Today, 01:36 AM
|
||
Started by yertle, Yesterday, 05:49 PM
|
2 responses
11 views
0 likes
|
Last Post
by yertle
Today, 12:12 AM
|
||
Started by kaywai, Today, 12:06 AM
|
0 responses
9 views
0 likes
|
Last Post
by kaywai
Today, 12:06 AM
|
||
Started by kaywai, 03-25-2024, 10:04 PM
|
3 responses
37 views
0 likes
|
Last Post
by kaywai
Yesterday, 11:57 PM
|
Comment