Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Adding Bollinger to Strategy Analyzer chart.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Adding Bollinger to Strategy Analyzer chart.

    I am trying to add Bollinger Bands to a strategy. I create a BB object and call AddChartIndicator. The only thing that appears on the chart is a series of jagged lines reflected above and below the prices. Is there a way to make this work? Thanks.

    #region Using declarations
    ...
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class goldreturn : Strategy
    {

    private Bollinger bb;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "goldreturn";
    Calculate = Calculate.OnPriceChange;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    rsi = RSI(14, 1);
    adx = ADX(14);
    // bbu = Bollinger(20,2).Upper();
    bbl = Bollinger(20,2).Lower;
    bb = Bollinger(20,2);

    // Add RSI and ADX indicators to the chart for display
    // This only displays the indicators for the primary Bars object (main instrument) on the chart

    AddChartIndicator(bb);
    }
    }

    protected override void OnBarUpdate()
    {
    //Add your custom strategy logic here.


    if (Input[0] > Bollinger(2,20).Upper[0] + 0.5 ) {
    EnterShort(10,"shortgold");
    }
    if (Input[0] < Bollinger(2,20).Upper[0])
    ExitShort("shortgold");


    if (Input[0] < Bollinger(2,20).Lower[0] - 0.5 ) {
    EnterLong(10,"longgold");
    }
    if (Input[0] > Bollinger(2,20).Lower[0])
    ExitLong("longgold");
    }


    }

    #2
    Hello bjmoose,

    Thanks for your post.

    This line in your code: bb = Bollinger(20,2); is specifying at 20 standard deviation of a 2 period Bollinger which would lead to plots that quickly change direction. I think you just switched the sequence which should be: bb = Bollinger(2, 20);
    Reference: https://ninjatrader.com/support/help...nger_bands.htm

    In your OnBarUpdate() you are directly adding the Bollinger on each line which is not needed as you created a private Bollinger called bb. You can use that local bollinger in place of the direct calls, for example:

    if (Input[0] > bb.Upper[0] + 0.5 ) {
    EnterShort(10,"shortgold");
    Last edited by NinjaTrader_PaulH; 02-20-2019, 07:06 AM. Reason: Added NT8 help guide reference to Bollinger
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    5 views
    0 likes
    Last Post Touch-Ups  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    8 responses
    61 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    4 responses
    3,289 views
    1 like
    Last Post jgualdronc  
    Started by Option Whisperer, Today, 09:55 AM
    0 responses
    5 views
    0 likes
    Last Post Option Whisperer  
    Started by halgo_boulder, 04-20-2024, 08:44 AM
    2 responses
    24 views
    0 likes
    Last Post halgo_boulder  
    Working...
    X