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

problems converting a few lines

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

    problems converting a few lines

    Hi,

    I'm trying to "convert" the following code to NinjaScript. It correctly compiles however my debugging process indicates a problem that I believe is related to the following lines. I had hoped somebody might "see" something. Here's the "old" code:

    K= 5; Pr = 5;
    VarSto:= If(Barnum<Pr+(Pr*1.5),StK,MOV((((1-MyConst)*Ref(VarSto,-1))+(MyConst*Close)),2,s));
    StVarK := Mov((((VarSto-LLV(VarSto,K ))/(HHV(VarSto,K )-LLV(VarSto,K)))*100),Sl,s);


    Here's the code I've written/converted to NinjaScript:

    if(CurrentBar < (Pr + (Pr * 1.5))){VarSto = StK;}
    if(CurrentBar >= (Pr + (Pr * 1.5)))
    {
    myDataSeries2.Set(((1 - MyConst) * (VarStoSeries[1])) + (MyConst * Close[0]));
    VarSto = SMA(myDataSeries2,
    2)[0];
    }
    VarStoSeries.Set(VarSto);

    myDataSeries.Set(((VarSto - Math.Min(VarSto, K)) / (Math.Max(VarSto, K) - Math.Min(VarSto, K))) * 100);
    StVarK = SMA(myDataSeries, sl)[
    0];

    I believe the problem I'm having is within this posted code...specifically the "myDataSeries.Set" calculation always equates to "100", which should not be the case. I wondered if somebody could point out the difference in my Ninja code compared to the original code...is there a problem with math, logic, or something else? Thank you in advance.

    #2
    Unfortunately I am not a Metastock expert (looked like Metastock code). What I noticed is you converted HHV and LLV to Math.Max/Min. I believe this is incorrect.

    HHV(data array, period) is what the Metastock function is. Math.Max takes the highest number between the two inputs you provide it. This isn't the same. Instead you want to use MAX and MIN functions.

    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks, that sounds to me like it could be the problem. Unfortunately when I make the change NT gives me errors left and right--here's what I've tried to do:

      VarSto1 = MIN(VarSto, K);
      VarSto2 = MAX(VarSto, K)
      ;
      myDataSeries.Set(((VarSto - VarSto1) / (VarSto2 - VarSto1)) *
      100);

      Comment


        #4
        Please check your syntax. The first parameter is not an int/double. It is suppose to be a DataSeries.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks...got it.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by fitspressoburnfat, Today, 04:25 AM
          0 responses
          2 views
          0 likes
          Last Post fitspressoburnfat  
          Started by Skifree, Today, 03:41 AM
          1 response
          4 views
          0 likes
          Last Post Skifree
          by Skifree
           
          Started by usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          604 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          23 views
          0 likes
          Last Post xiinteractive  
          Working...
          X