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

most recent cross and count

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

    most recent cross and count

    Need help to a newbie. started coding an indicator to use in MA having 5,15,30 min columns. so far working fine with buy n sell signals. now on a buy or sell signal , need go back and find MRO on recent 5ema to 10sma cross below and count how many times a cci/stoch crossed above 20 from that point. need a little sample code .,
    please help...

    #2
    kinshin,

    So to be clear, you want to count how many times the cci AND stochastic crossed above 20? Could you describe in a little more detail the condition you are looking for here?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Adam,
      On a BarUpdate function I keep checking for some buy, sell signals.,(already coded and working)
      here is what i need: Once it is met then I want to go back in time from that bar and find when this 5 and 10 ma crossed below/above. And once I find it, I want to know if the CCi made n number of crosses to change the status in MA with buy or sell.

      here is the sample:
      OnBarUpate()
      {
      If(RSI>60 && upCycleVariable==true){
      //here is what I need
      before return 1 make sure cci crossed 20, 3 times from the time 5,10 crossed below

      return 1; // flag to update column to buy
      }
      else
      return -1; //flag for sell

      using this as indicator in MA on 5,15,30 min columns.
      Hope I'm clear.
      thanks.

      Comment


        #4
        kinshin,

        I believe something like this would work for tracking CCI crossings since the last MA crossing.

        This would go at the beginning of OnBarUpdate(), outside your if statement for order entry.

        Code:
                //If the MA's cross below reset the CCI crossing counter.
                if(CrossBelow(SMA(5),SMA(10)))
        	{
        		CCICrossings = 0;
        		MACrossFlag = true;
        	}
        	else if(CrossAbove(SMA(5),SMA(10)))  //Check if there is a cross above
        	{
        		MACrossFlag = false;
        	}
        	
                //Count the number of CCI crossings since the last MA cross below
        	if(CrossBelow(CCI(Period),20))
        	{
        		CCICrossings++;
        	}
        This would go inside your if statement brackets : If(RSI>60 && upCycleVariable==true){}

        Code:
                // If there were 3 CCI crossings since the last MA cross below
        	if(CCICrossings>=3 && MACrossFlag)
        	{
        		// do something
        	}
        Please note this assumes that CalculateOnBarClose = true;
        Last edited by NinjaTrader_AdamP; 05-29-2012, 08:09 AM.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          thnx Adam,
          I'll try this. looks pretty simple.

          Comment


            #6
            Adam,
            created the custom indicator for this same purpose and plotted on the charts and working gr8. But the indicator using in the MA has the same calculations., (infact the same method) but the results are way off. I even created public methods to access the the same variables from the one that was plotted on the chart. it returns half of the number of crosses, but never same. yes I am calling update() too.
            Can you suggest any Ideas to fix this ??
            thanks.

            Comment


              #7
              Kinshin,

              How are the results off? Could you possible post your code and a screen shot?

              I'd be happy to take a look.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Adam,
                first I need to get some basics.
                1. When we reload/apply an indicator to the MA window, How do that indicator read the values ?.
                meaning is it like "file reading" program, where it opens the file and start parsing the chunks ?
                So to visually understand this: If I have a 15 min chart with 3 days of data in it, every time I hit reload script in MA, does it start from the left most candle from the 3rd day and ends up at right most candle of present day ?
                2. What happens when we call update() function on a plotted indicator ? is it equivalent to a reload ?
                thnx.

                Comment


                  #9
                  kinshin,

                  1. When we reload/apply an indicator to the MA window, How do that indicator read the values ?.
                  meaning is it like "file reading" program, where it opens the file and start parsing the chunks ?
                  So to visually understand this: If I have a 15 min chart with 3 days of data in it, every time I hit reload script in MA, does it start from the left most candle from the 3rd day and ends up at right most candle of present day ?
                  An indicator would start with the oldest bar on your chart and iterate forward through them, calling OnBarUpdate() for each historical bar. The data series for an indicator gets updated so that MyDataSeries[0] is always the most current bar value during these iterations.

                  If you have a 15 min chart with 3 days of data, your understanding is correct here. There is a slight nuance though with the CalculateOnBarClose setting. If this is true, the calculation ends with the most current CLOSED bar, whereas with this setting false it would end with the most current open bar. Additionally, as the price updates for this open bar it would update the most recent calculation at myDataSeries[0], basically calling OnBarUpdate() tick-by-tick.

                  2. What happens when we call update() function on a plotted indicator ? is it equivalent to a reload ?
                  This would force the OnBarUpdate() method to be called regardless of CalculateOnBarClose settings, or whether a bar closed recently or not.

                  Please let me know if I may assist further.
                  Adam P.NinjaTrader Customer Service

                  Comment


                    #10
                    thanks Adam,
                    glad I asked about the basics. now I see what's going on. In the chart I have 60 days of "data to load" set. And my indicator in MA looking at 256 (by default) nothing in Initialize() set. But columns (5M,15M) of MA , the "#number of bars to look back" set to default 50. That's the reason for the different crossOver counts.
                    I changed it to 256 in MA columns.. Now everything is in sync., and working fine.

                    But here are the new questions:
                    1. Are MA and chart are independent of each other ? If yes, then what it means "use update() on unplotted indicator calls";
                    2. The setting "look back period" hardCoded in indicator gets overridden by what the column setting has in MA ? meaning which one takes the precedence ?
                    3. If I set lookback period infinte, what does it mean ? and how do I set the same setting in MA column ?
                    -kin

                    Comment


                      #11
                      Kinshin,

                      1. Are MA and chart are independent of each other ? If yes, then what it means "use update() on unplotted indicator calls";
                      Yes. Each would have its own instance of the indicator running however they work similarly. Where are you reading that "use update()" at?

                      2. The setting "look back period" hardCoded in indicator gets overridden by what the column setting has in MA ? meaning which one takes the precedence ?
                      It shouldn't. I am wondering if you are looking at two different things here. There is MaximumBarsLookBack, and a look back period for cross over that are not the same. Could you clarify?

                      3. If I set lookback period infinte, what does it mean ? and how do I set the same setting in MA column ?
                      I think I see now. MaximumBarsLookBack is only to set the size you will allow your data series to be. If its set to 256 it will throw away the oldest element in the data series once it reaches 256 elements every time its updated with a new one. 256 is a maximum number of elements allowed, not necessarily how many will be in the data series. Its used for memory conservation. Plot data series are overridden to be Infinite so that it will allow the whole dataseries to be plotted on your chart.
                      Adam P.NinjaTrader Customer Service

                      Comment


                        #12
                        with my ignorance I read "not plots" as unplotted on charts.
                        here is the thread replied by you:


                        So when I call update(), does it wake up the indicator every time to go thru the whole dataSeries objects with current bar ? Or the first call makes it active instance for that process ?

                        Comment


                          #13
                          Hi kinshin9,

                          OnBarUpdate() isn't something you call. It's an event that's raised when a new bar is received. Indicators then process all logic within their OnBarUpdate() section during this event

                          Update() calls have a very specific use, related to exposing non-plot values from another indicator. This is shown here:


                          How are you using Update() within your own script?
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            Ryan,
                            it's a general question about the basics, as of now I'm not using update(). What I meant about "calling update()" is , I saw this "update()" was used right before accessing a public variable via public method
                            in an outside indicator. so in general terms I'm referencing this event as call() within that public method.
                            Hope I didn;t confuse.

                            Comment


                              #15
                              I see. Update() is used here just to make sure that the indicator values in the called script are up to date. There's internal logic that does this automatically for any called plots or *Series, but it's needed for the non plot values.
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              150 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post tkaboris  
                              Working...
                              X