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 junkone, Today, 11:37 AM
    0 responses
    2 views
    0 likes
    Last Post junkone
    by junkone
     
    Started by quantismo, 04-17-2024, 05:13 PM
    5 responses
    34 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by proptrade13, Today, 11:06 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    34 views
    0 likes
    Last Post love2code2trade  
    Started by cls71, Today, 04:45 AM
    2 responses
    10 views
    0 likes
    Last Post eDanny
    by eDanny
     
    Working...
    X