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]; )

    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.

          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 Mindset, 04-21-2026, 06:46 AM
            0 responses
            102 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            144 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            71 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by cmoran13, 04-16-2026, 01:02 PM
            0 responses
            125 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            79 views
            0 likes
            Last Post PaulMohn  
            Working...
            X