Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
ATM in ninja script strategy
Collapse
X
-
I am using Default 24/7 session template in market replay. Is there a session template in Ninja that start before 6:30?
Comment
-
Initialize () section:
startTime = new DateTime(0001, 1, 1, 6, 30, 00); // ignore the date portion. It is unused
endTime = new DateTime(0001, 1, 1, 15, 20, 00);
OnBarUpdate() section:
if (ToTime(Time[0]) >=ToTime(startTime) && ToTime(Time[0]) <= ToTime(endTime))
Properties section:
[Description("Time to start trading (if you want to trade within a window or subset of the overall session). Use Military time (00-24)")]
[Category("Parameters")]
[Gui.Design.DisplayName("Time Start")]
public string StartTime
{
get { return startTime.ToString("HH:mm:ss"); } // "hh:mm:ss tt"
set { startTime = Convert.ToDateTime(value); }
}
[Description("Time to stop trading (if you want to trade within a window or subset of the overall session). Use Military time (00-24)")]
[Category("Parameters")]
[Gui.Design.DisplayName("Time End")]
public string EndTime
{
get { return endTime.ToString("HH:mm:ss"); } // "hh:mm:ss tt" for AM/PM visual
set { endTime = Convert.ToDateTime(value); }
}
Is there a wrong in my code?
Comment
-
luxurious_04, the default 24 / 7 template would offer all available data, so it should cover the time range you've setup - please add a print or drawing object to check how your time conditions are exactly triggering. Is there perhaps a replay day missing or incomplete in your data available?
Comment
-
I will test it with the data of the whole month of September. Yes, I already added some print in the output window there it's working well in the replay but in live it does not start at 6:30 which is supposed to be the start time to trade. What it did is that it start at 9:30.
Comment
-
atm strategy exit and reverse
Hello Bertran I have with strategy on the exit and reverse. Normally, it will exit first the short position if there is a long signal and then entry long position. When I used EnterLong and EnterShort method the strategy works well with the exit and reverse. But when I used the atm stategy create method the strategy missed the exit and reverse. What shall I do?
Comment
-
How to close the open position first on atm strategy? AtmStrategyClose(atmstrategyId); will not work sometimes. Is there other way to close the open position. Or I want to make the market position to be flat if my condition is true. Please help me on these. Thanks.
Comment
-
It will only work when 2 bars lapse from the last entry bar. If I have a long position in the current bar then in the next bar short signal is triggered and then it should exit first the long position before submitting short order. But in my in test it does not exit or close the long position. It will only be close if the short signal is triggered in the next 2 bars from the long position.
Comment
-
else if (atmStrategyIdS.Length > 0 && orderIdS.Length == 0)
{
// It would cancel working orders and close any open strategy position by modifying the exits
// and if those would not exist, it would use a market order to achieve flat state.
// Close first open position in opposite direction
AtmStrategyClose(atmStrategyIdS); // close or exit the short position
// Submit long order
if (orderIdL.Length == 0 && atmStrategyIdL.Length == 0 && Position.MarketPosition==MarketPosition.Flat)
{
atmStrategyIdL = GetAtmStrategyUniqueId();
orderIdL = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Close[0], 0, TimeInForce.Day, orderIdL, atmstrategytemplate, atmStrategyIdL);
cancelPriceL = High[0] + (12 * TickSize);
cancelPriceS = 0;
counterS=0;
// Set to true in preparation for the second order to be taken if there is.
switcherL=true;
// Set the short switcher to false
switcherS=false;
// Add 1 to the counter each order
counterL++;
}
}Last edited by luxurious_04; 10-25-2010, 01:30 AM.
Comment
-
Also, is there other way to test a custom strategy aside from back testing in replay data. Or how we can backtest custom strategies without using Replay Data because backtest with replay will take too long and inaccurate. Is there other way to test a custom strategies that is more faster. If someone knows a better way then we will appreciate and always ready to listen. Thanks in advance..
Comment
-
Unfortunately to backtest ATM's you would need to work on replay data, as in regular backtesting those will not work - another approach would the be coding out the ATM aspects yourself with the Entry / Exit order methods.
For your ATM snippet provided, the issue is likely you would need to wait until the position info has been updated to retrigger your setup, this is not guaranteed to be the case unitl the next OnBarUpdate() event.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
650 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
577 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment