NexusFi: Find Your Edge


Home Menu

 





Need little help with a Ninjatrader script


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one bukkan with 3 posts (6 thanks)
    2. looks_two max-td with 2 posts (2 thanks)
    3. looks_3 raindrop with 2 posts (0 thanks)
    4. looks_4 MXASJ with 1 posts (5 thanks)
      Best Posters
    1. looks_one MXASJ with 5 thanks per post
    2. looks_two bukkan with 2 thanks per post
    3. looks_3 NinjaTrader with 2 thanks per post
    4. looks_4 max-td with 1 thanks per post
    1. trending_up 3,732 views
    2. thumb_up 15 thanks given
    3. group 4 followers
    1. forum 9 posts
    2. attach_file 0 attachments




 
Search this Thread

Need little help with a Ninjatrader script

  #1 (permalink)
 raindrop 
USA
 
Experience: Beginner
Platform: NinjaTrader 6.5
Posts: 18 since Mar 2010
Thanks Given: 13
Thanks Received: 1

Hi All,
I need to code few simple lines but not sure how to do it. I'd appreciate any help.

1) RSI(14) has been above 80 anytime within last 12 bars.

2) And price is at least 20 pips above the SMA(25)

Thanks.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Cheap historycal L1 data for stocks
Stocks and ETFs
What broker to use for trading palladium futures
Commodities
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
 
  #3 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927


hi raindrop,

i think a little more explaination of what you like to have is needed for helpers.
do you work on an indicator or strategy ?
do you want to plot anything ?
do you only want to have the conditions to be written in code ?

thanks
max

max-td
Reply With Quote
  #4 (permalink)
 bukkan 
Calcutta, India
 
Experience: Intermediate
Platform: ArthaChitra
Posts: 278 since Jun 2009
Thanks Given: 161
Thanks Received: 271


raindrop View Post
Hi All,
I need to code few simple lines but not sure how to do it. I'd appreciate any help.

1) RSI(14) has been above 80 anytime within last 12 bars.

2) And price is at least 20 pips above the SMA(25)

Thanks.

dont know if this is the most elegant way to do, but you can try something like below

put the code in OnBarUpdate
 
Code
bool istrue = false;
            
 for (int i = 0;i<= 11; i++)
 {
           if (RSI(Close,14,3)[i] > 80)
          {
                    istrue = true;
                    break;
           }
 }

if (istrue && Close[0] - TickSize * 20 > SMA(25)[0])
{
   //do your stuff

}

Reply With Quote
  #5 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

You can also look at MostRecentOccurance()/LeastRecentOccurance() for the RSI part of the logic.

Reply With Quote
  #6 (permalink)
 bukkan 
Calcutta, India
 
Experience: Intermediate
Platform: ArthaChitra
Posts: 278 since Jun 2009
Thanks Given: 161
Thanks Received: 271


MXASJ View Post
You can also look at MostRecentOccurance()/LeastRecentOccurance() for the RSI part of the logic.

thanks MXASJ, thats the way to go.

Reply With Quote
Thanked by:
  #7 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927

what you guys think about the count If - code for the RSI - check ?

// If in the last 10 bars we have had 8 up bars then go long

if ( CountIf(delegate {return Close[0] > Open[0];}, 10) > 8)

.... do things

max-td
Reply With Quote
Thanked by:
  #8 (permalink)
 
NinjaTrader's Avatar
 NinjaTrader  NinjaTrader is an official Site Sponsor
Site Sponsor

Web: NinjaTrader
AMA: Ask Me Anything
Webinars: NinjaTrader Webinars
Elite offer: Click here
 
Posts: 1,714 since May 2010
Thanks Given: 203
Thanks Received: 2,686

Unless I am missing something...

if (MAX(RSI(14), 12)[0] > 80 && Close[0] > SMA(25)[0] + 20 * TickSize)
// Do something

Follow me on Twitter Reply With Quote
Thanked by:
  #9 (permalink)
 bukkan 
Calcutta, India
 
Experience: Intermediate
Platform: ArthaChitra
Posts: 278 since Jun 2009
Thanks Given: 161
Thanks Received: 271

boy o boy now whos the fairest of all

my code (post 4) and the one posted by Ray using the MAX function are essentially the same. my code breaks from the loop once the condition is fulfilled (i.e. RSI > 80) while MAX loops to the end and find the highest value. So that way max is doing some extra loop which is redundant in our case.

what is the code behind MRO as MXASJ pointed out?

Reply With Quote
  #10 (permalink)
 raindrop 
USA
 
Experience: Beginner
Platform: NinjaTrader 6.5
Posts: 18 since Mar 2010
Thanks Given: 13
Thanks Received: 1


I came back to see if there is any response to my question and was amazed to see the level of help here. I really appreciate everyone trying to help me here.

I am trying to write a trend trading strategy script so that's why I want to look back few periods. I do not have to plot the RSI on the chart but it would be a plus if I could. I can write simple scripts on Stockfetcher but that is the limit of my coding abilities
.

Now while testing my strategy I have noticed that price is more likely to whipsaw when it is very close to lets say SMA(25) and I want the strategy to only generate a signal if price is at least 25 pips away (above or below depending upon the direction of the trade) from SMA(25). What would you experts think such a script look like?


Again I appreciate all the help extended to me in this thread.


Raindrop.

Started this thread Reply With Quote




Last Updated on April 20, 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