Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to set alert based on MA cross?

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

    #16
    Thank you, I am getting ahead.

    Now, Continuation of the strategy. I want to set an exit strategy within the same strategy that i developed for the entry. So, after I finish setting the conditions and actions, clicking on "next" brings me to the next screen "stop loss & profit.." Trying to adding a target, it gives the only choice of percent or ticks etc.

    What I want to do is write a indicator based exit strategy like in the entry panel. I want to write an SMA based indicator that when triggered will close say an existing long position. Is there a way to do this?

    I have developed "SET 1" for the long entry and "Set 2" for the short entry. Currently it is "reverse" position situation, that is after a long a short trigger causes the long to close and at the same time initiates a short (and vice versa).

    If an exit strategy is written, then something needs to be added to the entry rules that will prevent the reverse positioning. Right? HOw?

    Thanks.

    Comment


      #17
      ju1234,

      Yes, you can add a market position check to your entries, that checks if you are flat before entering the position. This will prevent the reversal behavior.

      You then use a different set for the exit conditions. Define the conditions in a different set and then use either ExitLong() or ExitShort() for your exits.
      Last edited by NinjaTrader_RyanM1; 01-24-2011, 05:09 PM.
      Ryan M.NinjaTrader Customer Service

      Comment


        #18
        Thank you.

        As far as Checking for flat, should this be in the same set that has the enter short set or should it be in its own set.

        This is what i have done: Set one has the conditions for long and action of "enter long", set 2 has conditions and action for "enter short", set 3 has first line "market position == flat" and Next line lists the criteria for exit long and under action "exit long", set 4 is same as 3 except "exit short". Does it have to be in the order set 1, stuff from set 3 in set 2 (since that has to do with the long) and so on or the order of sets does not matter.

        I notice when doing the "Exit long" there are two parameters: "Signal name" and "From entry signal". Does anything have to be filled in these. Will the system not automatically label the signal as "closed long" on the chart? if something must be filled, In the "From entry signal" using the same name that was given to the "Entry signal", will that close that specific position only?

        Comment


          #19
          You will want to add market position check as a condition to both entry sets. (1 &2) If you don't want a reversal, the condition should check that you're flat for both entries.

          You don't have to use fromEntrySignal. If you don't type anything here, then it will apply to all entry conditions.
          Ryan M.NinjaTrader Customer Service

          Comment


            #20
            Ok. What i described earlier, with one correction, i put the check market flat in the "enter short " and "enter long" sets and not the exit sets.

            It seems to have worked. Couple of issues though: 1. When an initial long position is entered, it marks the chart with two arrows instead of one. One arrow at one bar (i assume the signal bar) and then an arrow under the next bar with a triangle pointing, i belied the price on the next bar. Is that what is supposed to happen? Is there anyway one of these can be removed (it just clutters the limited space on the chart). The only commands i have in this set is "draw an arrow" and on the second line "enter long" "play a sound" and no other actions.

            The "exit long" set produces only one label on the chart "sell 1 @ price" and only one arrow.

            ANOTHER question: Right now, the OIL chart is set for 24 hours, 12 AM to 12 AM. If i instead do a 7AM to 2PM time frame, will the open positions at 2 PM be automatically closed or do i have to set something for this to happen.

            Thanks.

            Comment


              #21
              Thank you.

              Another totally unrelated question: I had developed this strategy some time ago, i think i had just copied something from another strategy already existing in NT. Here is the entries from the Wizard screens (I have shortened the lines):

              Set 1:
              Conditions:
              CrossAbove(Sto K .... , Sto D
              Variable 0==0
              Max[vol(),5][0]>VariableVol

              Action:
              Draw arrow.......
              EnterLong....
              Variable0=1


              In SET 2:

              Conditions:
              Instead of the line: variable...... It reads BarsSinceEntry()>0

              In Actions: Everything is dame except line Variable ... is missing.

              Can you please explain the function of the "Variable...... " lines in these sets.

              This may be helpful to me because i am trying to build another strategy that is to utilize the variable thing.

              Thanks.

              Comment


                #22
                Hello,

                Sure the variable is just used as a flag.

                You can check in another set if Variable0= 0 or 1 and anything else and then take some action based on that. So its used as a way to torn on or off a flag or store a number that needs to be stored.

                As far as your previous post can you please add a screenshot so I can see what your seeing. To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CRTL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

                And yes the positions will close and the end time on the chart.

                Let me know if I can be of further assistance.
                BrettNinjaTrader Product Management

                Comment


                  #23
                  I am trying to send you attachment. I have saved it as .jpeg as well as .jpg and tried sending. With either one it says incorrect type file.

                  Comment


                    #24
                    Please try sending in the one with the .jpg ending - if you send the file in please include a reference to this thread so we can route appropriately.

                    Thanks

                    Comment


                      #25
                      File attached name: chartreduced.bmp

                      Was not able to attach .jpg or jpeg.

                      Ok. If you look at the attached chart, the blue line is SMA50 and brown SMA100. At 7:15 or so the price penetrates through the SMA100 (assume this to be the current bar). But before that there are bars that have crossed SMA50 but not 100.

                      The condition i want to build is: If the current price is above 50 & 100 (but does not have to be simultaneous as in this example, THEN ....

                      I entered in the wizard (i have no ability to enter code directly) two conditions in the conditions section:

                      first line If Price close crosses above SMA50
                      Second Line: If price close crosses above SMA100.

                      This triggers the action ONLY when the current bar crosses both simultaneously.

                      So, I tried:

                      If Price > SMA50
                      If Price CrossesAbove SMA100.

                      This condition set means that the current bar does not have to cross SMA50, just have to be above that. This kind of represents what is shown in the chart but this set does not trigger if current bar crosses both simultaneously, which is not what i want.

                      My thought is, if there is a way to trigger an action on the first time bar that moves above SMA100 but not trigger for the subsequent bars (the subsequent bars that will also be above the SMA100.

                      How do i accomplish this?

                      Thanks.
                      Attached Files

                      Comment


                        #26
                        When using the strategy wizard, using User variables is one way to code for sequences.

                        In your condition for entry, add a condition that checks is UserVariable0 == 0. They initialize as zero so this will be true. Then, within your actions set to a different value so that the next time it checks the condition, it won't be true.

                        If you want to allow more trades down the line, then you need to identify a condition to reset this user variable back to 0.

                        A sample is available with user variables in the strategy wizard here:


                        Import that into your platform and can then edit the strategy to see how they're used to create sequences.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #27
                          I would like to send you the strategy i am creating using the method you have told me if you can check it for accuracy. How do i send it?

                          Comment


                            #28
                            Thank you for the help. I think my strategy is coming along except some new glitches.

                            I have now a strategy that goes long on a slow SMA. Rather than an automatic "reverse" on a short signal, i have an exit strategy. So, i have "Check position flat" in there. Here is the scenario: I have a long entry, then close long based on the exit criteria, but the same bar also meets the new short entry criteria but it does not take it because that particular bar is "checking for flat" and since on that bar it was not flat (was exiting) it does not take the "enter short" signal.

                            How can i rectify that problem.

                            I still want to send you the strategy to check it out. How? I still was not able to attach the JPEG or JPG files even though i reduced the size to below 900.

                            Thnaks.

                            Comment


                              #29
                              Hello,

                              In this case when you start the strategy to run live you would need to use Calculate On Bar Close = False to do this.

                              In the backtester however Calculate On Bar Close will always default to true. Therefor if you want this in the backtester you would have to add whats called granularity to your back test.

                              You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


                              Let me know if I can be of further assistance.
                              BrettNinjaTrader Product Management

                              Comment


                                #30
                                Do i do that by just unchecking the "calculate on close" box in the begining of the wizard?

                                I have previously noted that unchecking the box will then keep generating signal over and over on every tick for the say 5 minute bar,, and i have sound alert too, and that keeps going for those 5 minutes too.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                576 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                334 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                101 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                553 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                551 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X