NexusFi: Find Your Edge


Home Menu

 





Encoding a Hold signal for "X" bars?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one fredesch with 3 posts (2 thanks)
    2. looks_two Fat Tails with 2 posts (4 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 Big Mike with 1 posts (0 thanks)
    1. trending_up 2,888 views
    2. thumb_up 6 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread

Encoding a Hold signal for "X" bars?

  #1 (permalink)
 fredesch 
San Diego, CA
 
Experience: Intermediate
Platform: NinjaTrader, Tradestation
Broker: Mirus/ZenFire
Trading: EUR/USD
Posts: 4 since Apr 2010
Thanks Given: 1
Thanks Received: 1

Can anyone provide guidance as how to encode a "hold" signal for "x" number of bars in ninjascript? What I am seeking would resemble the following which was obtained from another language:

SYNTAX hold( EXPRESSION, periods )
FUNCTION Holds a "true" result of EXPRESSION for the specified number of periods.
This true result is held true over the number of periods specified even if a "false" result is generated.
EXAMPLE hold( cross(rsi(14),70),5 )

Thank you in advance for any help you can provide.
With kind regards,

Fred

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
What broker to use for trading palladium futures
Commodities
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103



fredesch View Post
Can anyone provide guidance as how to encode a "hold" signal for "x" number of bars in ninjascript? What I am seeking would resemble the following which was obtained from another language:

SYNTAX hold( EXPRESSION, periods )
FUNCTION Holds a "true" result of EXPRESSION for the specified number of periods.
This true result is held true over the number of periods specified even if a "false" result is generated.
EXAMPLE hold( cross(rsi(14),70),5 )

Thank you in advance for any help you can provide.
With kind regards,

Fred

I would define a BoolSeries object, which will hold the value "true" or "false" for each bar. You can then use an integer index, set it to 5 periods, count it down to zero and set the value to "true" if the index still is greater than 0.

However, it is not clear what you actually try to achieve.

Reply With Quote
  #4 (permalink)
 fredesch 
San Diego, CA
 
Experience: Intermediate
Platform: NinjaTrader, Tradestation
Broker: Mirus/ZenFire
Trading: EUR/USD
Posts: 4 since Apr 2010
Thanks Given: 1
Thanks Received: 1

Thanks, Fat Tails. Much appreciated. What I am trying to do is:
1. Define an entry setup that I believe should be valid for "x" bars even if all conditions defining that setup don't hold true for all "x" bars. For example, a Long entry setup could be a very oversold situation, eg, RSI(2) < 3.
2. Use price movement beyond the extreme of the last bar in the desired trade direction to confirm and trigger a Long trade entry. For example, using the above oversold case: H[0] > H[1] could be the Long entry trigger.

I hope that makes sense.

I have some limited programming experience with Amibroker but none really with Ninjascript, so I am currently using the Strategy Wizard to cobble together a strategy. If you wouldn't mind, would you be so kind as to provide a simple example of the code you proposed. I'm very new at this and would regard it as an excellent learning opportunity.

Many thanks,

Fred

Started this thread Reply With Quote
  #5 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103

The easiest think would be, if you just edit a sample strategy. You could for example edit the SampleMACrossOver and save it under a new name.

You can then change the conditions within this strategy. If you have coded indicators or strategies with AmiBroker that should not be much of a problem. For example, you can use the RSI instead of the SMA. Note that the RSI has two parameters, the period of the RSI and the smoothing period, so the syntax will be RSI(period,smooth), as opposed to the SMA(period).

Now let us assume that you have a setup signal

1st condition: RSI(2) < 30

and that you want to hold this signal for 5 bars, and that you have an entry condition

2nd condition High[0] > High[1]

This means that you would have to check, whether the second condition is true and whether the first condition was true for the current or one of the prior four bars

A simple solution:

 
Code
if ((RSI(2)[0]< 30 || RSI(2)[1]< 30 || RSI(2)[2]< 30 || RSI(2)[3]< 30 || RSI(2)[4]< 30) && 
High[0]>High[1])
EnterLong();
Admittedly not very elegant, but should work nevertheless. Alternatively you could code

 
Code
if(High[0]>High[1])
{
	for (int i=0; i<5; i++)
		if(RSI(2)[i]<30)
		{
			EnterLong();
			break;
		}
}

Reply With Quote
  #6 (permalink)
 fredesch 
San Diego, CA
 
Experience: Intermediate
Platform: NinjaTrader, Tradestation
Broker: Mirus/ZenFire
Trading: EUR/USD
Posts: 4 since Apr 2010
Thanks Given: 1
Thanks Received: 1

Dear Fat Tails,
With your kind assistance I was able to successfully deploy your second suggestion. Thank you very much for your generous efforts. FWIW, I've ordered a book on C# programming!

With kind regards,

Fred

Started this thread Reply With Quote
Thanked by:
  #7 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,469 since Jun 2009
Thanks Given: 33,246
Thanks Received: 101,669

Be kind, use the thanks button





Mike



Join the free Markets Chat beta: one platform, all the trade rooms!

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on May 12, 2011


© 2024 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 - Privacy Policy - Downloads - Top
no new posts