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 with trade signal

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

    Problem with trade signal

    In my strategy, i have "calculate on intrabar" (not at end). I think what happens with that is with each tick inside that bar, a new signal is generated, so with each tick a new position is being ordered. i do have maximum of 5 contracts per direction set. So in a way, 5 trades are occuring within that one bar. Is there anyway I can set it, so the signal is generated on intrabar basis but order is filled only once within that bar (not necessarily at the end oif the bar), so that the second trade will occur only on a new signal generated by another bar. Thanks.

    #2
    Add yourself more conditions to the entry condition. You could use something like BarsSinceEntry().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      How exactly do i do this?

      Comment


        #4
        Say you have Close[0] > Open[0] as your entry condition. Now you just add it within your if-statement.

        Code:
        if (Close[0] > Open[0] && BarsSinceEntry() > 0)
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Help in the attached file

          Josh, Thank you. I am really not sure how to proceed with this. I have attached the strategy here, can you please tell me exactly where and what should be added. I had to delete somed of the text from the file because the attachmentr thing kept saying file too big, i hope i have not deleted any important parts. Thanks.
          Attached Files

          Comment


            #6
            Code:
            [COLOR=blue][FONT=&quot]if[/FONT][/COLOR][COLOR=black][FONT=&quot] (CrossAbove(Stochastics([/FONT][/COLOR][COLOR=purple][FONT=&quot]7[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]14[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot]).K, Stochastics([/FONT][/COLOR][COLOR=purple][FONT=&quot]7[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]14[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot]).D, [/FONT][/COLOR][COLOR=purple][FONT=&quot]1[/FONT][/COLOR][COLOR=black][FONT=&quot])[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]     && MAX(Stochastics([/FONT][/COLOR][COLOR=purple][FONT=&quot]7[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]14[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot]).K, [/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot])[[/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]] < [/FONT][/COLOR][COLOR=purple][FONT=&quot]20[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]     && MAX(VOL(), [/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot])[[/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]] >= [/FONT][/COLOR][COLOR=purple][FONT=&quot]120000[/FONT][/COLOR][COLOR=black][FONT=&quot])[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]{[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]      DrawArrowUp([/FONT][/COLOR][COLOR=maroon][FONT=&quot]"My up arrow"[/FONT][/COLOR][COLOR=black][FONT=&quot] + CurrentBar, [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot], Low[[/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]] + -[/FONT][/COLOR][COLOR=purple][FONT=&quot]8[/FONT][/COLOR][COLOR=black][FONT=&quot] * TickSize, Color.Turquoise);[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]      EnterLong(DefaultQuantity, [/FONT][/COLOR][COLOR=maroon][FONT=&quot]""[/FONT][/COLOR][COLOR=black][FONT=&quot]);[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]}[/FONT][/COLOR]
            This is what you have right now. You can just try adding it into that condition like so
            Code:
            [COLOR=blue][FONT=&quot]if[/FONT][/COLOR][COLOR=black][FONT=&quot] (CrossAbove(Stochastics([/FONT][/COLOR][COLOR=purple][FONT=&quot]7[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]14[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot]).K, Stochastics([/FONT][/COLOR][COLOR=purple][FONT=&quot]7[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]14[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot]).D, [/FONT][/COLOR][COLOR=purple][FONT=&quot]1[/FONT][/COLOR][COLOR=black][FONT=&quot])[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]     && MAX(Stochastics([/FONT][/COLOR][COLOR=purple][FONT=&quot]7[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]14[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot]).K, [/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot])[[/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]] < [/FONT][/COLOR][COLOR=purple][FONT=&quot]20[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]     && MAX(VOL(), [/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot])[[/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]] >= [/FONT][/COLOR][COLOR=purple][FONT=&quot]120000
                [/FONT][/COLOR][SIZE=4][COLOR=Red][FONT=&quot]&& BarsSinceEntry() > 0[/FONT][/COLOR][/SIZE][COLOR=black][FONT=&quot])[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]{[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]      DrawArrowUp([/FONT][/COLOR][COLOR=maroon][FONT=&quot]"My up arrow"[/FONT][/COLOR][COLOR=black][FONT=&quot] + CurrentBar, [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR][COLOR=black][FONT=&quot], [/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot], Low[[/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]] + -[/FONT][/COLOR][COLOR=purple][FONT=&quot]8[/FONT][/COLOR][COLOR=black][FONT=&quot] * TickSize, Color.Turquoise);[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]      EnterLong(DefaultQuantity, [/FONT][/COLOR][COLOR=maroon][FONT=&quot]""[/FONT][/COLOR][COLOR=black][FONT=&quot]);[/FONT][/COLOR]
            [COLOR=black][FONT=&quot]}[/FONT][/COLOR]
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh, Thank you very much. Question on logistics: I go to tools- edit ninjascript- strategy - select the strategy to edit - then in the editor I click on view code. The code page appears. Is this where the changes are made because i tried and i cannot typeover the existing text. Is there something else i am supposed to do before i can type over?

              Comment


                #8
                If your strategy is still in the Strategy Wizard you cannot edit your code. You will need to press the "Unlock Code" button before you can edit your code. If you press the Unlock Code button you will not be able to use the Strategy Wizard's Condition Builder any more. Please make sure you are done with everything you want to do from the Wizard before doing proceeding.

                Alternatively, you can just add the condition via the condition builder. You will find the "Bars since entry" available in the "Misc" section. Just select that from the left side and select > in the middle and "Misc: -> "Numeric value" -> 0 on the right side.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Did not work

                  It did not seem to work. I applied it like you said. This removed all the signals from the chart. I have not watched it long enough to see what happens in real time, but at least the signals that were present before making this change are not there. According tothe other conditions in this set, there should be buys and sells at least one trade for each of the signals.

                  Comment


                    #10
                    Please post screenshots of your code/Condition Builder settings.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      On my computer for some reason I cannot get a screen shot, it just come out black/gray. I will write out exactly what i have on my "Conditions and Actions" screen:

                      SET 1
                      When the following conditions are true:

                      CrossAbove{Stochastics(7,14,3})K, Stochastics(7.14.3),D, 1}
                      MAX{VOL()>120000
                      MAX{Stochastics(7,14,3),K,3)(0) <20
                      BarsSinceEntry() > 0

                      Do the following:

                      DrawArrowUp{"My Up Arrow" + CurrentBar, True, 0, low(0) + -8 * TickSize, Color.Turquoise
                      EnterLong(DefaultQuantity,"")

                      Comment


                        #12
                        Ok. Here is the deal. On the very first trade BarsSinceEntry() will not be greater than 0 and if the very first trade is never entered BarsSinceEntry() will never be greater than 0.

                        Essentially you will need two Sets then. In Set 1 you want to remove BarsSinceEntry() from the conditions. Instead you want to add a condition that says Variable0 == 0. In the actions you want to add one that sets Variable0 = 1. You can find Variable0 under the "User defined variables" category.

                        Now in Set 2, you want to copy what you had in Set 1. This time remove the Variable0 from both the condition and action halves. In the condition add the BarsSinceEntry() > 0.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          On the action side, there is no option of variable to pick from?

                          Comment


                            #14
                            In "Misc", Set user defined variables.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Right now I have set one for the long side strategy and set 2 for the short. Can I still have the short strategy still within this strategy as sets 3 and 4 or should i put that in a totaly separate strategy.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Barry Milan, Today, 10:35 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by WeyldFalcon, 12-10-2020, 06:48 PM
                              14 responses
                              1,428 views
                              0 likes
                              Last Post Handclap0241  
                              Started by DJ888, Yesterday, 06:09 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              40 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Today, 08:51 AM
                              2 responses
                              16 views
                              0 likes
                              Last Post bill2023  
                              Working...
                              X