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

Use Bollinger Bands in Strategy

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

    Use Bollinger Bands in Strategy

    Hi there,

    I am trying to use Bollinger Bands in my Strategy but I got error: "Indicator 'Std. dev.': Error on calling 'OnBarUpdate' method on bar 1169: Object reference not set to an instance of an object.".
    After that I tried to create simple example using strategy builder and I still get this error: "Indicator 'Std. dev.': Error on calling 'OnBarUpdate' method on bar 1169: Object reference not set to an instance of an object.".
    I will attach simple code with should work but somehow its not working. Code:
    Code:
    #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.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class MyCustomStrategyBollingerBandsTest : Strategy
    {
    private Bollinger Bollinger1;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "MyCustomStrategyBollingerBandsTest";
    Calculate = Calculate.OnEachTick;
    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)
    {
    Bollinger1 = Bollinger(Close, 2, 14);
    Bollinger1.Plots[0].Brush = Brushes.Goldenrod;
    Bollinger1.Plots[1].Brush = Brushes.Goldenrod;
    Bollinger1.Plots[2].Brush = Brushes.Goldenrod;
    AddChartIndicator(Bollinger1);
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;
    
    if (CurrentBars[0] < 1)
    return;
    
    // Set 1
    if (CrossAbove(Close, Bollinger1.Upper, 1))
    {
    ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }
    
    // Set 2
    if (CrossBelow(Close, Bollinger1.Lower, 1))
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }
    
    }
    }
    }
    I am testing bots in market reply.
    Waiting for your reply. Thanks

    #2
    Hello Revazi123,

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm


    I've tested this on a 1 minute ES 03-21 chart and was not able to reproduce.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello ChelseaB,

      I am getting this issue in market reply. I will attach video where I am demonstrating it. Code is correct I am sure as it is generated from StrategyBuilder.
      Please check video:


      Waiting for your reply. Thanks

      Comment


        #4
        Hi again,

        I even checked default SampleMACrossOver strategy and that one also gets errors while trying to use it in market reply. I will attach screenshot so you can see errors.
        So its seems that problem is with market reply but I am able to test in market reply other strategies.

        Waiting for your reply. Thanks

        Click image for larger version

Name:	Screenshot 2021-03-08 172658.png
Views:	695
Size:	1.15 MB
ID:	1145424

        Comment


          #5
          Hello Revazi123,

          There may be an issue with the installation.

          Please run the repair from the installer.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello ChelseaB,

            I have reinstalled NT8 but I am getting same errors.

            Waiting for your reply. Thanks

            Comment


              #7
              Hello Revazi123,

              Please send an email to platformsupport [at] ninjatrader [dot] com so that we may investigate on your end.
              (corrected)
              Last edited by NinjaTrader_ChelseaB; 03-08-2021, 09:11 AM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello ChelseaB,

                That email address doesn't exists:
                Attached Files

                Comment


                  #9
                  Hello Revazi123,

                  Apologies, there is a typo in that address. I've corrected it.

                  Also, below is a link to the Contact Us page.
                  If you have any questions, concerns or feedback, or want to open an account, we're here to help. Click here to find the appropriate contact for your needs!
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by usazencort, Today, 01:16 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post usazencort  
                  Started by kaywai, 09-01-2023, 08:44 PM
                  5 responses
                  603 views
                  0 likes
                  Last Post NinjaTrader_Jason  
                  Started by xiinteractive, 04-09-2024, 08:08 AM
                  6 responses
                  22 views
                  0 likes
                  Last Post xiinteractive  
                  Started by Pattontje, Yesterday, 02:10 PM
                  2 responses
                  21 views
                  0 likes
                  Last Post Pattontje  
                  Started by flybuzz, 04-21-2024, 04:07 PM
                  17 responses
                  230 views
                  0 likes
                  Last Post TradingLoss  
                  Working...
                  X