NexusFi: Find Your Edge


Home Menu

 





NinjaScript Assistance: When a slope goes flat


Discussion in NinjaTrader

Updated
    1. trending_up 1,954 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
 ajk1 
London - England
 
Experience: Intermediate
Platform: NT, TW
Trading: Futures & Options
Posts: 35 since Dec 2016
Thanks Given: 60
Thanks Received: 12

Hi all,

I am reasonably new to C# but making progress with learning it on NT8.
I am having a issue with defining a condition and hoping someone could point me in the right direction.

Lets say I have a oscillator (RSI for instance) that can move between 100 and -100.


- I'd like to colour it green when it moves beyond 70..... and stay green while it stays above 0.
- Once below zero, it becomes grey.
- I'd like to colour it red when it moves below -70.... and stay red while it stays below 0.

In the OnBarUpdate() method...

- If I say: If(RSI[0] > 70) >>> thats only makes values ABOVE 70 green, and when we have a value of 65, that condition is not longer true (so doesnt satisfy the "stay green while it stays above 0" bit).

- If I say: If(CrossAbove(RSI)...) >>> that only colours that 1 value, and the condition is no longer true on the next bar, so that doesn't work either.

- If I says: If(CrossAbove(RSI)...) >>>
While(RSI>0) >>> that doesn't work either because the CrossAbove condition only satisfies the cross over bar.

Any insight into how one would translate this into a C# structure would be great.
I've attached a screenshot to better illustrate my goal.


Attached Thumbnails
Click image for larger version

Name:	TEST1.png
Views:	229
Size:	12.8 KB
ID:	234909  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MegaETH Proves the Crowd Right: Prediction Markets Calle …
Prediction Markets & Event Contracts
Memorandum Watch: How the 60-Day MOU Framework Makes May …
Prediction Markets & Event Contracts
New Section 301 Probes Target 16 Trading Partners -- Tra …
Traders Hideout
Wood Mackenzie Drops $200 Oil Forecast -- Airspace Expir …
Prediction Markets & Event Contracts
CFTC Launches Innovation Task Force for AI Trading Syste …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 SpeculatorSeth   is a Vendor
 
Posts: 781 since Apr 2016
Thanks Given: 22
Thanks Received: 1,026


What you need is a boolean to track which state you are in. If you last crossed the top/bottom line or not. Something maybe like this:


 
Code
If(!hasCrossedTopLine && RSI[0] > 70)
{
    hasCrossedTopLine = true;
    //change line color
}

if(hasCrossedTopLine && RSI[0] > 0)
{
    hasCrossedTopLine = false;
    //change line color
}


Reply With Quote
Thanked by:
  #4 (permalink)
 ajk1 
London - England
 
Experience: Intermediate
Platform: NT, TW
Trading: Futures & Options
Posts: 35 since Dec 2016
Thanks Given: 60
Thanks Received: 12

Thanks TWDsje,

Am I correct in saying that hasCrossedTopLine is the boolean variable right ?
So I'll need to declare this variable along with the other variables

 
Code
bool hasCrossedTopLine = true;


Started this thread Reply With Quote
  #5 (permalink)
 SpeculatorSeth   is a Vendor
 
Posts: 781 since Apr 2016
Thanks Given: 22
Thanks Received: 1,026


ajk1 View Post
Thanks TWDsje,

Am I correct in saying that hasCrossedTopLine is the boolean variable right ?
So I'll need to declare this variable along with the other variables

 
Code
bool hasCrossedTopLine = true;

Yeah exactly. At some point you may find yourself in a situation where you have multiple booleans, and it can be hard to sort out what your if statement and so forth should be. If you ever run into this look up "truth tables".


Reply With Quote
Thanked by:




Last Updated on May 29, 2017


© 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