• 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.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder syntax

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

    Strategy Builder syntax

    I am trying to create a condition in the Strategy build that will stop an enter long if below a certain level, say an indicator plot or even just a drawn line.

    The reverse is required so to create a condition that will stop an enter short if above a certain level.

    I have tried cross above,greater, and greater equal to prevent an enter long under the a certain level, but these trigger when they actually cross the level prescribed.

    I am just trying to prevent a trigger long if price is under a certain level ?

    Thanks in advance for any advice.

    #2
    Hello fredfred123,

    When you mention " stop an enter long" you are referring to cancelling a working buy limit order or cancel a working buy stop or stop limit order, is this correct?

    When using an manually coded script, typically one would call CancelOrder on the Order object variable when the condition is true.

    With orders that remain open and working, these will automatically be cancelled if the bar they are placed on is closed when liveUntilCancelled is not used or is set to false.

    As CancelOrder() is not available to the Strategy Builder, one can use the action of the automatic cancelling to achieve your goal by allowing the order to continuously be placed on any bar where the condition is explicitly not true.

    I've attached an example that will place a buy order as long as the current price is 2 ticks above the SMA and then keep this order alive as long as the price of the order is 2 ticks above the SMA. If the SMA drops below the price of the order, the order is allowed to be cancelled.

    Each step is printed to the output window to debug and understand the behavior.

    Set 1 allows the initial order to be placed and sets the price of the order to WorkingPrice and sets a bool OrderWorking to true so the script knows the order has been placed and should check if it should be kept alive on a later set.

    Set 2 checks that the OrderWorking bool is true, meaning if the price is still above the sma the order should be kept alive. it then places the order using the same parameters as the initial placement to keep it alive instead of being automatically cancelled.

    Set 3 will exit the position immediately if the entry order fills and reset the OrderWorking trigger. (this is a demonstration so no need to stay in the position)

    Set 4 will reset the OrderWorking trigger allowing the entry order to be cancelled if the order price is no longer greater than the sma or if the exit on close has occurred and a new session has started
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Helo ChelseaB

      The example you have provided is extremely helpful and will be very useful, I think I can work a solution with it.

      However what I meant was not to stop a working order, but to stop a working order from being placed.

      For instance if price is above the SMA I wouldn't want a short order placed, or if price was below the SMA I wouldn't want a long order placed.

      The use of the bool OrderWorking trigger is something I considered, true or false to place a trade but cannot get the right syntax to detect if price was above the SMA for instance and how then to trigger the bool to true or false
      I am relying on the strategy builder to write the code, and trying the conditions I think I need does not create matching conditions?

      Looking at the Strategy builder code you have provided I believe the conditions you suggest would work for me, I just need to change the Actions to not to trade.

      My strategy would call for a short over the SMA and I could prevent this short using conditions with the WorkingPrice and OrderWorking bool.

      Great response thanks
      Last edited by fredfred123; 11-19-2017, 02:50 PM.

      Comment


        #4
        Hello fredfred123,

        I'm not quite sure I am understanding.

        Are you asking how to not place an order?

        This would be up to the logic in your code. In your conditions to place an order, don't include conditions that you don't want to place an order..

        The script will only place orders if your condition is true.. If you don't want an order based on a set of conditions, write the conditions to place the order when those conditions aren't true but others are..
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by vpzdcv, Today, 02:31 AM
        0 responses
        7 views
        0 likes
        Last Post vpzdcv
        by vpzdcv
         
        Started by YevhenShynkarenko, Today, 01:22 AM
        0 responses
        11 views
        0 likes
        Last Post YevhenShynkarenko  
        Started by ttodua, Today, 12:52 AM
        0 responses
        6 views
        0 likes
        Last Post ttodua
        by ttodua
         
        Started by ttodua, Today, 12:50 AM
        0 responses
        5 views
        0 likes
        Last Post ttodua
        by ttodua
         
        Started by mulshah, Yesterday, 11:12 PM
        0 responses
        6 views
        0 likes
        Last Post mulshah
        by mulshah
         
        Working...
        X