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 trgui7883, 07-31-2024, 10:05 AM
            13 responses
            1,477 views
            0 likes
            Last Post alvinabish  
            Started by DuncanMarino, Today, 04:06 AM
            0 responses
            6 views
            0 likes
            Last Post DuncanMarino  
            Started by daledg28098, Today, 03:19 AM
            0 responses
            6 views
            0 likes
            Last Post daledg28098  
            Started by giogio1, Today, 12:52 AM
            0 responses
            11 views
            0 likes
            Last Post giogio1
            by giogio1
             
            Started by butt_toast, 04-28-2021, 05:46 AM
            8 responses
            2,716 views
            0 likes
            Last Post ILSNT
            by ILSNT
             
            Working...
            X