#region Using declarations
using System;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Strategies;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class TickTrader : Strategy
{
private int tickThreshold = 700; // Define the threshold for TICK
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "TickTrader";
Calculate = Calculate.OnEachTick; // More responsive with OnEachTick
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = true;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
// Add an TICK 1 minute Bars object to the strategy
AddDataSeries("^TICK", Data.BarsPeriodType.Minute, 1);
// Set stop loss and profit target
SetStopLoss("", CalculationMode.Ticks, 8, false);
SetProfitTarget("", CalculationMode.Ticks, 4);
}
}
protected override void OnBarUpdate()
{
// Ensure enough bars are loaded
if (CurrentBar < BarsRequiredToTrade || CurrentBars[1] < 1)
return;
// Only trade during market hours (9:00 AM - 2:15 PM)
bool market_open = ToTime(Time[0]) >= 90000 && ToTime(Time[0]) <= 141500;
// TICK value comes from the secondary data series (index 1)
double tickValue = Closes[1][0]; // Secondary series
// Trade only when market is open
if (market_open)
{
// Go long when TICK crosses below the threshold
if (tickValue < -tickThreshold && Position.MarketPosition == MarketPosition.Flat)
{
EnterLong();
}
// Go short when TICK crosses above the threshold
if (tickValue > tickThreshold && Position.MarketPosition == MarketPosition.Flat)
{
EnterShort();
}
}
}
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Why doesnt my strategy using ^TICK work?
Collapse
X
-
Why doesnt my strategy using ^TICK work?
I dont get why this isnt working but basically I want to go long when tick crosses below 700 and vice versa. I also want to skip the first 30 minutes.Code: -
-
Hello ExtremelyRough,
I would suggest trying a Print to see if the strategy is processing bars for that series, please try adding the following to the beginning of OnBarUpdate:
if(BarsInProgress == 1)
Print(CurrentBar);
If the secondary series is added and processing you should see incrementing prints in the output window. If that is the case that means you would need to use a print to check the conditions you made.
Print(market_open);
if (market_open)
{
Comment
-
I think ive found the issue. It only enters if TICK closes above or below +-700. Is there a way to make this more responsive and enter at the cross above or below?Originally posted by NinjaTrader_Jesse View PostHello ExtremelyRough,
I would suggest trying a Print to see if the strategy is processing bars for that series, please try adding the following to the beginning of OnBarUpdate:
if(BarsInProgress == 1)
Print(CurrentBar);
If the secondary series is added and processing you should see incrementing prints in the output window. If that is the case that means you would need to use a print to check the conditions you made.
Print(market_open);
if (market_open)
{
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
111 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
59 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
38 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
41 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
78 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment