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,
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.
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 > H 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.
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 > High
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:
Admittedly not very elegant, but should work nevertheless. Alternatively you could code
The following 3 users say Thank You to Fat Tails for this post:
Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.
Need help? 1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first. 2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses. 3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make. 4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance. 5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers. 6) Help using the forum? Watch this video to learn general tips on using the site.
If you want to support our community, become an Elite Member.