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

converting the price of a trigger to an double

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

    converting the price of a trigger to an double

    How do I convert a trigger into a double that I can use to make an additional if statement with for a 2 method trigger. Please provide the syntax for this. Thanks you.

    For example:

    if(MACD(Closes[2], 12, 26, 9).Avg[0] > 0) && Close[0] > Close[1])
    {
    triggerone = thecurrent price level
    }

    if(close[0] > trigger1)
    { bull alert goes out}

    #2
    Hello gordongekko,

    Thanks for your post.

    You would need to have declared the variable as a double. private double triggerone;

    Then you can:
    if(MACD(Closes[2], 12, 26, 9).Avg[0] > 0) && Close[0] > Close[1])
    {
    triggerone = Close[0]; // assign the close price of the current bar to triggerone.
    }

    if(close[0] > trigger1)
    { bull alert goes out}
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      If I do this will the value of the price attached to this double remain static as in stay the same price it was on the current close at that point in time? So for example, 5 bars later when the the current 0 bar has a different closing price this double will still be assigned the value of the price at the time that method was executed until it executes again and changes this value. Is this correct?

      Also how do I reset the value to null/0 using an additional boolean condition once the 2nd trigger has finished and the alert goes out? Or do i even need to do that since I'm assuming if first method is run again it will just overwrite that old value.

      Comment


        #4
        Hello gordongekko,

        Thanks for your reply.

        Correct, the variable would remain the same until it is changed. If your conditions never permit it will never change. If they permit on the next bar it will change on the next bar.

        You could reset like (assuming this is your second trigger):

        if(close[0] > trigger1)
        {
        //bull alert goes out
        triggerone = 0.0; // reset to zero.
        }
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          when you declare a double do you need to use a decimal?

          private double triggerone = 0.0; ?

          Comment


            #6
            Hello gordongekko,

            Thanks for your reply.

            Please see the educational resources here: https://ninjatrader.com/support/help...sic_syntax.htm
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by i019945nj, 12-14-2023, 06:41 AM
            5 responses
            64 views
            0 likes
            Last Post i019945nj  
            Started by ruudawakening, Today, 12:58 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by thread, Yesterday, 11:58 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by stafe, Yesterday, 08:34 PM
            1 response
            16 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by jclose, Yesterday, 09:37 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X