• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Strategy Triggers Once

  • Filter
  • Time
  • Show
Clear All
new posts

    Strategy Triggers Once

    Hello I have a question on how to make an automated strategy enter a trade only once within the strategy wizard. And after that initial trade it wont enter again until the strategy is disabled and started again. I thought using Bars since exit would work but it still enters another trade after exiting the initial trade. Here is my code:

    BarSinceExit < 1
    BarSinceExit != 1
    Position.MarketPosition = MarketPosition.Flat
    Close(1) < Open(1)

    EnterLongLimit(DefaultQuanity, Close(0) +-5 * Ticksize

    Any help on this would be appreciated,


    Hello rdprioleau,

    Thank you for writing in.

    The easist way to do this would be to set one of the user defined variables.

    When the order is submitted also set Variable0 to 1.

    In your conditions check that Variable0 is 0 before placing an order.

    In a way it is like using a bool with a true or false. Since a bool is not really available to the Strategy Wizard we use a user defined variable instead.
    Attached Files
    Chelsea B.NinjaTrader Customer Service



      Thanks I really needed help with that it makes perfect sense to do it that way I really appreciate the guidance ChelseaB.


        Hey Chelsea I had a problem getting this to trigger when I remove the user variable everything triggers like I intended it to should i set that variable a different way?

        Here is the code:

        Variable0 == 0
        Position.MarketPosition = MarketPosition.Flat
        Close(1) < Open(1)

        EnterLongLimit(DefaultQuanity, Close(0) +-5 * Ticksize
        Variable0 = 1



          The code that you are asking for is to make sure that the action can only be triggered once during the entire run of the script correct?

          If so, that code should allow for one EnterLongLimit order to be placed. This order is not guaranteed to fill, but it should still be placed.

          Is the issue that the order is not being filled or is the issue that the trigger is not happening? If you draw an object like a dot on the bar that triggered the condition does the dot not show up?

          Attached is an example of what I mean. Enable this strategy on a chart and you should see one blue dot on bar 20.

          May I have an export of your strategy?
          To export your script do the following:
          • Click File -> Utilities -> Export NinjaScript
          • Enter a unique name for the file in the value for 'File name:'
          • Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
          • Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message

          By default your exported file will be in the following location:
          • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>

          Below is a link to the help guide on Exporting NinjaScripts.
          Attached Files
          Chelsea B.NinjaTrader Customer Service


            Strategy places order once

            Yea and again thanks for your help on this I don't know I want the script to just place the limit order the code that I have attached won't place the limit order when I have the variable lines in it. It will place the limit order when I remove the variable lines and will behave in the way I want. My intentions are to have the code place a limit order once. After that it does nothing until the strategy is disabled and started again.

            I even tried to get it to place by putting Variable0 < 1 that didnt work either. I'm thinking is Variable0 defined when the strategy starts?

            I might have a work around if I do have to get into the code I know I can use the tradecounter method but I read that if I use that then my first trade would be counted as zero so in order for the strategy not to trigger again would my line would look something like this:

            tradecount < 0

            Lastly i have a 3 of different conditions in this strategy and I tried all the conditions with Variable0 and with assigning each condition with it's own different variable (i.e. Variable1, Variable 2, etc.) and it still does not place the limit unless I take out the User Variable lines.

            Again Thanks for your help on this the strategy is attached.
            Attached Files


              Hello rdprioleau,

              Thanks for your reply.

              I have tested your script and added TraceOrders = true; to the Initialize() section so that I could see if an order was placed.

              I added this to an ES 06-14 1 Minute chart with 5 days to load.

              I am finding that yes, the limit order is being placed and is being cancelled on the next bar because it is not filled within the bar. This is due to the liveUntilCancelled option being false by default.

              After that limit order is placed, Variable0 is set to 1 and the order is not placed again.

              The issue is that the order is placed but does not get filled.

              From the output window with TraceOrders = true;

              3/10/2014 4:21:00 PM Entered internal PlaceOrder() method at 3/10/2014 4:21:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=1867.75 StopPrice=0 SignalName='' FromEntrySignal=''

              3/10/2014 4:22:00 PM Cancelled expired order: BarsInProgress=0: Order='NT-00000/Replay101' Name='Buy' State=Working Instrument='ES 06-14' Action=Buy Limit price=1867.75 Stop price=0 Quantity=1 Strategy='BuyOrder1Mod' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='e8c5d21f0bb44d45afee98a7d81d7213' Gtd='12/1/2099 12:00:00 AM'
              Chelsea B.NinjaTrader Customer Service


                I will make this the last post on this the liveUntilCancelled option how do I set that to false can this be done in the wizard or do I have to go into the code. Thank you for working so hard and being prompt with your replies.


                  Hi rdprioleau,

                  The liveUntilCancelled bool cannot be used when using the Strategy Wizard. The Strategy Wizard is very helpful but does have some limitations.

                  The workaround is to continue resubmitting the order on each new bar as long as certain conditions are true.

                  To use liveUntilCancelled you will need to unlock the strategy.

                  As an example:
                  EnterLongLimit(0, true, 1, Low[0]-2*TickSize, "myEntry");
                  EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)

                  Below is a link to the help guide on EnterLongLimit().
                  Chelsea B.NinjaTrader Customer Service


                    You are Great!! Thanks for the help on this I hope you have a beautiful day, you were so helpful.




                    Latest Posts


                    Topics Statistics Last Post
                    Started by bltdavid, Today, 01:09 PM
                    0 responses
                    1 view
                    Last Post bltdavid  
                    Started by pstrusi, Today, 12:50 PM
                    1 response
                    Last Post NinjaTrader_Jesse  
                    Started by ralett, Today, 11:52 AM
                    1 response
                    Last Post NinjaTrader_PatrickG  
                    Started by rtwave, Yesterday, 07:06 PM
                    2 responses
                    Last Post rtwave
                    by rtwave
                    Started by DTSSTS, Today, 11:27 AM
                    3 responses
                    Last Post Zigfried