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 algospoke, 04-17-2024, 06:40 PM
            6 responses
            49 views
            0 likes
            Last Post algospoke  
            Started by arvidvanstaey, Today, 02:19 PM
            4 responses
            11 views
            0 likes
            Last Post arvidvanstaey  
            Started by samish18, 04-17-2024, 08:57 AM
            16 responses
            61 views
            0 likes
            Last Post samish18  
            Started by jordanq2, Today, 03:10 PM
            2 responses
            9 views
            0 likes
            Last Post jordanq2  
            Started by traderqz, Today, 12:06 AM
            10 responses
            21 views
            0 likes
            Last Post traderqz  
            Working...
            X