In this example I asked "Write an indicator in C# for NinjaTrader that calculates and plots the difference between the upper and lower bands of a 21 period Bollinger Bands indicator."
Note that this is just one way to implement this indicator, and there may be other approaches that could also work.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using NinjaTrader.Indicator; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; namespace MyNamespace { [Description("Calculates and plots the difference between the upper and lower bands of a 21 period Bollinger Bands indicator")] public class BollingerBandsDifference : Indicator { private BollingerBands bollingerBands; protected override void Initialize() { bollingerBands = BollingerBands(21, 2); } protected override void OnBarUpdate() { if (CurrentBar < bollingerBands.Upper.Count) { return; } Values[0][0] = bollingerBands.Upper[0] - bollingerBands.Lower[0]; } public override string ToString() { return "Bollinger Bands Difference"; } public override string DisplayName { get { return "Bollinger Bands Difference"; } } [Browsable(false)] public IndicatorDataSeries Upper { get { return Values[0]; } } [Browsable(false)] public IndicatorDataSeries Lower { get { return Values[1]; } } [Browsable(false)] public IndicatorDataSeries Middle { get { return Values[2]; } } } }
Now for the fun of it, here is the poem ChatGPT AI generated for the anaconda and the belly dancing rabbit:
My anaconda slithers and twists
As it swallows my belly dancing rabbit
With a graceful, fluid motion
It devours its prey in the ocean
The rabbit twirls and spins
But it cannot escape its fate
As it is engulfed by the anaconda's coils
And becomes its latest meal
The anaconda, satisfied and full
Continues on its way
A master of the underwater realm
It reigns supreme, without fear or dismay
So let this be a lesson to all
Who dare to cross the anaconda's path
For it is a predator without equal
And it will always come out on top.
Cheers!
Comment