Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Where to start if I want to create a strategy on a trading set-up?

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

    #76
    Oh, I almost forgot to share a good news with you Ryan! I finally have a trail code that WORKs ... after 3+ weeks of in-depth search + my heart has broken into million of pieces on the myth ..

    Comment


      #77
      Hi Belecona,

      Good to hear you got a working Trail stop.

      Your code won't work because you're comparing two values that will always be the same. Low[0] and Low[0].

      The snippet below looks closer to your english description.
      Code:
       
       
      if (CrossBelow(Low, MIN(Low, 2)[1],1))

      That will return true if, within the last bar, the low has crossed below the previous lowest two values. The MIN expression is displaced by one bar[1], so it will look at the two bars prior to the one you're testing the condition for.
      Ryan M.NinjaTrader Customer Service

      Comment


        #78
        Thanks Ryan.

        Your suggested snippet looks Great! For another Exit condition for a short position, ie when price is going above the highest high of the last 3 price bars, will the following be fine:

        if (CrossAbove(High, MIN(High, 3)[1],1))

        Please enlighten me again! Thank you.

        Comment


          #79
          That's close, but you need the HIGHEST value, and this is done with MAX function, not MIN.

          Code:
           
          if (CrossAbove(High, MAX(High, 3)[1],1))
          Ryan M.NinjaTrader Customer Service

          Comment


            #80
            You got me Ryan! Now you know I do not have a strong programming background LOL!

            Thank you very much. No knock knock this afternoon. Take care and enjoy a Lovely evening.

            Comment


              #81
              Good morning Ryan

              Need your help please! I would like to add an audio to the strategy so that I can validate the signal promptly. Please confirm the following:

              1. Do I have the sound code and its location right?
              Code:
              EnterLong();
              PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Long.wav");
              2. Will the sound code delay the trade entry?

              Thank you. Have a Great day.

              Comment


                #82
                1) There isn't a preinstalled sound file called long.wav. Unless you had placed an additional file in this directory I wouldn't expect anything to play.

                2) The sound file won't delay your entry.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #83
                  Yes Ryan. I do have a long.wav file in the sound folder. Actually, I've found a site where I can create wav files with any wordings I want .. smile .. I gather from your response that I do have sound code/location in good order. Please correct me if I'm wrong. Thank you!

                  Comment


                    #84
                    Good morning Ryan

                    Need your help please. I added an audio alert to my strategy so that I may get out of a trade when it starts looking bad. Funny that the alert was triggered even when I was not in a position.

                    Code:
                    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Position.MarketPosition == MarketPosition.Long
                    && [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]<Bollinger(Close,[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0.9[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]12[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]).Upper[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]])
                    { 
                    PlaySound([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]@"C:\Program Files\NinjaTrader 6.5\sounds\d9exitlong.wav"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);
                    }
                    [/SIZE][/FONT][/SIZE][/FONT]
                    Good news is the audio file works but it's still irritating. Please help! Thanks. Have a Great day.

                    Comment


                      #85
                      It's possible there was a strategy position.
                      See here for information on Strategy Position versus Account Position.

                      You can use Print statements to debug values. Verify what NinjaTrader believes is the current market position using the statement:
                      Code:
                       
                      Print(Position.MarketPosition.ToString());
                      See here for information on debugging your NS code.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #86
                        Thanks Ryan for your prompt response. I have other strategies running and did have some long trades going on when the alert was triggered. Guess the system look at my overall position (incl other strategies) and NOT just the audio strategy. Are there ways around it or I have to do my testing on another computer?? Please advise. Thank you.

                        Comment


                          #87
                          There is no cross-communication among strategies. Strategies are not aware of positions opened outside of their particular strategy instance.
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #88
                            Hi Ryan

                            It's been a few months since my last knock. Believe your spring has been a good one. Here in Ontario Canada was a short and warm one. Now it's summer.

                            You will be glad to learn that after months of research and non-stop strategy fine-tuning/creation, I believe I have a profitable strategy to run .. haha .. Before running it on live, I would like to add a code to limit one trade per day and not stopping the strategy manually. I went through your posts and am currently looking at the SampleTradeLimiter strategy which I downloaded from the suggested link. Please confirm I have the codes in the right place. Is there a way to test it before running the revised strategy in live? Appreciate very much your guidance.

                            Code:
                            #region Variables
                            [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] tradeCounter = [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000];[/COLOR][/SIZE][/FONT][/SIZE][/FONT]
                            [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] maxTrades = 1[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT][/SIZE][/FONT]
                            [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][/SIZE][/FONT][/SIZE][/FONT] 
                            [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]protected override void OnBarUpdate()[/SIZE][/FONT][/SIZE][/FONT]
                            [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// Reset the tradeCounter value at the first tick of the first bar of each session.
                            [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Bars.FirstBarOfSession && FirstTickOfBar)
                            tradeCounter = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];
                            
                            [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// If the amount of trades is less than the permitted value and the position is flat, go on to the next set of conditions.
                            [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (tradeCounter < MaxTrades && Position.MarketPosition == MarketPosition.Flat)[/SIZE][/FONT][/SIZE][/FONT]
                            [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][/SIZE][/FONT][/SIZE][/FONT] 
                            [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]#region Properties[/SIZE][/FONT][/SIZE][/FONT]
                            [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][Description([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Maximum number of trades to take per day."[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])]
                            [Category([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Parameters"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])]
                            [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] MaxTrades
                            {
                            [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]get[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] { [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] maxTrades; }
                            [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]set[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] { maxTrades = Math.Max([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], value); }
                            }[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]

                            Comment


                              #89
                              Hi Belecona,

                              Welcome back to NinjaTrader!

                              Yes, the snippet you shared looks like it has a trade counter check. You might need a space inbetween private and int for your variable declaration.

                              One additional step is that the counter adds one each time an entry signal is generated.

                              From the sample:
                              Code:
                              if (CurrentDayOHL().CurrentLow[0] < CurrentDayOHL().CurrentLow[1])
                                  {
                                   tradeCounter++;
                                   EnterShort();
                                  }


                              There are many options you can use to test this strategy before going live:
                              • Run a backtest
                              • Apply the strategy to a chart and verify the plot executions
                              • Run live against a simulated account.
                              • Run in market replay.
                              Ryan M.NinjaTrader Customer Service

                              Comment


                                #90
                                Thanks Ryan. You're Swift (as always)!

                                I saw your additional code in the sample script (for EnterShort and EnterLong). I don't understand until now, ie I MUST add tradeCounter++; to my Long and Short conditions. Please correct me if I get it wrong.

                                My trillion thanks again.

                                Have a Nice evening.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                651 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                370 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                109 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                574 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                577 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X