Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 04-05-2017, 10:23 AM   #1
Hanko
Junior Member
 
Join Date: Dec 2009
Posts: 12
Thanks: 1
Thanked 0 times in 0 posts
Default First change of direction

Hi,

I want to write a strategy and need some input how to begin because I'm not the best code writer.

The strategy is something like:
Enter short if RSI (or any other indicator) crosses below a certain level, let's say 50 and the MACD for example changes direction above its zero line for the first time from rising to falling.
I know how to implement all the codes beside the MACD changing direction (first MACD high above its zero line).
Is there someone, who can give me a hint how to start? Or does anybody know a link to a similar case. I didn't find anything in my search.
Thanks!
Hanko is offline  
Reply With Quote
Old 04-05-2017, 10:37 AM   #2
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,790
Thanks: 30
Thanked 1,217 times in 1,138 posts
Default

Hello Hanko,

Thank you for the post.

I wanted to first ask, are you trying to accomplish this using the strategy wizard or manually coding? I noted that you said you know how to implement these items but I wanted to be sure on which method you were actually using.

If you are manually coding, you could use a bool variable as one solution.

For example, you could check if the MACD is Rising or Falling and set variables to true or false depending on which direction the price is going.
Later you could compare the current Rising or Falling values against the bool variables, depending on the value that the variable currently has you could check if the current Rising or Falling is now different than the stored value and if so complete an action.
You may need to use further logic to reset these variables later or after a trade as an example.

The wizard would be slightly more complicated but would be generally the same process. Setting a user variable when the condition is true, and resetting it later as needed.

I look forward to being of further assistance.
NinjaTrader_Jesse is online now  
Reply With Quote
Old 06-13-2018, 11:30 AM   #3
stafe
Member
 
Join Date: Nov 2011
Posts: 92
Thanks: 8
Thanked 4 times in 4 posts
Default

this is what i'm trying to do in strategy builder....
i'ld like a signal to print and a sound when two indicators both change directions from both going down to both going up but i'm stuck on rising falling because i can't enter bars ago anywhere ??


i.e.:
ema13 and ema34 are going down i'ld like to run a strategy that plays a sound when they both turn up... and visa versa...


thanks,
w
stafe is offline  
Reply With Quote
Old 06-13-2018, 03:31 PM   #4
stafe
Member
 
Join Date: Nov 2011
Posts: 92
Thanks: 8
Thanked 4 times in 4 posts
Default

i decided to code this as an indicator but i've run into a problem using IsFalling IsRising:


i'm trying to check several bars back for the falling condition then check the current bar for the rising condition and i thought mistakenly that i could just force bars ago into the mix...


if ( IsFalling(emaFast[2]) && IsFalling(emaFast[1]) && IsRising(emaFast[0]) )


but i get an invalid argument error...
is there a quick way to do this ?


thanks,
w
stafe is offline  
Reply With Quote
Old 06-14-2018, 07:46 AM   #5
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,790
Thanks: 30
Thanked 1,217 times in 1,138 posts
Default

Hello stafe,

Thank you for the post.

The reason for the error is that Falling takes an IDataSeries and you are giving it a double. Also I see you are using IsFalling as your syntax, is this an NT7 or NT8 question? NT7 uses Falling, NT8 uses IsFalling

You would likely need to make a BoolSeries to store the previous Falling or Rising values if you need to check a prior bars Falling or Rising.

Rising and Falling simply checks "now" while the bars are processing. If you wanted to refer back to a prior bar that has been processed, you would need to have stored the value at the time the bar was processed.

After creating a BoolSeries you could set the value of the series on each bar to the Rising or Falling value. Then you can use the series to look back at a previously evaluated bar and see if it was rising or falling.

https://ninjatrader.com/support/help...sub=boolseries

I look forward to being of further assistance.
NinjaTrader_Jesse is online now  
Reply With Quote
Old 06-14-2018, 09:24 AM   #6
stafe
Member
 
Join Date: Nov 2011
Posts: 92
Thanks: 8
Thanked 4 times in 4 posts
Default

thanks Jesse, it is NT8 - but i didn't find any questions like this one in the NT8 section...
i'm just trying to make a strat that detects when both averages are going up after having been going the other direction -- i hacked one out using the strat builder like EMA[3] > EMA[2] && EMA[2] > EMA[1] && EMA[0] > EMA[1] for the long term EMA and EMA[2] < EMA[1] && EMA[1] < EMA[0]


but that seems really clunky....


do you have any previous examples of code or strats that detect two indicators both having changed directions or say the longer term indi having just changed to the same direction the short term one was going ?


i was actually trying to make an indicator that would do this instead of a strategy so i can see my trade locations but i can't get the signals to fire for some reason... should we change over to the NT8 forum and i can share my coding attempt ?



thx
Last edited by stafe; 06-14-2018 at 09:27 AM.
stafe is offline  
Reply With Quote
Old 06-14-2018, 09:35 AM   #7
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,790
Thanks: 30
Thanked 1,217 times in 1,138 posts
Default

Hello stafe,

Thank you for the reply.

I went ahead and moved this to the NT8 forum, in the future please ensure to either post in the NT8 forum for NT8 questions or mark the question as NT8 so that we can provide the most relevant help/syntax.

The way you have created this with the builder is fine it is just a larger condition because of what is required. This is actually basically the same as what I had suggested with the series, you are just skipping the IsFalling so a series wouldn't be needed to access prior values.

For what you are trying I am not sure there is a more elegant way to do this as you need to check the prior values for what you are trying to do.

If you would like to upload what you tried that didn't work, I could take a look and see if I can note anything that might help.


I look forward to being of further assistance.
NinjaTrader_Jesse is online now  
Reply With Quote
Old 06-14-2018, 11:18 AM   #8
stafe
Member
 
Join Date: Nov 2011
Posts: 92
Thanks: 8
Thanked 4 times in 4 posts
Default

i ran across a post where someone gave some code using a bool series to do the same thing but i don't keep browsing history and i can't find it now....
i'm not very versed in using a series to store indicator direction attributes...
stafe is offline  
Reply With Quote
Old 06-14-2018, 03:31 PM   #9
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,790
Thanks: 30
Thanked 1,217 times in 1,138 posts
Default

Hello stafe,

Thank you for the reply.

We have a sample of creating a bool series, I will provide that below. If you dont want to use a series, that would be the same as using a bool series it just true or false instead of a price value.

I think the easiest way is going to be what you had shown or just using the prices, that is using the least syntax so far.

https://ninjatrader.com/support/help...us/seriest.htm

bool would replace T or double shown in the examples, T is a C# generic replaceable type that can be substituted with bool or double as an example.

I look forward to being of further assistance.
NinjaTrader_Jesse is online now  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Entries per direction ShruggedAtlas Strategy Development 4 06-19-2015 09:12 AM
change scroll wheel direction? madLyfe Platform Technical Support 2 05-06-2011 02:33 PM
Macd Diff Change Direction kenb2004 Strategy Development 15 09-21-2010 01:35 PM
MA direction change counter JamesF Indicator Development 15 06-11-2009 03:50 PM
One Trade per Direction 123r34 Platform Technical Support 3 02-15-2009 01:43 PM


All times are GMT -6. The time now is 07:22 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.