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 CarlTrading, 03-31-2026, 09:41 PM
            1 response
            67 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            36 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            61 views
            1 like
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            62 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            53 views
            0 likes
            Last Post CarlTrading  
            Working...
            X