Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Building Strategy where I only trade when Stochastics is between 10 and 60

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

    #16
    Hello Ken,

    Thanks for your post and question.

    To rename a strategy:

    1) Select Tools>Edit NinjaScript>Strategy

    2) Select the strategy to copy/rename

    3) In the "Edit strategy" window, click on "view code" button

    4) After the code window opens, right mouse click on a blank area of the code and select "Save As" and enter a new name.

    5) A caution window will appear, click "Okay"

    6) Close the code window by clicking on the upper right window close "X".

    7) After closing the code window you will be returned to the "Edit Strategy" window, click on "cancel" to conclude the process.

    8) Now when you Tools>Edit NinjaScript>strategy, your new strategy will appear as a selection and you can continue to make changes through the wizard.


    Please let me know if I can be of further assistance.

    Comment


      #17
      Paul, thanks the copy process worked fine, I tried to do it with the indicators but that one does not show up in the listing. Anyway to copy an indicator?

      - I would like to exit all trades on Friday @ 410pm, I am sure there is some way to do this?

      - currently I have it exiting trade at macd crossbelow or upper keltner channel but would like to have it exit at macd crossbelow only if an minimum of $12.50 earned. Any way of doing this.

      - the slope values you gave me for the macd exiting, what do they stand for and how do I tweak them?

      - Where do I change the 256 to infinite for the keltner channel?

      Thanks again, I this is a great way of learning to write code in ninjatrader... I have been using your code example in other ways as well. As well you have put great effort in to getting a quick turn around time....

      Ken

      Comment


        #18
        Hi ken,

        Thanks for your post and comments, glad that you are gaining benefit.

        Answers are in order of your questions:

        Regarding copy/renaming indicators it is slightly different. Go to Tools>Edit NinjaScript>Indicators and select the indicator to copy/rename by double clicking it. That action will open the code file of the indicator. Right mouse click in an open space and select "Save As" and name the new indicator copy.

        The question about exiting all trades Friday at 4:10 PM needs clarity. You want to exit all trades regardless of position? Or are you saying you want to not enter any new trades after a certain time? If the later, would that be used daily, not just Friday?

        This question, "currently I have it exiting trade at macd crossbelow or upper keltner channel but would like to have it exit at macd crossbelow only if an minimum of $12.50 earned. Any way of doing this?" is a little more complicated. What do you do if it is not in profit? Are you using ATM strategies?

        The slope values in the wizard are based on comparing two points, in both cases the comparison is to the current bar, in one case the other end is 4 bars back, in the other case the end is 10 bars back. You would basically alter the 4 and 10 to "tweak" the slope measurements themselves and then understand that as set up in the wizard they are being compared short term (4 bars) to the longer term (10 bars). You will need to spend some time finding what works best for you. Slope is basically the steepness of a line. To help you with understanding slope, here is a link that gives a great visual that you can dynamically adjust: http://www.mathopenref.com/coordslope.html

        The lookback period is changed for the strategy in the parameters window. I have attached a picture that shows the selection area. The red rectangle shows the existing, default, 256 bar lookback, the green rectangle shows the selection changed to the only other choice of infinite (or rather, all of the data, no limit). You have to click on the 256 wording to get the dropdown arrow.

        I look forward to your reply.

        Comment


          #19
          Regarding copy/renaming indicators it is slightly different. Go to Tools>Edit NinjaScript>Indicators and select the indicator to copy/rename by double clicking it. That action will open the code file of the indicator. Right mouse click in an open space and select "Save As" and name the new indicator copy.
          This worked fine for me this time, not sure why it didn't seem to work the first time. I can see both of the copies now.

          The question about exiting all trades Friday at 4:10 PM needs clarity. You want to exit all trades regardless of position? Or are you saying you want to not enter any new trades after a certain time? If the later, would that be used daily, not just Friday?
          I want to exit all trades regardless of position, only on Friday at 410pm

          This question, "currently I have it exiting trade at macd crossbelow or upper keltner channel but would like to have it exit at macd crossbelow only if an minimum of $12.50 earned. Any way of doing this?" is a little more complicated. What do you do if it is not in profit? Are you using ATM strategies?

          I am using atm, and if no profit exit on stoploss but not macd crossbelow. If profit of $12.50 exit on macd crossbelow.

          The slope values in the wizard are based on comparing two points, in both cases the comparison is to the current bar, in one case the other end is 4 bars back, in the other case the end is 10 bars back. You would basically alter the 4 and 10 to "tweak" the slope measurements themselves and then understand that as set up in the wizard they are being compared short term (4 bars) to the longer term (10 bars). You will need to spend some time finding what works best for you. Slope is basically the steepness of a line. To help you with understanding slope, here is a link that gives a great visual that you can dynamically adjust: http://www.mathopenref.com/coordslope.html

          I want to look back 2 bars and 1 bar and get the slope between the two, and compare to the slope of 1 bar back and current.

          The lookback period is changed for the strategy in the parameters window. I have attached a picture that shows the selection area. The red rectangle shows the existing, default, 256 bar lookback, the green rectangle shows the selection changed to the only other choice of infinite (or rather, all of the data, no limit). You have to click on the 256 wording to get the dropdown arrow

          You forgot attachement

          Comment


            #20
            Hello Ken,

            The ability to close all positions each Friday is not a function contained within the strategy wizard, to perform that action you would need to go into the NinjaScript code itself and write that part of the program. At that point you would no longer be able to edit the strategy in the wizard builder. This would be a fairly advanced process if you are unfamiliar with C# and NinjaScript.

            You wrote, "I am using atm, and if no profit exit on stoploss but not macd crossbelow. If profit of $12.50 exit on macd crossbelow." To exit at breakeven+1 you could use the "breakeven" stop strategy within the ATM. While this doesn't match with your desire to go auto breakeven based on Macd it is one way to protect yourself when price start to go back against you. Here is a link to the help guide on auto breakeven. http://www.ninjatrader.com/support/h..._breakeven.htm

            Yes, I missed the attachment for the lookback period, it is attached this time.

            Please let me know if I can be of further assistance.
            Attached Files

            Comment


              #21
              This question, "currently I have it exiting trade at macd crossbelow or upper keltner channel but would like to have it exit at macd crossbelow only if an minimum of $12.50 earned. Any way of doing this?" is a little more complicated. What do you do if it is not in profit? Are you using ATM strategies?

              Im not using atm, if no profit, stay in trade until profit or other (exit at upper keltner channel) exit strategy.

              - When I do backtest I have a vertical line drawn when I enter a trade, and a colored line based upon exit strategy when I exit a trade. It works fine in back testing, but on live chart none of them work. using same 600 tick chart. any ideas?

              - How do I create pivot highs and pivot lows from the price data and be able use them in my strategy; and how do I plot them on the price chart during back testing and on live chart?

              Again Thanks for your help....
              Ken

              Comment


                #22
                Hi Ken,

                Thanks for your post.

                For your strategy you can add a trailing stop in the strategy wizard.

                Regarding the backtesting lines, the colored lines show the distance from entry to exit and are produced in backtesting only and are not related to your strategy. I am not sure about the vertical line, please send a screen shot.

                Pivot highs and lows mean different things to different people. There are pivot points based on yesterdays data, there are current days OHL and there is the swing indicator. Can you clarify what you mean (it may be easier to mark up a chart)?

                I look forward to your reply.

                Comment


                  #23
                  These line draw in back test but do not draw on live 600 chart. see attached
                  Attached Files

                  Comment


                    #24
                    Hi Ken,

                    Thanks for the post and the chart picture.

                    I don't know what the source of the vertical lines are. Can you share your strategy code so that I might better understand what is drawing the lines in backtesting and then why they are not being applied to live conditions? If you don't wish to post the strategy, please e-mail it to [email protected] with atten: Paul and a link to this thread.

                    The strategy file would be located in your documents NinjaTrader7>bin>custom>Strategy folder

                    I look forward to your reply.

                    Comment


                      #25
                      hope the attachment helps
                      Attached Files

                      Comment


                        #26
                        Hi Ken,

                        Thanks for your screen shots of the strategy builder showing the conditions to draw the vertical lines in tab 1 and tab 3. I replicated these and was able to verify that the lines show up in backtesting as well as market replay and live data with no issues. In order to understand what you are seeing I need you to send or post the actual code file for the strategy. The file can be found under Documents>NinjaTrader7>Bin>Custom>Strategy It will have the name of your strategy for the file name.

                        I look forward to your reply.

                        Comment


                          #27
                          here is a sample of a simple code that works in backtesting and no t on live chart.
                          Attached Files

                          Comment


                            #28
                            Hi Ken,

                            Thank-you for sending your sample strategy.

                            I tested it in the strategy analyzer, market replay and on live charts this morning. What I see, on all type charts:
                            • Blue vertical line on long entry.
                            • When there is a profit target hit, there is no vertical exit line.
                            • When I see a stop loss there may or may not be a vertical brown line.
                            • I see a vertical brown line whenever the MACD crosses down.


                            I reviewed the code and looked at it through the strategy wizard. Starting in the Conditions and Actions window:

                            Set 1 - You have the conditions of: MACD of the EMA 3 crossing above then the actions of: Enter long 2 contracts and place a Blue vertical line. The line is placed in all cases on all charts. There is no check to see if you are already in a position.

                            Set 2 - You have the conditions of: MACD of the EMA 3 crossing below, check that Position.MarketPosition == Position.MarketPosition (does nothing because it is like saying Apple=Apple) then Actions of: ExitLong and draw a brown vertical line. So in this set, the brown line is drawn whenever the MACD crosses below regardless of being in a trade or not. So in some cases the brown line may happen to match up with being in a trade. To ensure it is only in a trade in progress, change your Position.MarketPosition == Position.MarketPosition to Position.MarketPosition == MarketPosition.Long. Making that change will ensure that a brown line is drawn when the MACD crosses below AND you are in a Long trade.

                            You have set a profit target and stop loss. When either of those condition occur, no line is being drawn because there is no action to. Occasionally you will find that the MACD crosses below and the stop loss coincide causing the Brown line to be drawn at the stop loss exit.

                            In summary, as the sample strategy stands, you will always see a blue entry line, you will always see a brown line when the MACD crosses below.

                            I hope this answers your questions.

                            Please let me know if I can be of further assistance.

                            Comment


                              #29
                              Paul, Thanks for your response,
                              you said:

                              Set 1 - You have the conditions of: MACD of the EMA 3 crossing above then the actions of: Enter long 2 contracts and place a Blue vertical line. The line is placed in all cases on all charts. There is no check to see if you are already in a position.

                              How would I add the code to check if I am already in a position?

                              If I am already in a position why is there a need to check? Is there a problem with drawing the line again?

                              You have set a profit target and stop loss. When either of those condition occur, no line is being drawn because there is no action to. Occasionally you will find that the MACD crosses below and the stop loss coincide causing the Brown line to be drawn at the stop loss exit.

                              How do I draw a line when I exit on the stop loss?:

                              How do I draw a line when I exit on the profit target?

                              In my backtest chart line are there BUT on live chart my lines are not drawing....
                              I have a support call in for 2pm today about another issue for not being able to change a trade on the superdom. Shall I ask them about this as well it may be related.

                              Comment


                                #30
                                Hi Ken,

                                Regarding the position check, here is the code: Position.MarketPosition == MarketPosition.Long. I've attached a picture of the strategy builder conditions section to illustrate how to set up the check to see if you are in MarketPosition.Long.

                                In set 1 you would want to check that you are not already in a position to ensure that you don't unintentionally ADD to the position (unless of course you want to ADD to the position).

                                Regarding drawing a vertical line when your profit target or stop is hit is not possible within the strategy builder when you are using the Stop and Targets window to enter your optional stops and targets. You have two options; 1) using the strategy builder, create a new set of conditions/actions that exit at a target or a stop loss and draw the line or; 2) You would need to go into the code itself to add that. Keep in mind once you unlock the code to add the vertical lines you would no longer be able to use the strategy builder on that strategy.

                                Yes, as we are calling you certainly can ask.

                                Please let me know if I can be of further assistance.
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                648 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                369 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                108 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                572 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                573 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X