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 Quick Summary with 1 posts (0 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 4,609 views
    2. thumb_up 15 thanks given
    3. group 4 followers
    1. forum 9 posts
    2. attach_file 0 attachments




 
Search this Thread
  #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?
Iran Lebanon Problem Kills Switzerland Talks, Brent at $ …
Prediction Markets & Event Contracts
Fed Hike Odds at 57% After Warsh: England Surges 12.9%, …
Prediction Markets & Event Contracts
Datafeed for Atas
Platforms and Indicators
Trump Media to sell instant access to market-moving soci …
Traders Hideout
No book, only a stair: journaling fills where price move …
Cryptocurrency
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Want your NinjaTrader indicator created, free?
5 thanks
Afternoon-close session
1 thanks
Franks Trading Journey
1 thanks
Denied 20K payouts: Alpha Futures
1 thanks
FootPrintV2 Chart for NT8
1 thanks
  #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: 279 since Jun 2009
Thanks Given: 161
Thanks Received: 272


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: 801

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: 279 since Jun 2009
Thanks Given: 161
Thanks Received: 272


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,715 since May 2010
Thanks Given: 203
Thanks Received: 2,689

Unless I am missing something...

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


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

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


© 2026 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 - Downloads - Top
no new posts