Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Updated June 30, 2023
Top Posters
looks_one
SJunior
with 6 posts (0 thanks)
looks_two
zt379
with 3 posts (2 thanks)
looks_3
EDGE
with 2 posts (2 thanks)
looks_4
DavidHP
with 1 posts (0 thanks)
trending_up
1,261 views
thumb_up
4 thanks given
group
4 followers
forum
10 posts
attach_file
1 attachments
June 27th, 2023, 10:19 PM
Goiânia/Goiás/Brazil
Posts: 5 since Jun 2023
Thanks Given: 4
Thanks Received: 0
My knowledge in NT8 programming is very little and I need to add the following situation in the source code, but I have already tried some alternatives, but without success.
Change the candlesticks/bars chains, when:
HS = (d18[0] > 0 && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0]);
color Lime
LS = (d18[0] < 0 && dO18[0] > 0 && d18[0] < d38[0] && dO18[0] > d38[0]);
color red
H = (d18[0] > 0 && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0] && d18[0] > d208[0] && dO18[0 ] < d208[0]);
color cyan
L = (d18[0] < 0 && dO18[0] > 0 && d18[0] < d38[0] && dO18[0] > d38[0] && d18[0] < d208[0] && dO18[0 ] > d208[0]);
color magenta
=======================================================
Below is the complete and working code, but without the candles/bars coloring coding.
=====================================================
//
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader .Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
namespace NinjaTrader.NinjaScript.Indicators.mah_Indicators
{
public class Indicators : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "SJunior";
Name = "SJunior";
IsSuspendedWhileInactive = true;
AddPlot(new Stroke(Brushes.LightPink, 4), PlotStyle.Line, "d38");
AddPlot(new Stroke(Brushes.DarkGreen, 4), PlotStyle.Line, "d208");
AddPlot(new Stroke(Brushes.Cyan, 1), PlotStyle.Bar, "d18");
AddPlot(new Stroke(Brushes.Yellow, 1), PlotStyle.Bar, "dO18");
AddPlot(new Stroke(Brushes.LightCyan, 1), PlotStyle.Line, "osc");
AddPlot(new Stroke(Brushes.Goldenrod, 1), PlotStyle.Line, "srs");
AddPlot(new Stroke(Brushes.Goldenrod, 1), PlotStyle.Line, "sri");
AddPlot(new Stroke(Brushes.Yellow, 1), PlotStyle.Line, "nvel_0");
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 20) return;
d38[0] = (((SMA (1)[0]-SMA(8)[0])/SMA(8)[0])*100);
d208[0] = (((SMA(20)[0]-SMA(8)[0])/SMA(8)[0])*100);
d18[0] = (((SMA(1)[0]-SMA(8)[0])/SMA(8)[0])*100);
dO18[0] = (((SMA(1)[1]-SMA(8)[0])/SMA(8)[0])*100);
osc[0] = (d38[0]-d208[0]);
srs[0] = (((2*StdDev(8)[0])/SMA(8)[0])*100);
sri[0] = (((-2*StdDev(8)[0])/SMA(8)[0])*100);
nivel_0[0] = 0;
if (d208[0] <= 0 && d208[0] < d208[1])
PlotBrushes[1][0] = Brushes.Green;
else if (d208[0] >= 0 && d208[0] > d208[1])
PlotBrushes[1][0] = Brushes.Red;
else if (d208[0] <= 0 && d208[0] > d208[1])
PlotBrushes[1][0] = Brushes.Magenta;
else if (d208[0] >= 0 && d208[0] < d208[1])
PlotBrushes[1][0] = Brushes.Orange;
if (osc[0] >= 0 && osc[0] > osc[1])
PlotBrushes[4][0] = Brushes.Green;
else if (osc[0] <= 0 && osc[0] < osc[1])
PlotBrushes[4][0] = Brushes.Red;
else if (osc[0] >= 0 && osc[0] < osc[1])
PlotBrushes[4][0] = Brushes.Magenta;
else if (osc[0] <= 0 && osc[0] > osc[1])
PlotBrushes[4][0] = Brushes.Orange;
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> d38
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> d208
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> d18
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> dO18
{
get { return Values[3]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> osc
{
get { return Values[4]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> srs
{
get { return Values[5]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> sri
{
get { return Values[6]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> nivel_0
{
get { return Values[7]; }
}
[Browsable(false)]
[XmlIgnore]
public bool HiE
{
get; set;
}
[Browsable(false)]
[XmlIgnore]
public bool LoE
{
get; set;
}
[Browsable(false)]
[XmlIgnore]
public bool Hi
{
get; set;
}
[Browsable(false)]
[XmlIgnore]
public bool Lo
{
get; set;
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private mah_Indicators.Indicators[] cacheIndicators;
public mah_Indicators.Indicators Indicators()
{
return Indicators(Input);
}
public mah_Indicators.Indicators Indicators(ISeries<double> input)
{
if (cacheIndicators != null)
for (int idx = 0; idx < cacheIndicators.Length; idx++)
if (cacheIndicators[idx] != null && cacheIndicators[idx].EqualsInput(input))
return cacheIndicators[idx];
return CacheIndicator<mah_Indicators.Indicators>(new mah_Indicators.Indicators(), input, ref cacheIndicators);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.mah_Indicators.Indicators Indicators()
{
return indicator.Indicators(Input);
}
public Indicators.mah_Indicators.Indicators Indicators(ISeries<double> input )
{
return indicator.Indicators(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.mah_Indicators.Indicators Indicators()
{
return indicator.Indicators(Input);
}
public Indicators.mah_Indicators.Indicators Indicators(ISeries<double> input )
{
return indicator.Indicators(input);
}
}
}
#endregion
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
June 28th, 2023, 06:18 AM
Isla Mujeres, MX
Legendary Market Wizard
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: ES / 6E / 6B / CL
Frequency: Every few days
Duration: Minutes
Posts: 1,637 since Aug 2009
Thanks Given: 11,399
Thanks Received: 2,790
You should post the request here:
Sent using the nexusfi.com mobile app
Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind . . .
But Learning to Dance in the Rain ! ! !
June 28th, 2023, 06:28 AM
Saint Louis, Mo., USA
Experience: Advanced
Platform: NinjaTrader, Tradestation
Broker: Amp/CQG, Velocity/TT, Kinetick, TS
Trading: Anything That Moves..
Frequency: Daily
Duration: Minutes
Posts: 209 since Aug 2010
Thanks Given: 98
Thanks Received: 392
SJunior
Change the candlesticks/bars chains
While NT's help guide is not perfect, it does contain a wealth of knowledge, and searchable topics..
https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?barbrushes.htm
Please be safe in this crazy world!
June 28th, 2023, 08:36 AM
Goiânia/Goiás/Brazil
Posts: 5 since Jun 2023
Thanks Given: 4
Thanks Received: 0
EDGE
While NT's help guide is not perfect, it does contain a wealth of knowledge, and searchable topics..
Please be safe in this crazy world!
Yes, but I couldn't do the coding of this function in my indicator.
Could you help me with this coding?
June 28th, 2023, 08:59 AM
Saint Louis, Mo., USA
Experience: Advanced
Platform: NinjaTrader, Tradestation
Broker: Amp/CQG, Velocity/TT, Kinetick, TS
Trading: Anything That Moves..
Frequency: Daily
Duration: Minutes
Posts: 209 since Aug 2010
Thanks Given: 98
Thanks Received: 392
SJunior
Yes, but I couldn't do the coding of this function in my indicator. Could you help me with this coding?
//BarBrushes[x] where x = number of bars back
//Only if condition1 true set current bar color blue
if(yourCondition1TrueFalse) BarBrushes[0] = Brushes.Blue;
//Only if condition2 true set previous bar color yellow
if(yourCondition2TrueFalse) BarBrushes[1] = Brushes.Yellow;
Be Safe!
June 29th, 2023, 01:14 PM
UK London
Legendary Market Wizard
Posts: 2,166 since Sep 2009
Thanks Given: 1,637
Thanks Received: 2,162
SJunior
Yes, but I couldn't do the coding of this function in my indicator.
Could you help me with this coding?
@SJunior
Hi.
I've attached "SJunior Bar Colours NT8"
However it seems the conditions you set out for each bar colour aren't met in order to colour the bars.
If you look at the code and reduce each bar colour criteria to it's minimum you'll see it does colour the bars.
But as you add each further criteria then the bar colours can't be generated
For example using the criteria for your HS:
Code
{
if (d18[0] > 0 && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0])
{
BarBrush = UpColor1;
}
If you break this down in to smaller sections ie:
by moving the last ) bracket and commenting out the remainder of the line with // :
Code
if (d18[0] > 0) // && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0])
will colour the bars
And then if you add the further criteria it still colours the bars but less frequently
Code
if (d18[0] > 0 && dO18[0] < 0 )
Then add the next criteria it colours even fewer bars and when you get the whole criteria it doesn't colour any bars
Code
if (d18[0] > 0 && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0])
So unless I'm misunderstanding something the criteria you have for each bar colour is too complicated to actually generate a bar colour.
Anyway I hope this helps at least to see the code I've added in On Bar Update and Properties and hopefully you can move forward in some way with it.
Kind regards
Attached Files
Elite Membership required to download: SJunior Bar Colours NT8.zip
June 29th, 2023, 08:09 PM
Goiânia/Goiás/Brazil
Posts: 5 since Jun 2023
Thanks Given: 4
Thanks Received: 0
zt379
@
SJunior
Hi.
I've attached "SJunior Bar Colours NT8"
However it seems the conditions you set out for each bar colour aren't met in order to colour the bars.
If you look at the code and reduce each bar colour criteria to it's minimum you'll see it does colour the bars.
But as you add each further criteria then the bar colours can't be generated
For example using the criteria for your HS:
Code
{
if (d18[0] > 0 && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0])
{
BarBrush = UpColor1;
}
If you break this down in to smaller sections ie:
by moving the last ) bracket and commenting out the remainder of the line with // :
Code
if (d18[0] > 0) // && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0])
will colour the bars
And then if you add the further criteria it still colours the bars but less frequently
Code
if (d18[0] > 0 && dO18[0] < 0 )
Then add the next criteria it colours even fewer bars and when you get the whole criteria it doesn't colour any bars
Code
if (d18[0] > 0 && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0])
So unless I'm misunderstanding something the criteria you have for each bar colour is too complicated to actually generate a bar colour.
Anyway I hope this helps at least to see the code I've added in On Bar Update and Properties and hopefully you can move forward in some way with it.
Kind regards
Thanks for the help, it didn't work, but it helped with other details that I needed to put in the code.
I had to develop another formula for the code to work.
I also had to remove "else" to get it to work as I needed it to.
Below is the change I made.
if (ColorBars1)
{
if (closePrice > openPrice && closePrice > SMA (3)[0] && closePrice > SMA(8)[0] && openPrice < SMA(3)[0] && openPrice < SMA(8)[0])
{
BarBrush = UpColor1;
}
if (closePrice < openPrice && closePrice < SMA(3)[0] && closePrice < SMA(8)[0] && openPrice > SMA(3)[0] && openPrice > SMA(8)[0])
{
BarBrush = DnColor1;
}
if (closePrice > openPrice && closePrice > SMA(3)[0] && closePrice > SMA(8)[0] && openPrice < SMA(3)[0] && openPrice < SMA(8)[0] && closePrice > SMA(20)[0] && openPrice < SMA(20)[0])
{
BarBrush = UpColor2;
}
if (closePrice < openPrice && closePrice < SMA(3)[0] && closePrice < SMA(8)[0] && openPrice > SMA(3)[0] && openPrice > SMA(8)[0] && closePrice < SMA(20)[0] && openPrice > SMA(20)[0])
{
BarBrush = DnColor2;
June 29th, 2023, 08:11 PM
Goiânia/Goiás/Brazil
Posts: 5 since Jun 2023
Thanks Given: 4
Thanks Received: 0
EDGE
//BarBrushes[x] where x = number of bars back
//Only if condition1 true set current bar color blue
if(yourCondition1TrueFalse) BarBrushes[0] = Brushes.Blue;
//Only if condition2 true set previous bar color yellow
if(yourCondition2TrueFalse) BarBrushes[1] = Brushes.Yellow;
Be Safe!
Thank's for your help, I combined your information with others and managed to solve the problem.
June 30th, 2023, 05:08 AM
UK London
Legendary Market Wizard
Posts: 2,166 since Sep 2009
Thanks Given: 1,637
Thanks Received: 2,162
@SJunior
Glad you've made progress.
In your code you'll need to replace the instances of
closeprice with
and openPrice with
For example:
Code
if (closePrice > openPrice && closePrice > SMA(3)[0] && closePrice > SMA(8)[0] && openPrice < SMA(3)[0] && openPrice < SMA(8)[0])
should be:
Code
if (Close[0] > Open[0] && Close[0] > SMA(3)[0] && Close[0] > SMA(8)[0] && Open[0] < SMA(3)[0] && Open[0] < SMA(8)[0])
kind regards
June 30th, 2023, 10:44 AM
Goiânia/Goiás/Brazil
Posts: 5 since Jun 2023
Thanks Given: 4
Thanks Received: 0
zt379
@
SJunior
Glad you've made progress.
In your code you'll need to replace the instances of
closeprice with
and
openPrice with
For example:
Code
if (closePrice > openPrice && closePrice > SMA(3)[0] && closePrice > SMA(8)[0] && openPrice < SMA(3)[0] && openPrice < SMA(8)[0])
should be:
Code
if (Close[0] > Open[0] && Close[0] > SMA(3)[0] && Close[0] > SMA(8)[0] && Open[0] < SMA(3)[0] && Open[0] < SMA(8)[0])
kind regards
Thank you for your help.
So that I understand, why does [0] have to be used and when do I have to change it to [1] or [2] or [3]......?
Last Updated on June 30, 2023