How do I close positions 5 bars after they are opned - NinjaTrader Programming | futures io social day trading
futures io futures trading


How do I close positions 5 bars after they are opned
Updated: Views / Replies:72 / 5
Created: by xNICK Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 100,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

How do I close positions 5 bars after they are opned

  #1 (permalink)
Trading Apprentice
chattanooga
 
Trading Experience: Beginner
Platform: ThinkorSwim
 
Posts: 5 since Dec 2018
Thanks: 0 given, 0 received

How do I close positions 5 bars after they are opned

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!

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Evans GA/USA
 
Trading Experience: Intermediate
Platform: NinjaTrader
Broker/Data: NinjaTrader Brokerage - Philip Capital
Favorite Futures: NQ,ES,6E,CL
 
TradingOgre's Avatar
 
Posts: 528 since Jul 2018
Thanks: 874 given, 1,504 received



xNICK View Post
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!

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().


Quoting 
BarsSinceEntryExecution()

Previous page Return to chapter overview Next page
Definition
Returns the number of bars that have elapsed since the last specified entry.


Method Return Value
An int value that represents a number of bars. A value of -1 will be returned if a previous entry does not exist.



Syntax
BarsSinceEntryExecution()
BarsSinceEntryExecution(string signalName)



The following method signature should be used when working with multi-time frame and instrument strategies:



BarsSinceEntryExecution(int barsInProgressIndex, string signalName, int entryExecutionsAgo)



Note: When working with a multi-series strategy the BarsSinceEntryExecution() will return you the elapsed bars as determined by the first Bars object for the instrument specified by the barsInProgressIndex.





Parameters
signalName

The signal name of an entry order specified in an order entry method.

barsInProgressIndex

The index of the Bars object the entry order was submitted against.



Note: See the BarsInProgress property.

entryExecutionsAgo

Number of entry executions ago. Pass in 0 for the number of bars since the last entry execution.





Examples
ns

protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;

// Only enter if at least 10 bars has passed since our last entry
if ((BarsSinceEntryExecution() > 10 || BarsSinceEntryExecution() == -1) && CrossAbove(SMA(10), SMA(20), 1))
EnterLong();

}


Reply With Quote
 
  #4 (permalink)
Trading Apprentice
chattanooga
 
Trading Experience: Beginner
Platform: ThinkorSwim
 
Posts: 5 since Dec 2018
Thanks: 0 given, 0 received

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

Reply With Quote
 
  #5 (permalink)
Elite Member
Evans GA/USA
 
Trading Experience: Intermediate
Platform: NinjaTrader
Broker/Data: NinjaTrader Brokerage - Philip Capital
Favorite Futures: NQ,ES,6E,CL
 
TradingOgre's Avatar
 
Posts: 528 since Jul 2018
Thanks: 874 given, 1,504 received

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.

Reply With Quote
 
  #6 (permalink)
Trading Apprentice
chattanooga
 
Trading Experience: Beginner
Platform: ThinkorSwim
 
Posts: 5 since Dec 2018
Thanks: 0 given, 0 received

Thank you for that idea Ill go see what I can do with that!
Thank you for your time and help!

Reply With Quote

Reply



futures io > > > > > How do I close positions 5 bars after they are opned

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

Battlestations! Show us your trading desks w/GFF Brokers ($750 in Prizes)

January
 

Surviving the coming Bear Market w/Adam Grimes

Elite only
 

Trading Preparedness w/GFF Brokers

Jan 22
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically close out all positions when condition is reached hdsouza ThinkOrSwim Programming 2 January 28th, 2016 08:51 PM
Only Close Open Positions? davetapson AmiBroker 0 September 23rd, 2014 04:59 AM
How to make program close all positions by 4:15PM EST? honoluluhustler EasyLanguage Programming 4 July 7th, 2014 04:08 PM
Hedging currency risk in short stock positions (any different from long positions?) ikeaboy Currency Futures 9 May 15th, 2014 05:00 PM
Cutting The Deficit: They Wonít Because They Donít Have To Quick Summary News and Current Events 0 November 22nd, 2011 07:10 PM


Tags
bars object, code, crossabove, es, how to, multi-time frame, ninjascript, ninjatrader, ninjatrader 8, nt8, order entry, parabolicsar, signal, sma, strategies, strategy, switching, t3, thinkorswim

All times are GMT -4. The time now is 11:30 PM. (this page content is cached, log in for real-time version)

Copyright © 2019 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432 WhatsApp Business, info@futures.io
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.
no new posts
Page generated 2019-01-17 in 0.14 seconds with 13 queries on phoenix