• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 DaveCro, Today, 09:05 PM
      0 responses
      13 views
      0 likes
      Last Post DaveCro
      by DaveCro
       
      Started by magnatauren, Today, 08:26 PM
      0 responses
      7 views
      0 likes
      Last Post magnatauren  
      Started by SharonSS, Today, 07:21 PM
      1 response
      17 views
      0 likes
      Last Post NinjaTrader_EricB  
      Started by bmccoard, Today, 06:48 PM
      0 responses
      11 views
      0 likes
      Last Post bmccoard  
      Started by omololu, Today, 05:10 PM
      0 responses
      15 views
      0 likes
      Last Post omololu
      by omololu
       
      Working...
      X