Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Code to determine Linear Regression Crossover Price in Advance

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

    Code to determine Linear Regression Crossover Price in Advance

    I'm trying to figure out how to calculate the Close price needed to cause the LinearRegression indicator to crossover. I want to seen this price in advance of the actual crossing.
    I've been trying to add ticks to the Close[0] term to find out how many ticks are needed but am having a problem and getting messages of "Cannot implicitly convert type 'double' to Ninja Trader.Data.DataSeries"
    I get this message whether i try the below code or increment the Close[0] term inside the LinReg formula itself.

    Can someone help me to increment the input to the LinReg formula by adding 1 tick (a double) at a time t the Close[0] (an IdataSeries) to find the value for the crossover?

    TIA...
    taddypole...

    Variables:

    private double deltaDn;
    private DataSeries CloseCrossOver;

    Initialize:
    CloseCrossOver = new DataSeries(this);




    for (int i=0; i < 10; i++)
    {
    CloseCrossOver = Close[0] + i * TickSize;
    LinReg.Set(LinReg(CloseCrossOver ,length)[0]);
    LinRegAvg.Set(EMA(LinRegCurve,trigAvg)[0]);
    deltaDn = (LinReg[0] - LinRegAvg[0]);

    if(deltaDn == 0)
    {
    int TurnUpTickTarget = i;
    }
    }
    Attached Files

    #2
    Originally posted by Taddypole View Post
    I'm trying to figure out how to calculate the Close price needed to cause the LinearRegression indicator to crossover. I want to seen this price in advance of the actual crossing.
    I've been trying to add ticks to the Close[0] term to find out how many ticks are needed but am having a problem and getting messages of "Cannot implicitly convert type 'double' to Ninja Trader.Data.DataSeries"
    I get this message whether i try the below code or increment the Close[0] term inside the LinReg formula itself.

    Can someone help me to increment the input to the LinReg formula by adding 1 tick (a double) at a time t the Close[0] (an IdataSeries) to find the value for the crossover?

    TIA...
    taddypole...

    Variables:

    private double deltaDn;
    private DataSeries CloseCrossOver;

    Initialize:
    CloseCrossOver = new DataSeries(this);




    for (int i=0; i < 10; i++)
    {
    CloseCrossOver = Close[0] + i * TickSize;
    LinReg.Set(LinReg(CloseCrossOver ,length)[0]);
    LinRegAvg.Set(EMA(LinRegCurve,trigAvg)[0]);
    deltaDn = (LinReg[0] - LinRegAvg[0]);

    if(deltaDn == 0)
    {
    int TurnUpTickTarget = i;
    }
    }
    Looking only at your code without testing it out, you declared CloseCrossOver as a DataSeries. The correct way to assign a value to a DataSeries is to use the Set method, not an equals sign.

    Code:
    CloseCrossOver.Set(Close[0] + i * TickSize);
    As to a comment on the likely outcome of your code, deltaDn is very unlikely to ever be exactly zero, as the two values from which it is calculated are doubles. Thus, the block that assigns TurnUpTickTarget is very unlikely to ever run. You might want to look at examining a deviation from a set small value instead of equality to zero.
    Last edited by koganam; 12-15-2012, 07:43 AM.

    Comment


      #3
      Thanks Koganam,

      I've made progress thanks to your help, but now stuck on another point.

      I've attached a test indicator called "LinRegCrossingPrice.cs" for reference.

      What has me stuck now is curious. I am able to iterate the “CloseDelta” dataSeries variable by one tick, but the TriggerChannelUp and TrigAvgChannelUp variables do not update. Thus my deltaUp variable does not change either.

      I don’t understand why these variables would not update.

      And per your earlier comment about the zero crossing of deltaUp and deltaDn, I have changed the crossing test to <= for now. I will refine this more if I can get the indicator working.

      Regards,
      Taddypole…
      Attached Files

      Comment


        #4
        I still don't understand why this won't calculate an iterated input such as the dataSeries CloseDelta.
        I'm trying to iterate the Close[0] by one tick through a range of 10 ticks to look for a crossing of the linear regression curve with its linear regression curve average. Is there something simple i'm dong wrong or is this just not possible?

        thanks,
        taddypole...



        for (int i=0; i < 10; i++)
        {
        CloseDelta.Set(Close[0] + i * TickSize);
        TriggerChannelUp.Set(LinReg(CloseDelta,length)[0]);
        TrigAvgChannelUp.Set(EMA(TriggerChannelUp,trigAvgL ength)[0])
        }

        Comment


          #5
          Originally posted by Taddypole View Post
          I still don't understand why this won't calculate an iterated input such as the dataSeries CloseDelta.
          I'm trying to iterate the Close[0] by one tick through a range of 10 ticks to look for a crossing of the linear regression curve with its linear regression curve average. Is there something simple i'm dong wrong or is this just not possible?

          thanks,
          taddypole...



          for (int i=0; i < 10; i++)
          {
          CloseDelta.Set(Close[0] + i * TickSize);
          TriggerChannelUp.Set(LinReg(CloseDelta,length)[0]);
          TrigAvgChannelUp.Set(EMA(TriggerChannelUp,trigAvgL ength)[0])
          }
          You have some sleuthing to do.


          Check on the actual values of the TriggerChannel terms.
          • Are they changing at all?
          • Are they changing in lockstep, so that even though they are changing, their difference is not?
          • If changing, are the changes large enough to trigger your delta conditions?
          Have you considered plotting the values, to confirm visually that there is a crossover that your code does not trap?

          You might also want to look at the logic of your code, once you verify that you are getting changes large enough. I notice that you have the same difference you are checking, in the same manner, for both up and down conditions, but you are not using an absolute value.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DayTradingDEMON, Today, 09:28 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          8 responses
          31 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by helpwanted, Today, 03:06 AM
          2 responses
          21 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by navyguy06, Today, 09:28 AM
          0 responses
          2 views
          0 likes
          Last Post navyguy06  
          Started by rjbtrade1, 11-30-2023, 04:38 PM
          2 responses
          77 views
          0 likes
          Last Post DavidHP
          by DavidHP
           
          Working...
          X