NexusFi: Find Your Edge


Home Menu

 





Time and ToTime in Ninja Trader


Discussion in NinjaTrader

Updated
    1. trending_up 2,409 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 3 attachments




 
Search this Thread
  #1 (permalink)
 
gfullmer's Avatar
 gfullmer 
Phoenix, AZ
 
Experience: Intermediate
Platform: Nijatrader, TradeStation
Broker: Interactive Brokers
Trading: Stocks, Options
Posts: 11 since Oct 2014
Thanks Given: 15
Thanks Received: 1

I am trying to code a system that is called "Filling the Gap":

Buy a stock when it opens more than 2% lower than the prior day close.
Sell at yesterday's closing price or a the close if yesterday's closing price is never hit.

Only downside to coding this is I want to Sell on the same day it is Bought. I was thinking about doing this with 5 minute bars and closing it at 3:55pm, but then I have to have the time of the Close of yesterday. I am using ToTime and Time, but not sure how to do it.

I guess I could do it daily and then close on the next day's Open.

Thanks,
Glen


Follow me on X Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NYSE Owner ICE Invests in Crypto Exchange OKX at $25 Bil …
Cryptocurrency
Orban at 29pct as Hungary Votes Tomorrow -- McIlroy Surg …
Prediction Markets & Event Contracts
April 2026 Jobs Report: +115k vs +65k Expected
Traders Hideout
Saylors 41-Month HODL Breaks: Strategy Sells 32 BTC as $ …
Prediction Markets & Event Contracts
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,114


Something like this?

What filters would you use to avoid shorting runaway gaps as shown on the chart?



Reply With Quote
Thanked by:
  #4 (permalink)
 
gfullmer's Avatar
 gfullmer 
Phoenix, AZ
 
Experience: Intermediate
Platform: Nijatrader, TradeStation
Broker: Interactive Brokers
Trading: Stocks, Options
Posts: 11 since Oct 2014
Thanks Given: 15
Thanks Received: 1

Thanks Fat Tails. Yes, that is what I was looking for. Have you back tested it? How does it look? Did you use the TIME and ToTime functions to do that or some other function?

As far as a filter, one could look at the size of the gap, but not sure if that is correlated.

Some other filters when that day before was down for the stock, or using QQQ to see if it gaped down as well, or just buying and not shorting.

Any other ideas?

Thanks,
Glen


Follow me on X Started this thread Reply With Quote
  #5 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,114


gfullmer View Post
Thanks Fat Tails. Yes, that is what I was looking for. Have you back tested it? How does it look? Did you use the TIME and ToTime functions to do that or some other function?

As far as a filter, one could look at the size of the gap, but not sure if that is correlated.

Some other filters when that day before was down for the stock, or using QQQ to see if it gaped down as well, or just buying and not shorting.

Any other ideas?

Thanks,
Glen


I do not use the ToTime function, but usually create a TimeSpan object which holds the value of the exit time. I then compare the hour and minute of the current time stamp with the TimeSpan object.


Reply With Quote
  #6 (permalink)
 
gfullmer's Avatar
 gfullmer 
Phoenix, AZ
 
Experience: Intermediate
Platform: Nijatrader, TradeStation
Broker: Interactive Brokers
Trading: Stocks, Options
Posts: 11 since Oct 2014
Thanks Given: 15
Thanks Received: 1


Fat Tails View Post
I do not use the ToTime function, but usually create a TimeSpan object which holds the value of the exit time. I then compare the hour and minute of the current time stamp with the TimeSpan object.

I had some issues with the ToTime and Time function so I found the Bars.GetDayBar(1) to get yesterday's close and also to close on today's close to be helpful for back testing. It probably wouldn't work for trading as it trades at close.

Also, I don't want to trade all day like your system does, but only daily and then only on the long side.

I have enclosed a simple example.

Thanks,
Glen


Attached Files
Elite Membership required to download: FillingTheGap.zip
Follow me on X Started this thread Reply With Quote
  #7 (permalink)
 
gfullmer's Avatar
 gfullmer 
Phoenix, AZ
 
Experience: Intermediate
Platform: Nijatrader, TradeStation
Broker: Interactive Brokers
Trading: Stocks, Options
Posts: 11 since Oct 2014
Thanks Given: 15
Thanks Received: 1

Here is an updated version to the FillTheGap strategy.


Attached Files
Elite Membership required to download: FillingTheGap2.zip
Follow me on X Started this thread Reply With Quote




Last Updated on February 8, 2015


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts