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

Beginner - Can't get strategy to buy anything

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

    Beginner - Can't get strategy to buy anything

    Hi,

    Believe it or not I was a comp sci major a long time ago. Giving NinjaTrader a legitimate effort but for the life of me I can't get anything to run. I'm not even going to get started importing data until I can get something to run on a random simulation.

    Trying to see how my strategy runs in the simulation. Is this even possible? I have read through the help booklet but my strategy still won't buy anything when the simulation is running.
    I'd really like to use this program as I have a bunch of strategies I have backtested elsewhere.

    Here is the code. Just looking to buy 1 e-mini ES future if it trends up and then set limits on selling it. Can't find anything online that will help me with this. Pretty damn simple for starters. I used the strategy wizard and then edited the code. It compiles fine. HELP!!!

    public class PeteScalper : Strategy
    {
    #region Variables
    // Wizard generated variables
    private double initial_P = 0.00; // Default setting for Initial_P
    private double longP = 1; // Default setting for LongP
    private double longWin = 1; // Default setting for LongWin
    private double longLose = 1; // Default setting for LongLose
    // User defined variables (add any user defined variables below)
    #endregion

    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }

    protected override void OnBarUpdate()
    {
    Initial_P = Open[0];
    LongP = Initial_P +0.50;
    LongWin = LongP +0.50;
    LongLose = LongP -1.00;

    if (Close[0] >= LongP)
    {
    EnterLongLimit(1, LongP, "");
    }

    if (Close[0] >= LongWin)
    {
    ExitLongLimit(LongWin, "", "");
    }

    if (Close[0] <= LongLose)
    {
    ExitLongLimit(LongLose, "", "");
    }
    }

    #2
    Attach your strategy to a chart and turn on chart trader.

    Also use print statements and look in the output window.

    You're trying to enter the market at $0000.50.

    Maybe you mean to

    EnterLongLimit (1,Close [0]+LongP) ;

    ?

    Comment


      #3
      Doesn't this simply define my LongP?

      Initial_P = Open[0];
      LongP = Initial_P +0.50;


      So if it was 2000.00 at the open. You buy at 2000.50?

      And then you said "Attach your strategy to a chart and turn on chart trader." I am running a simulation. I can't get the chart to even appear. The 'Help' doesn't really explain it.

      Really wish there was a basic video or instructional walkthru with this program for beginners. I can't spend money on something (ninjatrader) if I can't even get it working from the start. This is very frustrating/confusing.

      Comment


        #4
        I'm sorry pistolpt, I completely missed that assignment late last night.

        You are correct in your assumptions.

        Bring up the output window, and put in some print statements, and see if you are even getting that.

        You should open an ES 12-15 chart (File->New Chart?), and right click on the chart and add your strategy there.

        I haven't run in the simulation mode in ages. You might want to download 1 or 2 days of data and run in Market Replay.


        Code:
        protected override void OnBarUpdate()
         {
         Initial_P = Open[0];
         LongP = Initial_P +0.50;
         LongWin = LongP +0.50;
         LongLose = LongP -1.00;
        
        Print ("Initial_P=" + Initial_P + " LongWin="+ LongWin +" Close[0]="+Close[0] );
        
         if (Close[0] >= LongP)
         {
         EnterLongLimit(1, LongP, "");
         }

        Comment


          #5
          Hello pistolpt,

          Thank you for writing in. Once you enable the strategy, please navigate to the NinjaTrader Control Center window and select the "Strategies" tab. Please check if your strategy is not shown in green. If not, please review the following documents:
          http://ninjatrader.com/support/helpG...ync%2Bposition
          http://ninjatrader.com/support/helpG...ync%2Bposition

          Your strategy will not enter any positions until it is shown in green in the strategies tab.

          Please let me know if you have any questions or if I may be of further assistance.
          Michael M.NinjaTrader Quality Assurance

          Comment


            #6
            Yeah I'm not even getting print statements. Just printing "Hello" doesn't come up. And yes, the strategy is enabled and green when the simulation is running.
            Here is all I get....
            "**NT** Disabling NinjaScript strategy 'PeteScalper/ce8566ffdec8400bbb4311b249cb7ad6'
            **NT** Enabling NinjaScript strategy 'PeteScalper/81d50c462ec847cd83d9701793ca36b3' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes"

            Here is the entire freggin thing. It's VERY small:
            #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

            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Strategy
            {
            /// <summary>
            /// Scalper_Pete
            /// </summary>
            [Description("Scalper_Pete")]
            public class PeteScalper : Strategy
            {
            #region Variables
            // Wizard generated variables
            private double initial_P = 0.00; // Default setting for Initial_P
            private double longP = 1; // Default setting for LongP
            private double shortP = 1; // Default setting for ShortP
            private double longWin = 1; // Default setting for LongWin
            private double longLose = 1; // Default setting for LongLose
            private double shortWin = 1; // Default setting for ShortWin
            private double shortLose = 1; // Default setting for ShortLose
            // 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()
            {
            CalculateOnBarClose = true;
            Print("Hello");

            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            Initial_P = Open[0];
            LongP = Initial_P +0.50;
            LongWin = LongP +0.50;
            LongLose = LongP -1.00;

            Print("LongP ",LongP);
            Print(" - ");
            Print(Open[0]);
            Print(Close[0]);

            if (Close[0] >= LongP)
            {
            EnterLongLimit(1, LongP, "");
            }

            if (Close[0] >= LongWin)
            {
            ExitLongLimit(LongWin, "", "");
            }

            if (Close[0] <= LongLose)
            {
            ExitLongLimit(LongLose, "", "");
            }
            }

            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public double Initial_P
            {
            get { return initial_P; }
            set { initial_P = Math.Max(0.00, value); }
            }

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

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

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

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

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

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

            Comment


              #7
              Hello pistolpt,

              Thank you for your response.

              I am getting prints and orders using your code.

              Can you clarify the following?
              • Who are you connected to? This is displayed by green on lower left corner of the Control Center window.
              • What instrument(s) have you selected? If a futures instrument, what expiry is selected? (Example: ES 06-13)
              • What interval is selected for your chart(s)? (Example: Tick, Minute, Day, etc.)

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by helpwanted, Today, 03:06 AM
              1 response
              10 views
              0 likes
              Last Post sarafuenonly123  
              Started by Brevo, Today, 01:45 AM
              0 responses
              8 views
              0 likes
              Last Post Brevo
              by Brevo
               
              Started by aussugardefender, Today, 01:07 AM
              0 responses
              5 views
              0 likes
              Last Post aussugardefender  
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              242 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              386 views
              1 like
              Last Post Gavini
              by Gavini
               
              Working...
              X