Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I need help with granularity...PLEASE!

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

    I need help with granularity...PLEASE!

    Can someone PLEASE help me out with this granularity issue? As I've stated before I can't seem to figure out what I'm doing wrong. I've been banging my head for the last couple of days. Here's the problem again. I'm trying to generate a buy signal based on the daily closing price being greater than the previous day's high and enter the market the if the following day's intraday price is greater than the signal bar's high price. e.g. :

    bool tradeSignal=false; // this variable has global scope

    double stopPrice=0; // this variable has local scope

    if(BarsInProgress==0)
    {
    if(Close[0]>High[1]) // trade signal condition
    {
    tradeSignal=true;
    stopPrice=High[0];
    }
    }

    if(BarsInProgress==1)
    {
    if(Close[1][0]>stopPrice && tradeSignal==true) // trying to compare current intrabar price to signal bars high
    {
    EnterLong(1,100,"Long: 10min") // trying to execute market order at intrabar price
    tradeSignal=false;
    }
    }

    // logic to exit if daily close<previous day's low...
    if(BarsInProgress==0)
    {
    if(Close[0]<Low[1])
    {
    ExitLong("Long: 10min");
    tradeSignal=false;
    }
    }
    Last edited by d.allen101; 07-03-2009, 07:18 AM.

    #2
    Originally posted by d.allen101 View Post
    Can someone PLEASE help me out with this granularity issue? As I've stated before I can't seem to figure out what I'm doing wrong. I've been banging my head for the last couple of days. Here's the problem again. I'm trying to generate a buy signal based on the daily closing price being greater than the previous day's high and enter the market the if the following day's intraday price is greater than the signal bar's high price. e.g. :

    bool tradeSignal=false; // this variable has global scope

    double stopPrice=0; // this variable has local scope

    if(BarsInProgress==0)
    {
    if(Close[0]>High[1]) // trade signal condition
    {
    tradeSignal=true;
    stopPrice=High[0];
    }
    }

    if(BarsInProgress==1)
    {
    if(Close[1][0]>stopPrice && tradeSignal==true) // trying to compare current intrabar price to signal bars high
    {
    EnterLong(1,100,"Long: 10min") // trying to execute market order at intrabar price
    tradeSignal=false;
    }
    }

    // logic to exit if daily close<previous day's low...
    if(BarsInProgress==0)
    {
    if(Close[0]<Low[1])
    {
    ExitLong("Long: 10min");
    tradeSignal=false;
    }
    }
    what is your issue?

    Comment


      #3
      1) It enters orders that don't conform to the logic e.g. if(Close[1][0]>stopPrice && tradeSignal==true)...the code I've written will execute the order regardless if the current entry intraday price exceeds the previous day's high or not!

      2) Other than the initial trade during the back test all subsequent trades are executed 2 day's following the signal bar which shouldn't be the case...the trades should be executed the day after the daily signal bar granted the statement within the entry logic is true.

      The logic to calculate the signal works just fine so does the logic to exit, it's the entry logic that's not working as expected...again what I'm attempting to do is generate a signal based on daily data and execute the trade the FOLLOWING day but only under certain conditions i.e. if(Close[1][0]>stopPrice...

      Comment


        #4
        I suggest you print the timestamps of your bars on every single BarsInProgress to first get an understanding of the sequence of events. Then you will know which bar is referenced when you do Closes[1][0] (you currently are using Close).

        Depending on how you have your bars added it is important to understand the order in which bar events come in.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          That (Closes[1][0]) was just a typo, I'm using the correct syntax. I'll try printing with timestamp or maybe even read the section in NT doc on debugging with Visual Studio, that way I can step through it...

          Comment


            #6
            Originally posted by d.allen101 View Post
            That (Closes[1][0]) was just a typo, I'm using the correct syntax. I'll try printing with timestamp or maybe even read the section in NT doc on debugging with Visual Studio, that way I can step through it...
            at least post the entire code

            Comment


              #7
              here's what i wrote this morning, this is slightly different than the code from yesterday, but the intent is still the same: 1) generate signal based on daily prices and execute trade the following data under certain conditions:

              #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>
              /// Generate trade siganls in higher time fram and execute orders in lower time fram
              /// </summary>
              [Description("Generate trade siganls in higher time fram and execute orders in lower time fram")]
              public class MyGranularity : 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;
              Add(PeriodType.Minute,10);
              // TraceOrders=true;
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              bool tradeSignal=false;
              protected override void OnBarUpdate()
              {
              if(BarsInProgress==0)
              {
              // Print("primary bar called at: " + Time[0]);

              if(Close[1]>High[2])
              {
              tradeSignal=true;
              }
              }

              if(BarsInProgress==1)
              {
              // Print("secondary bar called at: " + Time[0]);

              double stopPrice=Highs[0][1];

              if(Close[0]>stopPrice && tradeSignal==true)
              {
              EnterLong(1,100,"long");

              if(Position.MarketPosition==MarketPosition.Long)
              {
              tradeSignal=false;
              }
              else
              {
              tradeSignal=true;
              }
              }
              }

              if(BarsInProgress==0)
              {
              if(Close[0]<Low[1])
              {
              ExitLong();
              tradeSignal=false;
              }
              }
              }

              #region Properties
              #endregion
              }
              }

              Comment


                #8
                if(Position.MarketPosition==MarketPosition.Long)
                {
                tradeSignal=false;
                }
                else
                {
                tradeSignal=true;
                }
                This piece will cause you problems for sure

                Comment


                  #9
                  excluding that piece still doesn't produce the desired results... do you have any solutions?

                  Comment


                    #10
                    try changing
                    if(Close[1]>High[2])
                    {
                    tradeSignal=true;
                    }
                    }

                    to Close[0] > High[1]

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    630 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    364 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    105 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    566 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    568 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X