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

Getting Close[0] when conditions met

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

    Getting Close[0] when conditions met

    Hello,
    I'm wondering if someone can give me an idea of how to capture the Close[0] when a condition is met and then record that data for future use? Thanks

    #2
    Hello CaptainAmericaXX,

    Are you going to be using the Strategy Wizard to create this strategy or are you creating with some custom code?

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hello JC. Custom code, but I get a lot of hand holding.

      Comment


        #4
        Originally posted by CaptainAmericaXX View Post
        Hello,
        I'm wondering if someone can give me an idea of how to capture the Close[0] when a condition is met and then record that data for future use? Thanks
        Code:
         
        private double CaptainAmericaMegaBucksPrice = -1;
        Code:
         
        if (ConditionMet && CaptainAmericaMegaBucksPrice < 0)
        {
        CaptainAmericaMegaBucksPrice = Close[0];
        }
         
        MakeMegaBucks(CaptainAmericaMegaBucksPrice, ...);
         
        if (PositionHasBeenClosed || WeNeedToReset)
        {
        CaptainAmericaMegaBucksPrice = -1; //or whatever the initial unset value is supposed to be.
        }

        Comment


          #5
          koganam, you're awesome! I swear if I ever start making money trading I'm going to send you a check!
          I tried to follow your advice. I'm ok at plugging what others give me, but not very good at figuring it out myself. Here is what I have so far:

          Code:
          private double closeprice = -1;
          Code:
          if (CrossAbove(RSMarketDirection(12).UpTrend, RSMarketDirection(12).SMALine, 1) && vcloseprice < 0)
                      {
                          closeprice = Close[0];
                      }
                  
                  MakeMegaBucks(closeprice);
                  
                  if (PositionHasBeenClosed || WeNeedToReset)
                      {
                      closeprice = -1; 
                      }
          So what I want to do is capture the Close[0] at the CrossAbove. I then want to look back x amount of bars to see if there was a cross at that exact price. Is what you gave me along those lines? I especially like the "MakeMegaBuck" (I know you just made that up), but I have to admit I don't have the foggiest idea what that line is going to accomplish. Do you have some more advice?

          Comment


            #6
            Originally posted by CaptainAmericaXX View Post
            koganam, you're awesome! I swear if I ever start making money trading I'm going to send you a check!
            I tried to follow your advice. I'm ok at plugging what others give me, but not very good at figuring it out myself. Here is what I have so far:

            Code:
            private double closeprice = -1;
            Code:
            if (CrossAbove(RSMarketDirection(12).UpTrend, RSMarketDirection(12).SMALine, 1) && vcloseprice < 0)
                        {
                            closeprice = Close[0];[COLOR=blue] //good enough[/COLOR]
                        }
             
                    MakeMegaBucks(closeprice); [COLOR=blue]//this just represents all the stuff that you want to do with the information that you have captured above. It was just a placeholder.[/COLOR]
             
                    if (PositionHasBeenClosed || WeNeedToReset) [COLOR=blue]//this is just a description of when you want to reset your variable, so that you do not have unintended side effects.[/COLOR]
                        {
                        closeprice = -1; 
                        }
            So what I want to do is capture the Close[0] at the CrossAbove. I then want to look back x amount of bars to see if there was a cross at that exact price. Is what you gave me along those lines? I especially like the "MakeMegaBuck" (I know you just made that up), but I have to admit I don't have the foggiest idea what that line is going to accomplish. Do you have some more advice?
            Pretty much. Once you have captured the price of interest, all you need to do is call another method to see if your condition is filled. In this case, I would use the MIN() and MAX() classes to find the MIN and MAX values starting from the bar on which I captured closeprice, and going back your x number of bars. If MIN is below the cross line, and MAX is above it, then there was at least one cross.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by aligator, 01-06-2022, 12:14 PM
            4 responses
            233 views
            0 likes
            Last Post john_44573  
            Started by reynoldsn, Today, 05:56 PM
            0 responses
            4 views
            0 likes
            Last Post reynoldsn  
            Started by bortz, 11-06-2023, 08:04 AM
            51 responses
            1,989 views
            0 likes
            Last Post aligator  
            Started by dmking, 11-12-2019, 12:31 PM
            4 responses
            4,150 views
            0 likes
            Last Post jasonw
            by jasonw
             
            Started by roblogic, Today, 04:31 PM
            0 responses
            10 views
            0 likes
            Last Post roblogic  
            Working...
            X