• 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, 06: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 martyn73, Today, 05:27 PM
    0 responses
    5 views
    0 likes
    Last Post martyn73  
    Started by MichaelAlexander, 02-22-2017, 05:06 AM
    5 responses
    1,402 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by walter739, Today, 11:56 AM
    3 responses
    10 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by kevinfloresz, Today, 09:46 AM
    4 responses
    29 views
    0 likes
    Last Post kevinfloresz  
    Started by digibob, 12-13-2019, 10:01 PM
    7 responses
    20 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Working...
    X