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

Momentum level double

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

    Momentum level double

    Hello !!! wood some one help me to solve this problem
    code like this return level int 1
    i check all properties double but got return as int in window testing

    private double buyLevel = 0.003;

    if (Momentum(MomentP)[0] < -BuyLevel)
    {
    EnterLong(Lot, "Buy");
    }

    #2
    Hello,

    I am unsure on your question here.

    There is no print statement listed in the code you had provided, can you please explain what you are printing and provide more details on what you are trying to do? Are you printing the BuyLevel and it is not a double?

    It would be best to provide the exact code that you are printing, this will help me see what you are trying to do or print.

    I look forward to being of furhter assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi !!! here is the code
      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Indicator;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Strategy;
      #endregion
      namespace NinjaTrader.Strategy
      {

      [Description("Enter the description of your strategy here")]
      public class cmo : Strategy
      {
      #region Variables
      // Wizard generated variables
      private int lot = 1;
      private int momentP = 14;
      private double buyLevel = 0.003;
      private int sellLevel = 66;
      private int profit = 44;
      private int stop = 55;
      private int profitS = 44;
      private int stopS = 44;
      #endregion

      protected override void Initialize()
      {
      Add(Momentum(MomentP));
      SetProfitTarget("Buy", CalculationMode.Ticks, Profit);
      SetStopLoss("Buy", CalculationMode.Ticks, Stop, false);

      CalculateOnBarClose = true;
      }

      protected override void OnBarUpdate()
      {
      if (Momentum(MomentP)[0] < BuyLevel)
      {
      EnterLong(Lot, "Buy");
      }
      }

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

      [Description("")]
      [GridCategory("Parameters")]
      public int MomentP
      {
      get { return momentP; }
      set { momentP = Math.Max(1, value); }
      }

      [Description("")]
      [GridCategory("Parameters")]
      public double BuyLevel
      {
      get { return buyLevel; }
      set { buyLevel = Math.Max(1, value); }
      }

      [Description("")]
      [GridCategory("Parameters")]
      public int SellLevel
      {
      get { return sellLevel; }
      set { sellLevel = Math.Max(1, value); }
      }

      [Description("")]
      [GridCategory("Parameters")]
      public int Profit
      {
      get { return profit; }
      set { profit = Math.Max(1, value); }
      }

      [Description("")]
      [GridCategory("Parameters")]
      public int Stop
      {
      get { return stop; }
      set { stop = Math.Max(1, value); }
      }

      [Description("")]
      [GridCategory("Parameters")]
      public int ProfitS
      {
      get { return profitS; }
      set { profitS = Math.Max(1, value); }
      }

      [Description("")]
      [GridCategory("Parameters")]
      public int StopS
      {
      get { return stopS; }
      set { stopS = Math.Max(1, value); }
      }
      #endregion
      }
      }

      Comment


        #4
        Hello,

        I am still unsure on this as you did not include your tests.

        The only double I see is BuyLevel, is this the value? If so can you provide the syntax for the test you were doing to print this? A double should be able to be used as the value you have, but I would need to see the code you are using for the print to see if that is the cause or not.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          in test strategy window buyLevel = 0.003 become int 1
          after i try run test or optimize
          optimization dont return any value and no trades
          test window return int 1

          Comment


            #6
            Hello,

            Are you aware you are using Math.Max in the BuyLevel property?

            Code:
            public double BuyLevel
            {
            get { return buyLevel; }
            set { buyLevel = Math.Max(1, value); }
            }
            You are using Math.Max(1, value);

            Math.Max Returns the larger of two specified numbers.

            The value 0.003 would be less than 1 so 1 would be used instead because it is the larger number. If you want to use any number you would need to remove the Max method and just use:

            Code:
            public double BuyLevel
            {
            get { return buyLevel; }
            set { buyLevel = value; }
            }
            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rajendrasubedi2023, Today, 09:50 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by geotrades1, Today, 10:02 AM
            0 responses
            4 views
            0 likes
            Last Post geotrades1  
            Started by ender_wiggum, Today, 09:50 AM
            0 responses
            4 views
            0 likes
            Last Post ender_wiggum  
            Started by bmartz, Today, 09:30 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by geddyisodin, Today, 05:20 AM
            3 responses
            24 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X