NexusFi: Find Your Edge


Home Menu

 





NinjaScript Assistance: When a slope goes flat


Discussion in NinjaTrader

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




 
Search this Thread

NinjaScript Assistance: When a slope goes flat

  #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:	162
Size:	12.8 KB
ID:	234909  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Are there any eval firms that allow you to sink to your …
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Futures True Range Report
The Elite Circle
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #3 (permalink)
 SpeculatorSeth   is a Vendor
 
Posts: 780 since Apr 2016
Thanks Given: 22
Thanks Received: 1,018


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: 780 since Apr 2016
Thanks Given: 22
Thanks Received: 1,018


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


© 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