Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to compare current stochastics to previous stoch

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

    how to compare current stochastics to previous stoch

    I'm trying to compare the current Stochastics K to the previous one of 2 crosses.

    something like this in code:

    if stochastics K cross above stochastics D of current bar
    &&
    current stochastics K > stochastics K from the previous stochastics K cross above stochastics D

    &&
    Current price < previous price from when stochastics K cross above D

    I'm also attaching a screenshot.

    Any help is appreciated.
    Thx.
    Attached Files

    #2
    Hi John, one idea would be working with an small array variable here to store what you need for your comparisons, consider this small snippet in your OnBarUpdate() to get started on this -

    Code:
    if (CurrentBar < 10) return;
    			
    if (CrossAbove(StochasticsFast(3, 14).K, StochasticsFast(3, 14).D, 1))
    {
    	pastCrosses[1] = pastCrosses[0];
    	pastCrosses[0] = StochasticsFast(3, 14).K[0];
    }
    			
    if (pastCrosses[0] > pastCrosses[1] && StochasticsFast(3, 14).D[0] < 30.0 && CrossAbove(StochasticsFast(3, 14).K, StochasticsFast(3, 14).D, 1))
             DrawDot("tag" + CurrentBar, true, 0, Low[0] - TickSize, Color.Blue);
    ( pastCrosses is defined as private double[] pastCrosses = new double[2]; )
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand, thanks for the snippet. Let me give it a try and see how it goes.
      Thx,
      JR

      Comment


        #4
        Hi Bertrand, that snippet worked good. Could someone tell me what am i doing wrong in trying this loop below: I'm trying to replace a OR OR OR condition with a loop, but it is not working:

        Ugly code (see the many CCI(5)
        #region Variables
        private bool myFlag = false;

        protected override void OnBarUpdate()
        . post: from bertrand on: 10-16-2014, 02:47 AM has the if for pastCrosses section.
        .
        .
        if (pastCrosses[0] > pastCrosses[1] && Stochastics(3, 8, 3).D[0] < 30.0
        && CrossAbove(Stochastics(3, 8, 3).K, Stochastics(3, 8, 3).D, 1))
        && ((CCI(5)[1] > 0) || (CCI(5)[2] > 0) || (CCI(5)[3] > 0)|| (CCI(5)[4] > 0)
        || (CCI(5)[5] > 0) || (CCI(5)[6] > 0) || (CCI(5)[7] > 0) || (CCI(5)[8] > 0)))


        {
        DrawDot("tag" + CurrentBar, true, 0, Low[0] - TickSize, Color.Blue);
        }

        ========================
        Better code:
        ========================
        #region Variables
        private bool myFlag = false;

        protected override void OnBarUpdate()

        if (pastCrosses[0] > pastCrosses[1] && Stochastics(3, 8, 3).D[0] < 30.0
        && CrossAbove(Stochastics(3, 8, 3).K, Stochastics(3, 8, 3).D, 1))

        myFlag = false;
        for (int i = 0; i < 8; i++)
        {
        if (CCI(5)[i] > 0){
        myFlag = true;
        break;
        }
        }

        if (myFlag)

        {
        DrawDot("tag" + CurrentBar, true, 0, Low[0] - TickSize, Color.Blue);
        }
        Attached Files
        Last edited by john_robertson00; 10-29-2014, 03:36 PM.

        Comment


          #5
          John, looks as if you need to change your flag reset location, i.e. -

          Code:
          if (CrossAbove(Stochastics(3, 8, 3).K, Stochastics(3, 8, 3).D, 1)) 
          		{
          				
          			for (int i = 0; i < 8; i++)
          			{
          				if (CCI(5)[i] > 0)
          				{
          					myFlag = true;
          					break;
          				}
          			}
          		}
          			
          		if (myFlag)
          			DrawDot("tag" + CurrentBar, true, 0, Low[0] - TickSize, Color.Blue);
          			
          			myFlag = false;
          Last edited by NinjaTrader_Bertrand; 10-30-2014, 06:43 AM.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Bertrand, you are the master. It works like a champ now. Thank you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            2 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Working...
            X