Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
How do I close positions 5 bars after they are opned
How do I close positions 5 bars after they are opned
xNICK
chattanooga
Posts: 10 since Dec 2018
Thanks Given: 0
Thanks Received: 0
Hey, I'm currently switching over from thinkorswim to ninjatrader 8 and I need to know the code I need to add to ninjascript or how I add it to the strategy builder. But I would like to close all short positions 5 bars after the position was opened. (or 5 mins or would be even better If I could close the position on the next 5 min increment, so if short position was opened at 10:22 it will close at 10:25)
Here is the current code
// Set 1
if (CrossAbove(ParabolicSAR1, Close, 1))
{
EnterShort(Convert.ToInt32(DefaultQuantity), "");
}
// Set 2
if (CrossAbove(ParabolicSAR1, Close, 1))
{
ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
}
Also what does the 1 mean after the para crossabove the close?
Thank you so much for your time and help!
Can you help answer these questions from other members on NexusFi?
The 1 refers to when you want the cross to occur in number of previous bars.
There is a command in NT8 (not sure about 7) called BarsSinceEntryExecution().
xNICK
chattanooga
Posts: 10 since Dec 2018
Thanks Given: 0
Thanks Received: 0
Thanks for that quote and telling me what that 1 meant! This is code for me that closes my last position 5 bars later.
// Set 1
if (CrossAbove(ParabolicSAR1, Close, 1))
{
EnterShort(Convert.ToInt32(DefaultQuantity), "");
}
// Set 2
if (BarsSinceEntryExecution()==5)
{
ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
}
which will work, still trying to learn how to close it on 5 minute increments though
TradingOgre
Evans GA/USA
Legendary Market Wizard
Experience: Intermediate
Platform: NinjaTrader
Broker: NinjaTrader Brokerage - Philip Capital
Trading: NQ,ES,6E,CL
Posts: 556 since Jul 2018
Thanks Given: 908
Thanks Received: 1,672
You could store the time when you send the entry order, then compare it to the current time. If it is > 5 minutes then exit.
xNICK
chattanooga
Posts: 10 since Dec 2018
Thanks Given: 0
Thanks Received: 0
Thank you for that idea Ill go see what I can do with that!
Thank you for your time and help!