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

Error when multiplying ATR indicator with double user input variable

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

    Error when multiplying ATR indicator with double user input variable

    I get a compilation error on line 37 when I multiply an indicator ATR(20)*TrStopATR (a double user input).

    Error is line 37 - "Operator * cannot be applied to NinjaTrader.Indicator.ATR and double"
    Line 37 - SetTrailStop("", CalculationMode.Price, ATR(20)*TrStopATRs, false);

    Strategy code below
    Pl advise what i'm doing wrong?

    thanks
    Kiran



    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// BB
    /// </summary>
    [Description("BB ")]
    public class BBcross0TrStop : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int bBperiod = 20; // Default setting for BBperiod
    private double bBstdev = 1; // Default setting for BBstdev
    private double trStopATRs = 3; // Default setting for TrStopATRs
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    SetTrailStop("", CalculationMode.Price, ATR(20)*TrStopATRs, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(Close, Bollinger(BBstdev, BBperiod).Lower, 1))
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (CrossBelow(Close, Bollinger(BBstdev, BBperiod).Lower, 1))
    {
    EnterShort(DefaultQuantity, "");
    }
    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int BBperiod
    {
    get { return bBperiod; }
    set { bBperiod = Math.Max(10, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public double BBstdev
    {
    get { return bBstdev; }
    set { bBstdev = Math.Max(0.4, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public double TrStopATRs
    {
    get { return trStopATRs; }
    set { trStopATRs = Math.Max(1.5, value); }
    }
    #endregion
    }

    #2
    Hello Kiran,

    This is because "ATR(20)" is going to return a Indicator not a value like a double. You will want to use the "[]" brackets to reference the double value of the Plot. Here is a thread that you may view that will go over how to use "[]" brackets.



    Note if you are going to use the SetTrailingStop() to a price value of based on the ATR you will want to move that into your Entry Conditions. The reason for this is the inside of Initialize() the ATR is not going to have any data loaded and is only going to get called when the Strategy is first started up.

    If you would like to see how you could use this inside of the strategy wizard you may view the following post.

    Support for the development of custom automated trading strategies using NinjaScript.
    JCNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Jon17, Today, 04:33 PM
    0 responses
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Started by alifarahani, Today, 09:40 AM
    6 responses
    41 views
    0 likes
    Last Post alifarahani  
    Started by Waxavi, Today, 02:10 AM
    1 response
    21 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Working...
    X