NexusFi: Find Your Edge


Home Menu

 





BackBrush coding Help..


Discussion in NinjaTrader

Updated
    1. trending_up 981 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 9 posts
    2. attach_file 6 attachments




 
Search this Thread

BackBrush coding Help..

  #1 (permalink)
 hfwiley 
new haven CT/usa
 
Experience: Intermediate
Platform: ninja
Trading: es mini
Posts: 9 since Jul 2012
Thanks Given: 1
Thanks Received: 0

I Have an Indicator I am working on that I am trying to have a background change as price moves through the lines.

As I'm just beginning to lean to code, please forgive any ignorant statement or questions I may ask or the code structure itself.. I'm Learning.

I have coded the backbrushes on the chart where and somewhat when I want them to change. It compiles and shows on the chart. Here is the code I have.

protected override void OnBarUpdate()


if (High[0] >= Upper[0])
BackBrushes[0] = Brushes.Green;


if(Low[0] <= Upper2[0])
BackBrushes[0] = Brushes.Silver;

if(Low[0] <= Upper2[0])
BackBrushes[0] = Brushes.Silver;


if(Low[0] <= Lower[0])
BackBrushes[0] = Brushes.Red;

I am trying to have the backbrush color remain until the price hits another line.

If I understand correctly the BackBrush[0] will show color choice every time with current bar if the (if)statement is true and upon next bar if statement is false the BackBrush color shows the default chart color.

I am trying to have BackBrushes[0] = Brushes.Green; stay green as price is falling

until it hits the if(Low[0] <= Upper2[0])BackBrushes[0] = Brushes.Silver;

Any Help would be greatly appreciated, I've been trying with no avail

Thanks

Attached Thumbnails
Click image for larger version

Name:	background screen shot.png
Views:	42
Size:	10.5 KB
ID:	328515  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Better Renko Gaps
The Elite Circle
NexusFi Journal Challenge - April 2024
Feedback and Announcements
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
GFIs1 1 DAX trade per day journal
18 thanks
The Program
18 thanks
  #2 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,171
Thanks Received: 6,018

Try this

 
Code
if (High[0] >= Upper[0])
 BackBrushes[0] = Brushes.Green;
else if(Low[0] <= Upper2[0])
 BackBrushes[0] = Brushes.Silver;
else if(Low[0] <= Lower[0])
 BackBrushes[0] = Brushes.Red;
else
 BackBrushes[0] = null; // <- default background color as defined in the properties

Reply With Quote
  #3 (permalink)
 hfwiley 
new haven CT/usa
 
Experience: Intermediate
Platform: ninja
Trading: es mini
Posts: 9 since Jul 2012
Thanks Given: 1
Thanks Received: 0


That code produced green background @ [0] and silver @ [0] locations

Attached Thumbnails
Click image for larger version

Name:	background01.png
Views:	39
Size:	11.2 KB
ID:	328516  
Started this thread Reply With Quote
  #4 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 73 since Jan 2020
Thanks Given: 23
Thanks Received: 42


hfwiley View Post
That code produced green background @ [0] and silver @ [0] locations

Try changing that last line (after else) to:
 
Code
 
else
      BackBrushes[0] = BackBrushes[1]; // <- paints current background to same brush as background 1 bar ago
If your code doesn't already, it may also be necessary to introduce a check to make sure that there is indeed a "one bar ago", otherwise this would throw an error when processing the chart's very first bar. So maybe this instead:

 
Code
 
else
     if (CurrentBar >= 1)
         BackBrushes[0] = BackBrushes[1];

Reply With Quote
  #5 (permalink)
 hfwiley 
new haven CT/usa
 
Experience: Intermediate
Platform: ninja
Trading: es mini
Posts: 9 since Jul 2012
Thanks Given: 1
Thanks Received: 0

This code produced proper green backbrush at price point

held green background color until price point hit Silver backbrush price point and held silver background until hit green price point.

Totally ignored the red price point.

if (High[0] >= Upper[0])
BackBrushes[0] = Brushes.Green;
else if(Low[0] <= Upper2[0])
BackBrushes[0] = Brushes.Silver;
else if(Low[0] <= Lower[0])
BackBrushes[0] = Brushes.Red;
else
BackBrushes[0] = BackBrushes[1];

Attached Thumbnails
Click image for larger version

Name:	background02.png
Views:	32
Size:	31.8 KB
ID:	328523  
Started this thread Reply With Quote
  #6 (permalink)
 hfwiley 
new haven CT/usa
 
Experience: Intermediate
Platform: ninja
Trading: es mini
Posts: 9 since Jul 2012
Thanks Given: 1
Thanks Received: 0

Should I be trying to use this instead, RegionHighlights

if (High[0] >= Upper[1])
Draw.RegionHighlightX(this, "GreenBackground " + CurrentBars[0].ToString(), 1,0, Brushes.Transparent, Brushes.Green, 20);
BackBrushes[0] = Brushes.Green;
if (Low[0] <= Upper2[1])
Draw.RegionHighlightX(this, "YellowBackground " + CurrentBars[0].ToString(), 1,0, Brushes.Transparent, Brushes.Silver, 30);
BackBrushes[0] = Brushes.Silver;
if (Low[0] <= Lower[1])
Draw.RegionHighlightX(this, "RedBackground " + CurrentBars[0].ToString(), 1,0, Brushes.Transparent, Brushes.Magenta, 30);
BackBrushes[0] = Brushes.Magenta;
// BackBrushes[0] = High[0] <= Upper2[1] ? Brushes.Yellow : Brushes.Yellow;//


Total mess with that..... not sure on how to end region

Attached Thumbnails
Click image for larger version

Name:	background03.png
Views:	35
Size:	36.8 KB
ID:	328525  
Started this thread Reply With Quote
  #7 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 73 since Jan 2020
Thanks Given: 23
Thanks Received: 42


hfwiley View Post
This code produced proper green backbrush at price point

held green background color until price point hit Silver backbrush price point and held silver background until hit green price point.

Totally ignored the red price point.

if (High[0] >= Upper[0])
BackBrushes[0] = Brushes.Green;
else if(Low[0] <= Upper2[0])
BackBrushes[0] = Brushes.Silver;
else if(Low[0] <= Lower[0])
BackBrushes[0] = Brushes.Red;
else
BackBrushes[0] = BackBrushes[1];

Assuming "Upper2" is always Higher than "Lower", the logic is probably never going to the segment with Brushes.Red, because once Silver is found we exit the if comparison.

Try testing for Red before Silver and see if that works:

 
Code
if (High[0] >= Upper[0])
 BackBrushes[0] = Brushes.Green;
else if(Low[0] <= Lower[0])
 BackBrushes[0] = Brushes.Red;
else if(Low[0] <= Upper2[0])
 BackBrushes[0] = Brushes.Silver;
else
  BackBrushes[0] = BackBrushes[1]

Reply With Quote
Thanked by:
  #8 (permalink)
 hfwiley 
new haven CT/usa
 
Experience: Intermediate
Platform: ninja
Trading: es mini
Posts: 9 since Jul 2012
Thanks Given: 1
Thanks Received: 0

Red showed up but didn't continue with red background, should continue till price hits an upper line. is there a way to check for background color? if( background = color)
Then xyz

is there any kind of reference beside ninja help guide that shows all the syntax that are available.

Attached Thumbnails
Click image for larger version

Name:	background04.png
Views:	30
Size:	39.6 KB
ID:	328543  
Started this thread Reply With Quote
  #9 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 73 since Jan 2020
Thanks Given: 23
Thanks Received: 42


hfwiley View Post
Red showed up but didn't continue with red background, should continue till price hits an upper line. is there a way to check for background color? if( background = color)
Then xyz

is there any kind of reference beside ninja help guide that shows all the syntax that are available.

Hello again. It's hard to diagnose without context. The fact that silver is showing in between the reds means that the condition is satisfied, and we're checking Low against two different things, so whichever is hit is taking precedence.

Another way is to put in a "return" once a condition is satisfied, and then re-ordering your checks according to precedence, e.g. once red is hit, do NOT go to check for silver and instead wait for the next bar. Based on your initial code, here's one way of doing it:

 
Code
if (High[0] >= Upper[0])
{
   BackBrushes[0] = Brushes.Green;
   return; // skips what's below and goes back to wait for the next bar
}

if(Low[0] <= Lower[0])
{
   BackBrushes[0] = Brushes.Red;
   return; // if we have a red, we don't check for a silver
}

if(Low[0] <= Upper2[0])
{
   BackBrushes[0] = Brushes.Silver;
   return; // skips what's below and goes back to wait for the next bar
}
See if this approach works

Reply With Quote
  #10 (permalink)
 hfwiley 
new haven CT/usa
 
Experience: Intermediate
Platform: ninja
Trading: es mini
Posts: 9 since Jul 2012
Thanks Given: 1
Thanks Received: 0


Finally got it figured out, here is what worked. Thanks for the help!

if(High[0] >= Upper[0])
BackBrushes[0] = Brushes.PaleGreen;
if(High[0] < Upper[0] && Low[0] > Lower[0])
BackBrushes[0] = Brushes.PaleGreen;



if(Low[0] <= Lower[0])
BackBrushes[0] = Brushes.Pink;
if(Low[0] > Lower[0] && High[0] < Upper[0])
BackBrushes[0] = BackBrushes[1];



if(BackBrush == Brushes.PaleGreen && Low[0] <= Upper2[0] )
BackBrushes[0] = Brushes.Gainsboro;
else if(BackBrush == Brushes.Pink && High[0] >= Upper6[0])
BackBrushes[0] = Brushes.Gainsboro;

Attached Thumbnails
Click image for larger version

Name:	background06.png
Views:	31
Size:	22.0 KB
ID:	328824  
Started this thread Reply With Quote




Last Updated on December 29, 2022


© 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