[newb] question on mult entries in direction of trend - NinjaTrader Programming | futures io social day trading
futures io futures trading


[newb] question on mult entries in direction of trend
Updated: Views / Replies:586 / 5
Created: by jordis 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 90,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
 

[newb] question on mult entries in direction of trend

  #1 (permalink)
Elite Member
Mobile, Alabama
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
Favorite Futures: Stocks
 
Posts: 29 since Sep 2011
Thanks: 6 given, 4 received

[newb] question on mult entries in direction of trend

I haven't really posted on here before, but I've been lurking for a while. I am not new to trading, but I'm a complete beginner when it comes to programming and backtesting. I have a question that should be pretty basic (I hope) for those of you who program in NT regularly. I've tried to search for similar questions on the forum, but I haven't had any luck; so I apologize if something like this has been answered before.

Disclaimer: This is not part of a strategy, it's more of a conceptual question about programming. I understand that this concept would produce horrific results!

Question: How would I go about programming a strategy that (after identifying a trend, in some way or another) would simply enter a new trade in the direction of the trend on the open of every bar, and close these trades at a fixed interval, one after the other?
For example, say I choose to trade long whenever the closing price of a bar is above the 10EMA. So for every bar that opens after the previous bar closes above the 10EMA I want to enter a new long position, hold it for exactly 10 bars, and then sell. This would continue until the price dipped below the 10EMA. So, if the trend lasted for more than 10 bars total then the strategy would enter long trades only until the 11th bar where it would then both open a new long trade as well as close out the initial long trade (and so on).
The concept of how to program this is what is eluding me at the moment. Whenever I try to code this using the strategy builder I end up doing one of 2 things. First, I was getting the consecutive trades to open, but they would all close on the same bar (when my counter is hit from the FIRST entry, not each individual entry). Second, I tried the following code, but no new entry would be opened until the initial entry had been closed (after the 10 bars).

protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(Close, EMA(10), 1))
{
EnterLong(DefaultQuantity, "long");
}

// Condition set 2
if (Close[0] > EMA(10)[0])
{
EnterLong(DefaultQuantity, "long");
}

// Condition set 3
if (BarsSinceEntry() == 10)
{
ExitLong("close", "long");
}
}



So, I realize this is probably basic for most of you, but could someone help explain to me how to code this so I end up with the desired result?

Thanks for any help,
Jordis

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
Northern Germany
 
Futures Experience: Intermediate
Platform: NT
Favorite Futures: FDAX, CL
 
vvhg's Avatar
 
Posts: 1,583 since Mar 2011
Thanks: 1,016 given, 2,807 received



jordis View Post
I haven't really posted on here before, but I've been lurking for a while. I am not new to trading, but I'm a complete beginner when it comes to programming and backtesting. I have a question that should be pretty basic (I hope) for those of you who program in NT regularly. I've tried to search for similar questions on the forum, but I haven't had any luck; so I apologize if something like this has been answered before.

Disclaimer: This is not part of a strategy, it's more of a conceptual question about programming. I understand that this concept would produce horrific results!

Question: How would I go about programming a strategy that (after identifying a trend, in some way or another) would simply enter a new trade in the direction of the trend on the open of every bar, and close these trades at a fixed interval, one after the other?
For example, say I choose to trade long whenever the closing price of a bar is above the 10EMA. So for every bar that opens after the previous bar closes above the 10EMA I want to enter a new long position, hold it for exactly 10 bars, and then sell. This would continue until the price dipped below the 10EMA. So, if the trend lasted for more than 10 bars total then the strategy would enter long trades only until the 11th bar where it would then both open a new long trade as well as close out the initial long trade (and so on).
The concept of how to program this is what is eluding me at the moment. Whenever I try to code this using the strategy builder I end up doing one of 2 things. First, I was getting the consecutive trades to open, but they would all close on the same bar (when my counter is hit from the FIRST entry, not each individual entry). Second, I tried the following code, but no new entry would be opened until the initial entry had been closed (after the 10 bars).

protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(Close, EMA(10), 1))
{
EnterLong(DefaultQuantity, "long");
}

// Condition set 2
if (Close[0] > EMA(10)[0])
{
EnterLong(DefaultQuantity, "long");
}

// Condition set 3
if (BarsSinceEntry() == 10)
{
ExitLong("close", "long");
}
}



So, I realize this is probably basic for most of you, but could someone help explain to me how to code this so I end up with the desired result?

Thanks for any help,
Jordis

1. Condition 1 is entering a trade on the cross over, when you run the strategy with CalculateOnBarClose = true this is not needed. If set to false condition 2 would have to be changed as it would fire on every tick.

2. Condition 2 only can fire when there is no position with the signal name "long" you could instead use "long"+Time[0] to generate a unique signal name.

That way you could also access that 10 bars later as it will then be "long"+Time[10]

hope that helps...

Vvhg

P.s. The wizard is pretty useless, but the documentation in the help file is excellent. It alsohelps a lot to read some code others wrote...

Hic Rhodos, hic salta.
Reply With Quote
The following user says Thank You to vvhg for this post:
 
  #4 (permalink)
Elite Member
Mobile, Alabama
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
Favorite Futures: Stocks
 
Posts: 29 since Sep 2011
Thanks: 6 given, 4 received


vvhg View Post
1. Condition 1 is entering a trade on the cross over, when you run the strategy with CalculateOnBarClose = true this is not needed. If set to false condition 2 would have to be changed as it would fire on every tick.

2. Condition 2 only can fire when there is no position with the signal name "long" you could instead use "long"+Time[0] to generate a unique signal name.

That way you could also access that 10 bars later as it will then be "long"+Time[10]

hope that helps...

Vvhg

P.s. The wizard is pretty useless, but the documentation in the help file is excellent. It alsohelps a lot to read some code others wrote...

thanks for the response. I really appreciate the help!

Reply With Quote
 
  #5 (permalink)
Elite Member
Mobile, Alabama
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
Favorite Futures: Stocks
 
Posts: 29 since Sep 2011
Thanks: 6 given, 4 received

Ok, now I've got a new problem!

So I tried working on the code from above to track and sell a position after a set number of minutes.

First, I tried just writing the code to perform the action to the short side, using the below code:

 
Code
 protected override void OnBarUpdate()
        {
			
			{
				ExitShort("c", "short"+Time[14]);
			}
            if (EMA(1)[0] > EMA(10)[0])
            {
                EnterShort(DefaultQuantity, "short"+Time[0]);   
		    }
The results seem to be pretty much what I was trying accomplish, with most positions closing after 15 bars, and the ones that close earlier have Exit Names that are labeled as "Exit on Close" in the backtesting "trades" tab. I can only assume that this means that these trades were closed due to the end of the trading period (end of day maybe?) when my 15 bar limit could not be reached (I should note that I am running this on free downloaded FOREX data, so it's 24hr data in 1 minute bars).

So, after being satisfied for the moment with this result, I tried to add in the long side trades, and that's where I lost it. I tried the following code, hoping for the same result as above, just with long side trades included, but what I got wasn't even really close.

 
Code
 protected override void OnBarUpdate()
        {
			
			{
				ExitShort("c", "short"+Time[14]);
				ExitLong("c2", "long"+Time[14]);
			}
            if (EMA(1)[0] > EMA(10)[0])
            {
                EnterShort(DefaultQuantity, "short"+Time[0]);   
		    }
			else  if (EMA(1)[0] < EMA(10)[0])
            {
                EnterLong(DefaultQuantity, "long"+Time[0]);   
		    }

In the "trades" tab I am seeing a ton of trades with the Exit Name labeled as "Close Position" that are occurring at all hours of the day (ie. no apparent pattern for end of day or anything). The attempted addition of the long side trades even messed up my short side trades that had been successful in the first block of code. Now there are large blocks of trades all closing on (seemingly) random bars all at once.


So, my question is this: what the heck am I missing here? I'm guessing there's something glaringly obvious in my code that explains why I am not achieving what I think I should.


Thanks again for the help. I'm just trying to use trial and error to learn some basic coding, but I'm confusing myself a lot of times and don't know where to turn next!

Reply With Quote
 
  #6 (permalink)
Elite Member
Northern Germany
 
Futures Experience: Intermediate
Platform: NT
Favorite Futures: FDAX, CL
 
vvhg's Avatar
 
Posts: 1,583 since Mar 2011
Thanks: 1,016 given, 2,807 received


jordis View Post
Ok, now I've got a new problem!

So I tried working on the code from above to track and sell a position after a set number of minutes.

First, I tried just writing the code to perform the action to the short side, using the below code:

 
Code
 protected override void OnBarUpdate()
        {
			
			{
				ExitShort("c", "short"+Time[14]);
			}
            if (EMA(1)[0] > EMA(10)[0])
            {
                EnterShort(DefaultQuantity, "short"+Time[0]);   
		    }
The results seem to be pretty much what I was trying accomplish, with most positions closing after 15 bars, and the ones that close earlier have Exit Names that are labeled as "Exit on Close" in the backtesting "trades" tab. I can only assume that this means that these trades were closed due to the end of the trading period (end of day maybe?) when my 15 bar limit could not be reached (I should note that I am running this on free downloaded FOREX data, so it's 24hr data in 1 minute bars).

So, after being satisfied for the moment with this result, I tried to add in the long side trades, and that's where I lost it. I tried the following code, hoping for the same result as above, just with long side trades included, but what I got wasn't even really close.

 
Code
 protected override void OnBarUpdate()
        {
			
			{
				ExitShort("c", "short"+Time[14]);
				ExitLong("c2", "long"+Time[14]);
			}
            if (EMA(1)[0] > EMA(10)[0])
            {
                EnterShort(DefaultQuantity, "short"+Time[0]);   
		    }
			else  if (EMA(1)[0] < EMA(10)[0])
            {
                EnterLong(DefaultQuantity, "long"+Time[0]);   
		    }

In the "trades" tab I am seeing a ton of trades with the Exit Name labeled as "Close Position" that are occurring at all hours of the day (ie. no apparent pattern for end of day or anything). The attempted addition of the long side trades even messed up my short side trades that had been successful in the first block of code. Now there are large blocks of trades all closing on (seemingly) random bars all at once.


So, my question is this: what the heck am I missing here? I'm guessing there's something glaringly obvious in my code that explains why I am not achieving what I think I should.


Thanks again for the help. I'm just trying to use trial and error to learn some basic coding, but I'm confusing myself a lot of times and don't know where to turn next!


When you hold a short position and do EnterLong() NT will first close all short positions and then enter the long. So what you want to do is to exit a short when you have short positions open. So first you check MarketPosition and when its short you do ExitShort() and else you use EnterLong().

Vvhg

Hic Rhodos, hic salta.
Reply With Quote

Reply



futures io > > > > > [newb] question on mult entries in direction of trend

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
The Direction of the Compromise kbit News and Current Events 0 September 15th, 2012 05:50 PM
New and looking for direction. wrenchmaster Beginners and Introductions 3 August 23rd, 2012 10:32 PM
Newb needs help with Kinetick options? pricestudent Reviews of Brokers and Data Feeds 4 August 16th, 2012 11:10 AM
need some help to point me in the right direction kaywai NinjaTrader Programming 2 February 9th, 2011 03:18 PM
Pivots for newb using NT 6.5 tammyd549 NinjaTrader 5 September 14th, 2010 08:55 PM


All times are GMT -4. The time now is 02:35 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, 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 2017-12-14 in 0.13 seconds with 19 queries on phoenix via your IP 54.221.76.68