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

Addition of Input Variables

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

    Addition of Input Variables

    Hi,
    I want to create a crossover where period 1 (P1) is always smaller than the second one. To get this I thought I could simply add P1 and P2 for the second value.
    For example: If P1 is 5 and P2 is 3 I would create a cross of 5 and 8.
    Somehow my code does not work. The addition does not work.
    How do I fix it?


    Code:
            protected override void Initialize()
            {
                Add(SMA(P1));
                Add(SMA(P2));
                
                
    
                CalculateOnBarClose = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set 1
                if (CrossAbove(SMA(P1), SMA(P1+P2), 1))
                {
                    EnterLong(DefaultQuantity, "");
                }
    
                // Condition set 2
                if (CrossBelow(SMA(P1), SMA(P1+P2), 1))
                {
                    EnterShort(DefaultQuantity, "");
                }
    
            }

    #2
    moon_121, how do you judge that it would not work? Have you charted the P1+P2 SMA as well to confirm signals triggered by this logic?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Change
      Add(SMA(P1));
      Add(SMA(P2));

      to
      Add(SMA(P1));
      Add(SMA(P1+P2));

      Comment


        #4
        Thanks Baruch. That works fine! I knew I overlooked something simple.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by WHICKED, Today, 12:56 PM
        0 responses
        2 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by Spiderbird, Today, 12:15 PM
        2 responses
        10 views
        0 likes
        Last Post Spiderbird  
        Started by WHICKED, Today, 12:45 PM
        0 responses
        7 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by FrazMann, Today, 11:21 AM
        2 responses
        6 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by rjbtrade1, 11-30-2023, 04:38 PM
        2 responses
        80 views
        0 likes
        Last Post DavidHP
        by DavidHP
         
        Working...
        X