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

Problem using Math.ceiling & .floor

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

    Problem using Math.ceiling & .floor

    Here's my script :

    V1=Period / 2;
    if ((Math.Ceiling (V1) - V1) <= 0.5)
    { HalvedLength = Math.Ceiling(V1);}
    else
    {HalvedLength = Math.Floor(V1);}

    if ((Math.Sqrt(Period) - Math.Sqrt(Period)) <= 0.5)
    { SqrRootLength = Math.Sqrt(Period );}
    else
    {SqrRootLength = Math.Sqrt(Period);}

    Value1.Set(
    2 * T3(Price,0.7,HalvedLength)[0]);
    Value2.Set(T3(Price,
    0.7,Period)[0]);
    Value3.Set(Value1[
    0]-Value2[0]);

    Rising.Set(T3(Value3,
    0.7,SqrRootLength)[0]);

    The problem is that my HalvedLength and SqrRootLength must be integer since they are T3 moving average parameters and the Math.Ceiling and .Floor can only be used with decimal or double.
    What should I do ?

    #2
    Can't you just cast to an int?

    HalvedLength = (int) Math.Floor(V1);
    RayNinjaTrader Customer Service

    Comment


      #3
      This is weird because the floor of a number is an integer...why does the Math.Floor function return a double ?
      That is simply illogic

      Comment


        #4
        it works !!!

        thank you very much, you're my savior

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,221 views
        0 likes
        Last Post xiinteractive  
        Started by andrewtrades, Today, 04:57 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        9 views
        0 likes
        Last Post FAQtrader  
        Working...
        X