Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Strategy Triggers Once

Collapse
X
 
  • 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,

    Thanks

    #2
    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

    Comment


      #3
      Thanks

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

      Comment


        #4
        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

        Comment


          #5
          Hello,

          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.
          http://www.ninjatrader.com/support/h...nt7/export.htm
          Attached Files
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            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

            Comment


              #7
              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

              Comment


                #8
                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.

                Comment


                  #9
                  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().
                  http://www.ninjatrader.com/support/h...rlonglimit.htm
                  Chelsea B.NinjaTrader Customer Service

                  Comment


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

                    Thanks,

                    Bye

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Aviram Y, Today, 05:29 AM
                    4 responses
                    11 views
                    0 likes
                    Last Post Aviram Y  
                    Started by algospoke, 04-17-2024, 06:40 PM
                    3 responses
                    27 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by bmartz, 03-12-2024, 06:12 AM
                    3 responses
                    31 views
                    0 likes
                    Last Post NinjaTrader_Zachary  
                    Started by gentlebenthebear, Today, 01:30 AM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by cls71, Today, 04:45 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X