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 lorem, Yesterday, 09:18 AM
            4 responses
            13 views
            0 likes
            Last Post lorem
            by lorem
             
            Started by Spiderbird, Today, 12:15 PM
            0 responses
            5 views
            0 likes
            Last Post Spiderbird  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            12 responses
            42 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by FrazMann, Today, 11:21 AM
            0 responses
            6 views
            0 likes
            Last Post FrazMann  
            Started by geddyisodin, Yesterday, 05:20 AM
            8 responses
            52 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X