Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X