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

simple strategy ?!

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

    simple strategy ?!

    Hi guys,

    i tried to program a simple but quite well working EOD-strategy (tried it in MS Ex...for single stocks) in NinjaTrader.
    Unfortunately it doesn´t work. Hope someone of you can help me.

    The following conditions should be met:

    If
    Close[1]<Open[1]
    and
    Close[0]>Open[0]
    and
    SMA(12)[1]<Low[1]
    and
    SMA(12)[0]<Low[1]

    then a StopBuy-Order should be set. the StopBuy-Price for next-day-opening shall be High[0].
    If the Order is filled, a stoploss and Target should be set. Stoploss 0,99*Low[0] and a Targetprice of 4 percent from BuySignal.

    I´d be very happy if someone could help me. The Wizard didn´t work properly.

    The same vice versa should then be simple to do for me..




    Thanks in advance.

    Gallli

    #2
    Welcome to our forums here Galli - I'll have our NinjaScript trainee take a look at your inquiry shortly.

    Thanks for your patience,
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank you!
      I´m really confused because i tried it many times but neither the buy-signals worked properly nor the stoploss/targetprice

      Comment


        #4
        Hello Gallli,

        Thanks for the note. I am happy to help.

        So that I may further assist you can you answer the following questions.
        • How are you testing your strategy? (Example: Real-Time, Strategy Analyzer, etc..)
        • Who are you connected to? This is displayed by green on lower left corner of the Control Center window.
        • What interval are you using in you Strategy? (Example: “1 Min”, “1 Day”, “100 Tick”, etc…)

        Note that all pending orders will expire at the end of the next bar if not filled. So it would possible that if the current bid/ask on the next bar does not fill your order and then be cancelled.

        It is possible to have submitted orders to stay active until they are cancelled by using custom code and enabling the advanced order handling methods by setting liveUntilCancelled to true. See the following link below for more information about “Advanced Order Handling”.


        Here is a link that goes over “Entering a Long position using Stop orders”.


        If you are going to use some custom coding here is a link that can help you debug your code to find out what is going on inside your code.


        Also, if you have trouble with orders you can set “TraceOrders” to true for more debugging info. You may read more information about “TraceOrders” in the following link.


        Happy to be of further assistance.
        JCNinjaTrader Customer Service

        Comment


          #5
          So that I may further assist you can you answer the following questions.
          • How are you testing your strategy? (Example: Real-Time, Strategy Analyzer, etc..)

          At the time i´m only testing with Strategy Analyzer.

          • Who are you connected to? This is displayed by green on lower left corner of the Control Center window.

          I don´t have a realtime data-feed at the moment because i only want to analyse the stock market EOD. So i am connected to yahoo.

          • What interval are you using in you Strategy? (Example: “1 Min”, “1 Day”, “100 Tick”, etc…)

          I want to do my market analyze when market is closed and generate signals for next day open. So i set the time interval to 1 Day.

          THANKS IN ADVANCE!!!

          Best regards
          Gallli

          Comment


            #6
            Hello Gallli,
            Thanks for clarifying.

            I tested out a strategy with the same conditions that you are using but without your “StopLoss” and “ProfitTarget”. I do get a buy order on 02/06/2012 using the following parameters:

            • “Yahoo” - as the data provide
            • “Strategy Analyzer” – as the testing environment
            • “MS” – as the Instrument
            • Data Series Parameters
            o Price based on – “Last”
            o Type – “Day”
            o Value – “1”
            • Time frame Parameters
            o From – “01/01/2012”
            o To – “05/16/2012”

            Could you send a copy of your current strategy to “Support[AT}NinjaTrader[DOT]com” so that I can see what you have so far and run a few tests on it?

            In the subject line put: ATTN JC - http://www.ninjatrader.com/support/f...ad.php?t=49874

            To Export a Strategy go to the NinjaTrader Control Center -> File -> Utilities -> Export NinjaScript. Then put the name of the Strategy in the “File name”. Next, in the lower left panel, double left click on the Strategy to move it to the right panel. Now left click on the “Export” button.

            You are going to have to use some custom code for a few things. If you want the order to have a “StopLoss” be based off of the price of the “Low[0]” instead of the average entry price. You may read the following post about how to modify the price of a “StopLoss” or “Profit Target”.


            Note that when “Backtesting” a strategy it is important to understand orders are filled and the different fill algorithms in NinjaTrader. See the following link below for more information on “Backtest a Strategy”.


            Happy to be of further assistance.
            JCNinjaTrader Customer Service

            Comment


              #7
              Hello JC, thanks for your quick response. I´m just back from holiday.
              Unfortunately my problem still exists but another Indicator-Error worries me more.
              I tried to use the following Indicator.

              #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.Gui.Chart;
              #endregion

              // This namespace holds all indicators and is required. Do not change it.
              namespace NinjaTrader.Indicator
              {
              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              [Description("Enter the description of your new custom indicator here")]
              public class SellCondition : Indicator
              {
              #region Variables
              public int period = 12;
              // Wizard generated variables
              // User defined variables (add any user defined variables below)
              #endregion

              /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
              Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
              Overlay = false;
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              // Use this method for calculating your indicator values. Assign a value to each
              // plot below by replacing 'Close[0]' with your own formula.
              Plot0.Set(Close[0] < Open[0] && Close[1] > Open[1] && Low[2] < SMA(period)[2] && Low[1] < SMA(period)[1] && Low[0] < SMA(period)[0]?1:0);
              }

              #region Properties
              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries Plot0
              {
              get { return Values[0]; }
              }

              #endregion
              }
              }

              .
              .
              .
              then i get an error on my Output-Window:


              Failed to call 'OnBarUpdate' method for market analyzer column 'SellCondition': Ein Aufrufziel hat einen Ausnahmefehler verursacht.
              Error on calling 'OnBarUpdate' method for indicator 'Cond01' on bar 1: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.


              I don´t know what´s wrong with my Indicator-Code.


              I´d be very happy if you could help me!!


              Best regards


              Gallli

              Comment


                #8
                Hello Gallli,

                This error is because in "OnBarUpdate()" is trying to access the data series that does not have enough bars to calculate. More information about making sure you have enough bars can be found at the following link.


                This can be fixed by adding in a check to "CurrentBar" to make sure we have enough for the calculations in "OnBarUpdate()". Example:

                Code:
                protected override void OnBarUpdate()
                {
                	if(CurrentBar < 5)
                        {
                		return;
                        }
                
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
                Plot0.Set(Close[0] < Open[0] && Close[1] > Open[1] && Low[2] < SMA(period)[2] && Low[1] < SMA(period)[1] && Low[0] < SMA(period)[0]?1:0);
                }
                The "if(CurrentBar < 5)" makes sure that there is at least 5 bars worth of data before starting your calculation. This ensures that we are not trying to access data that has not been created yet.

                Please let me know if I can be of further assistance.
                JCNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                26 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 02-22-2024, 01:11 AM
                5 responses
                32 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, Yesterday, 09:53 PM
                2 responses
                49 views
                0 likes
                Last Post wzgy0920  
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                191 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,233 views
                0 likes
                Last Post xiinteractive  
                Working...
                X