Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA crossover and Calculate on bar close FALSE

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

    #31
    They all involve adjusting the strategy parameters to somehow ensure that the virtual order that is turning the strategy yellow, does not get taken.
    Or just exit immediately.

    Comment


      #32
      Koganam:

      Could you post example code of what one would use to force the strategy to go green if "Wait until flat before executing live" is selected and the instrument would otherwise be yellow waiting for it to go flat before going green?

      This would allow those to take the next valid signal in the real account...

      Comment


        #33
        Originally posted by birdog View Post
        Koganam:

        Could you post example code of what one would use to force the strategy to go green if "Wait until flat before executing live" is selected and the instrument would otherwise be yellow waiting for it to go flat before going green?

        This would allow those to take the next valid signal in the real account...

        One way is to use a time filter to start trading. Set the filter to start trading later than the virtual trade was taken. That way the trade is not valid, and so the strategy is flat when enabled.

        Another approach that I have used is detailed in this post: http://www.ninjatrader.com/support/f...31&postcount=4

        In either case, remember to reset to defaults at EOD. That is why it is somewhat cumbersome as a workaround.

        Comment


          #34
          Koganam:

          Do you have a some good code for time filtering?

          Actually, would like to add time filters so that they show up in the Parameters so they can be set upon enabling if possible?

          Greg
          Last edited by birdog; 02-12-2013, 04:06 PM.

          Comment


            #35
            Originally posted by birdog View Post
            Koganam:

            Do you have a some good code for time filtering?

            Actually, would like to add time filters so that they show up in the Parameters so they can be set upon enabling if possible?

            Greg
            NT has a reference sample: http://www.ninjatrader.com/support/f...ead.php?t=3226

            Comment


              #36
              Koganam:

              could you show how you would use if (BarsInProgress != 0) and if (BarsInProgress == 0) if you wanted to do the following along with any other necessary code to accomplish with multiple time indexes:

              Enter long if sma 8 crosses above sma 20 (at the precise point of cross over only...as you called it explicit) on the primary bars (index 0), BUT only if index 1 and index 2 (say 5 min and 60 min respectively on bar objects) sma 8 is only above the sma 20 only relatively on the 5 and 60 min (the 8 only has to be somewhere above the 20)? and vice versa with shorts...how would you do it?
              Last edited by birdog; 02-12-2013, 07:51 PM.

              Comment


                #37
                Originally posted by birdog View Post
                Koganam:

                could you show how you would use if (BarsInProgress != 0) and if (BarsInProgress == 0) if you wanted to do the following along with any other necessary code to accomplish with multiple time indexes:

                Enter long if sma 8 crosses above sma 20 (at the precise point of cross over only...as you called it explicit) on the primary bars (index 0), BUT only if index 1 and index 2 (say 5 min and 60 min respectively on bar objects) sma 8 is only above the sma 20 only relatively on the 5 and 60 min (the 8 only has to be somewhere above the 20)? and vice versa with shorts...how would you do it?
                You seem to be asking for the entire strategy to be written for you. As ingrates on this board have made me decide that I will no longer write complete indicators or strategies for anyone, I would suggest that you contact one of the NT partners or consultants. For the kind of strategy that you are describing, you are also probably going to need to track a few state variables, as well as error trapping.
                Last edited by koganam; 02-13-2013, 04:05 AM.

                Comment


                  #38
                  Koganam:

                  No...not at all...just was trying to figure out what I was doing wrong (there was a couple of pieces I was missing...but...

                  Actually, I got it working the way I wanted it last night...no problem Kog.

                  Also, I fixed the onbarupdate error so it works exactly how I was hoping...

                  There are not errors in the output or the log and everything is working perfectly (now all I will probably be doing is tweaking it or adding handling ideas in the future but I am happy with where it is at the moment as far as no errors and it running smoothly)...

                  Just looking for help not anyone to write the full code...that is what I am doing...smile...

                  I do appreciate your input from time to time and I hope to help folks as you do in the future...thanks!!!


                  Last edited by birdog; 02-13-2013, 07:15 AM.

                  Comment


                    #39
                    Koganam and/or anyone:

                    Is it possible to use both:

                    if (BarsInProgress != 0)

                    and

                    if (BarsInProgress == 0)

                    at the same time in the same code (I would be interpreting it if doing so to force it to look at the primary bars signals AND ALL the other index bars as well in order to fire (as I have 3 other EMAs I want in line on different bars before the primary fires...just want to be sure I am thinking right...may not...

                    Or, do I just use one or the other for this?



                    Greg

                    Comment


                      #40
                      Originally posted by birdog View Post
                      Koganam and/or anyone:

                      Is it possible to use both:

                      if (BarsInProgress != 0)

                      and

                      if (BarsInProgress == 0)

                      at the same time in the same code (I would be interpreting it if doing so to force it to look at the primary bars signals AND ALL the other index bars as well in order to fire (as I have 3 other EMAs I want in line on different bars before the primary fires...just want to be sure I am thinking right...may not...

                      Or, do I just use one or the other for this?



                      Greg
                      Absolutely: they force mutual exclusivity. In fact, it is the easiest way to force everything to calculate on only barSeries0, while reading data from any of the other barSeries.
                      Code:
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]#region[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Variables[/FONT]
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]private[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] NumLongEntries = [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]private[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] MaxLongEntries = [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]private[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]bool[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] MayEnterLong = [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]true[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]; [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]//or false if you prefer[/COLOR][/FONT]
                      [/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]#endregion[/COLOR][/FONT]
                      [/COLOR][/FONT]
                      Code:
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]protected [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]override [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Initialize()[/FONT]
                      [FONT=Courier New]{[/FONT]
                      [FONT=Courier New]Add(PeriodType.Minute, [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]10[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]);[/FONT]
                      [FONT=Courier New]Add(PeriodType.Minute, [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]30[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]);[/FONT]
                       [FONT=Courier New]}[/FONT]
                      Code:
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]protected [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]override [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]void [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]OnBarUpdate()[/FONT]
                      [FONT=Courier New]{[/FONT]
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (BarsInProgress != [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]) [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]; [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]//do nothing if not the primary bar series[/COLOR][/FONT]
                      [/COLOR][/FONT]
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (BarsInProgress == [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]) [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]//act only on primary barSeries[/COLOR][/FONT]
                      [/COLOR][/FONT][FONT=Courier New]{[/FONT]
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]bool[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] boolCond1 = CrossAbove(EMA(Typical, [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]5[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]), EMA(Typical, [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]10[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]), [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]); [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]//primary series EMA5 crossed above EMA10[/COLOR][/FONT]
                      [/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]bool[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] boolCond2 = EMA(Closes[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]10[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New])[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]] > EMA(Closes[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]20[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New])[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]]; [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]//10 minute EMA10 above EMA20[/COLOR][/FONT]
                      [/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]bool[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] boolCond3 = EMA(Closes[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]2[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]10[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New])[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]] > EMA(Closes[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]2[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]20[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New])[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]]; [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]//30 minute EMA10 above EMA20[/COLOR][/FONT]
                      [/COLOR][/FONT]
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (boolCond1 && boolCond2 && boolCond3 && MayEnterLong) [/FONT]
                      [FONT=Courier New]{[/FONT]
                      [FONT=Courier New]EnterLongLimit([/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]2[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], GetCurrentAsk(), [/FONT][FONT=Courier New][COLOR=#800000][FONT=Courier New][COLOR=#800000]"LongEntry-Opening"[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]);[/FONT]
                      [FONT=Courier New]NumLongEntries++;[/FONT]
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (NumLongEntries == MaxLongEntries) MayEnterLong = [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]false[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]; [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]//disable further entries [/COLOR][/FONT]
                      [/COLOR][/FONT][FONT=Courier New]}[/FONT]
                      [FONT=Courier New]}[/FONT]
                       
                      [FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]//How do you intend to exit? Write the code here, using Set methods or ExitLong() methods.[/COLOR][/FONT]
                      [/COLOR][/FONT]
                       
                      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (Position.MarketPosition == MarketPosition.Flat) [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]//probably want to add a time filter here.[/COLOR][/FONT]
                      [/COLOR][/FONT][FONT=Courier New]{[/FONT]
                      [FONT=Courier New]MayEnterLong = [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]true[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]; [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]//enable entries again.[/COLOR][/FONT][/COLOR][/FONT]
                      [FONT=Courier New][COLOR=#008000][COLOR=blue]NumLongEntries = 0;[/COLOR][/COLOR][/FONT][COLOR=#008000]
                      [/COLOR][FONT=Courier New]}[/FONT]
                      [FONT=Courier New]}[/FONT]
                      [/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT]
                      Last edited by koganam; 02-14-2013, 07:50 PM.

                      Comment


                        #41
                        Kog:

                        That is a piece of art...you make it very easy to understand now here...I understand that a lot better now...THANKS!!!

                        The short annotations made it click more than ever...big smile!!!



                        Greg

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        649 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
                        576 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X