Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy OnBarUpdate not outputing

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

    Strategy OnBarUpdate not outputing

    Hi there,

    This is my second thread, and since my last post got such a prompt and effective reply from Support, I thought I'd try again!

    I'm trying to run a basic strategy based on a custom indicator. When I add the strategy to a chart, the 'print' function in the initialize function is called, and output to the output window "Strategy initiating"

    However, I would then expect to see the output message from the OnBarUpdate method being output to the output window i.e. "checking positions" however the window is just blank. This is confusing and tells me that the strategy is not running - but I don't understand why!

    Please can you explain why OnBarUpdate is not being called? Thanks in advance Support, and keep up the great work!!!



    #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>
    /// 24/01/2014 - indicator now apparently working, so writing the strategy to wrap around it. Should be relatively straightforwrad
    /// </summary>
    [Description("24/01/2014 - indicator now apparently working, so writing the strategy to wrap around it. Should be relatively straightforwrad")]
    public class FirstCustomNTStrategyFRES : Strategy
    {
    #region Variables
    // Wizard generated variables
    // 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("Custom Strategy initiating");

    FirstNTCustomIndFRES().Plots[0].Pen.Color = Color.Orange;

    Add(FirstNTCustomIndFRES());
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if(CurrentBar < 100)
    {
    Print("Not enough bars to calculate, returning");
    return;
    }

    //THIS SECTION CHECKS WHETHER CURRENT ORDER EXISTS, THEN HAS COMBINATION
    //OF STATEMENTS FOR EACH INDICATOR OUTPUT
    Print("checking positions");
    if (Position.MarketPosition == MarketPosition.Flat)//CHECK IF FLAT
    {
    if (FirstNTCustomIndFRES().Plot0[0] == 1)//BUY
    {
    EnterLong(DefaultQuantity,"");
    Print("No position open, buy signal received - entering long position");
    }
    if (FirstNTCustomIndFRES().Plot0[0] == 2)//DO NOTHING
    {
    Print("No position open, sell signal received, no action");
    }
    if (FirstNTCustomIndFRES().Plot0[0] == 3)//DO NOTHING
    {
    Print("Hold signal received, no action");
    }
    if (FirstNTCustomIndFRES().Plot0[0] == 4)//BUY
    {
    EnterLong(DefaultQuantity,"");
    Print("No position open, mixed signal received - entering long position");
    }
    }
    if (Position.MarketPosition == MarketPosition.Long)//CHECK IF POSITION ALREADY EXISTS
    {
    if (FirstNTCustomIndFRES().Plot0[0] == 1)//DO NOTHING
    {
    Print("No position open, buy signal received, no action");
    }
    if (FirstNTCustomIndFRES().Plot0[0] == 2)//SELL
    {
    ExitLong(DefaultQuantity);
    Print("Position open, sell signal received - exiting long position");
    }
    if (FirstNTCustomIndFRES().Plot0[0] == 3)//DO NOTHING
    {
    Print("Hold signal received, no action");
    }
    if (FirstNTCustomIndFRES().Plot0[0] == 4)//SELL
    {
    ExitLong(DefaultQuantity);
    Print("Position open, mixed signal received - exiting long position");
    }
    }


    }

    #region Properties
    #endregion
    }
    }

    #2
    Are you connected?
    If not a strategy wouldn't run on chart only in strategy analizer.

    Comment


      #3
      Hello Cjeesebar,

      Thank you for your post.

      Baruch has a good question.

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

      What instrument have you selected?

      (For a chart) what interval is selected?

      How many days to load is available for the strategy?
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        Thanks to Baruch and Cal for replies!

        Yes I'm connected, to Google.

        The instrument I've selected is FRES, on the FTSE100.

        249 bars in the data, which should be enough.

        EDIT: daily intervals

        Thoughts?!
        Last edited by Cjeesebar; 01-30-2014, 09:55 AM.

        Comment


          #5
          Hello Cjeesebar,

          FRES should work fine as this is a stock.

          Since, Google only supports Stocks and Indexes you would not receive information for FTSE 100 as this is a future.

          Can you run this strategy with the FRES, using only Daily data?
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Hi Cal,

            I wasn't clear in my last message - the instrument I have selected is FRES-LON. This instrument is on the FTSE100, but I am not pulling data for the FTSE, I just mentioned this for context.

            Thus, the strategy is simply running on FRES data, and I am still not getting the expected output.

            Thanks again for your help!

            Comment


              #7
              Cjeesebar,

              Can you attach the actual script, this can be found in (My) Documents -> NinjaTrader 7 -> bin -> Custom -> Strategy

              Additionally, what are the expected results for the output window?
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Strategy attached.

                I'm really just looking for it to give a printed output to the output window, either "checking positions" if there are 100+ bars, or "Not enough bars to calculate, returning" if there are <100 bars.
                Last edited by Cjeesebar; 01-30-2014, 02:51 PM.

                Comment


                  #9
                  Do you have the Indicator that is suppose to be referenced with this strategy?
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    Yup, attached.
                    Last edited by Cjeesebar; 01-30-2014, 02:51 PM.

                    Comment


                      #11
                      Cjeesebar,

                      I was able to add the strategy and get it running without any issues.

                      Can you clarify a few things for me first.

                      When you add the strategy, is this to a Strategy Analyzer, chart, or Strategy Tab?

                      If the Chart or Strategy Tab, you enabling this strategy?
                      Cal H.NinjaTrader Customer Service

                      Comment


                        #12
                        I'm attaching it to a chart. The way I do it is:
                        1. New chart for FRES
                        2. Right click chart, select "strategies..."
                        3. I select the strategy in question, and press "new".
                        4. I press "apply" and it says "Although you have order confirmation enabled, orders generated by a strategy will be submitted without confirmation
                        5. I press close
                        6. I look at output window, doesn't show anything about "checking position" or "not enough bars" etc

                        Comment


                          #13
                          Cjeesebar,

                          If you go back to the Strategies window, is the parameter 'Enabled' set to true?
                          Cal H.NinjaTrader Customer Service

                          Comment


                            #14
                            Cal = legend.
                            Cjeesebar = noob.

                            No it was set to false. I didn't know you had to enable it. It is working fine now.

                            I would like to thank you again for your assistance in helping me getting this working, you guys do a great job and I for one very much appreciate it.

                            Cheers!!!!!
                            Cjeesebar

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by rocketman7, Today, 09:41 AM
                            3 responses
                            7 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by traderqz, Today, 09:44 AM
                            2 responses
                            4 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by stafe, 04-15-2024, 08:34 PM
                            8 responses
                            40 views
                            0 likes
                            Last Post stafe
                            by stafe
                             
                            Started by rocketman7, Today, 02:12 AM
                            7 responses
                            31 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by guillembm, Yesterday, 11:25 AM
                            3 responses
                            16 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Working...
                            X