NexusFi: Find Your Edge


Home Menu

 





Colour Bar Script Assistance


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one zt379 with 4 posts (0 thanks)
    2. looks_two eDanny with 3 posts (4 thanks)
    3. looks_3 bukkan with 1 posts (2 thanks)
    4. looks_4 redratsal with 1 posts (1 thanks)
      Best Posters
    1. looks_one bukkan with 2 thanks per post
    2. looks_two eDanny with 1.3 thanks per post
    3. looks_3 redratsal with 1 thanks per post
    4. looks_4 Big Mike with 1 thanks per post
    1. trending_up 4,218 views
    2. thumb_up 8 thanks given
    3. group 3 followers
    1. forum 10 posts
    2. attach_file 0 attachments




 
Search this Thread

Colour Bar Script Assistance

  #1 (permalink)
 zt379 
UK London
 
Platform: NT
Posts: 2,046 since Sep 2009
Thanks Given: 1,567
Thanks Received: 1,933

I am trying to learn this stuff !
Hoping someone can help.

This is what I have.
I've tried every combination of curly brakets and even those that compile keep
ALL bars coloured Magenta.



protected override void OnBarUpdate()

{
Value.Set(100 * (MAX(High, Period)[0] - Close[0]) / (MAX(High, Period)[0] - MIN(Low, Period)[0] == 0 ? 1 : MAX(High, Period)[0] - MIN(Low, Period)[0]));

if (Value[0] > 0);

BarColor = Color.Blue;

if (Value[0] < 0);

BarColor = Color.Magenta;

}

thx

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
How to apply profiles
Traders Hideout
Increase in trading performance by 75%
The Elite Circle
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,440 since Jun 2009
Thanks Given: 33,209
Thanks Received: 101,599


One useful thing is troubleshooting. Add a print() statement or two so you can see the value, and probably find the error in the calculation.

It's been a while, but something like:
 
Code
                            
Print(CurrentBar[0] + ": " Value[0]); 

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
redratsal's Avatar
 redratsal 
Milan (I)
 
Experience: Advanced
Platform: Ninjatrader
Broker: Kinetick
Trading: FDAX,6E,CL,YM,NQ,ES
Posts: 1,648 since Oct 2010
Thanks Given: 1,215
Thanks Received: 2,090


zt379 View Post
I am trying to learn this stuff !
Hoping someone can help.

This is what I have.
I've tried every combination of curly brakets and even those that compile keep
ALL bars coloured Magenta.



protected override void OnBarUpdate()

{
Value.Set(100 * (MAX(High, Period)[0] - Close[0]) / (MAX(High, Period)[0] - MIN(Low, Period)[0] == 0 ? 1 : MAX(High, Period)[0] - MIN(Low, Period)[0]));

if (Value[0] > 0);

BarColor = Color.Blue;

if (Value[0] < 0);

BarColor = Color.Magenta;

}

thx

try this one:

if (Value[0] > 0);

{
BarColor = Color.Blue;
}
else
{
BarColor = Color.Magenta;
}

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #5 (permalink)
 bukkan 
Calcutta, India
 
Experience: Intermediate
Platform: ArthaChitra
Posts: 278 since Jun 2009
Thanks Given: 161
Thanks Received: 271


zt379 View Post
if (Value[0] > 0);

BarColor = Color.Blue;

if (Value[0] < 0);

BarColor = Color.Magenta;


redratsal View Post
try this one:

if (Value[0] > 0);

{
BarColor = Color.Blue;
}
else
{
BarColor = Color.Magenta;
}


remove the ;

Reply With Quote
Thanked by:
  #6 (permalink)
 zt379 
UK London
 
Platform: NT
Posts: 2,046 since Sep 2009
Thanks Given: 1,567
Thanks Received: 1,933


bukkan View Post
remove the ;

And the winner is................
bukkan.
I only wish I understood why ! lol

I've changed it to a CrossAbove and CrossBelow statement:
I've coloured the bars ok for CrossAbove +5 and CrossBelow -5,
without the "else" statement.(which should colour all bars between +5 and -5 as gray)

But when I add the else statement I get the magenta bars ok but all other bars are gray:

I used :

if (CrossAbove (+5,Value,1))
{
BarColor = Color.Blue;
}
if (CrossBelow (-5,Value,1))
{
BarColor = Color.Magenta;
}
else
{
BarColor = Color.Gray;
}
}

Many thx

Started this thread Reply With Quote
  #7 (permalink)
 
eDanny's Avatar
 eDanny 
East Rochester, NY
 
Experience: Intermediate
Platform: NT
Posts: 329 since Jul 2009
Thanks Given: 18
Thanks Received: 425

if (CrossAbove (+5,Value,1))
BarColor = Color.Blue;
else
if (CrossBelow (-5,Value,1))
BarColor = Color.Magenta;
else
BarColor = Color.Gray;

Not sure if the logic here is good, if a CrossBelow can possibly happen while in the CrossAbove condition but this is the way to test anyway.

Reply With Quote
Thanked by:
  #8 (permalink)
 zt379 
UK London
 
Platform: NT
Posts: 2,046 since Sep 2009
Thanks Given: 1,567
Thanks Received: 1,933


eDanny View Post
if (CrossAbove (+5,Value,1))
BarColor = Color.Blue;
else
if (CrossBelow (-5,Value,1))
BarColor = Color.Magenta;
else
BarColor = Color.Gray;

Not sure if the logic here is good, if a CrossBelow can possibly happen while in the CrossAbove condition but this is the way to test anyway.

eDanny

It's working as per your post, all be it with 2 x } at the end so many thanks.

I'm at a loss as to the reasons for differences in how to group things within the curly brackets, or
as and when they are needed.
I spend hours only to find out my mistake is down to one single bracket or a semi colon etc..

Any suggestion as to what material/video/link (anything) that would help me learn this stuff
would be great, if you have time.

Again my thanks

Started this thread Reply With Quote
  #9 (permalink)
 
eDanny's Avatar
 eDanny 
East Rochester, NY
 
Experience: Intermediate
Platform: NT
Posts: 329 since Jul 2009
Thanks Given: 18
Thanks Received: 425

If you have two statements after an if() test you will need to enclose them ind curly brackets or else only the first one will execute according to the result of the test.

if (CrossAbove (+5,Value,1))
BarColor = Color.Blue;
Print("We changed the bar color!");

Above code will only change the bar color if the CrossAbove test is passed but it will always execute the Print statement. To only Print when the bar color changes you would uses brackets to group them together.

if (CrossAbove (+5,Value,1))
{
BarColor = Color.Blue;
Print("We changed the bar color!");
}

Reply With Quote
Thanked by:
  #10 (permalink)
 zt379 
UK London
 
Platform: NT
Posts: 2,046 since Sep 2009
Thanks Given: 1,567
Thanks Received: 1,933



eDanny View Post
If you have two statements after an if() test you will need to enclose them ind curly brackets or else only the first one will execute according to the result of the test.

if (CrossAbove (+5,Value,1))
BarColor = Color.Blue;
Print("We changed the bar color!");

Above code will only change the bar color if the CrossAbove test is passed but it will always execute the Print statement. To only Print when the bar color changes you would uses brackets to group them together.

if (CrossAbove (+5,Value,1))
{
BarColor = Color.Blue;
Print("We changed the bar color!");
}

So by having "else if" after the first "if", we don't need any brackets, hence your script in your post#7 works ?

But I'm confused.
I did have statements bracketed , see my post#6,
yet the first Color.Blue did not print, only the Magenta and Gray printed.

Perhaps I'm not understanding what your saying ?

thx

Started this thread Reply With Quote




Last Updated on March 17, 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