• 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

Stop Limit order triggered by price level cross

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

    Stop Limit order triggered by price level cross

    Hello
    Please help to generate a logic that makes a stop limit order to be placed on LEVEL X if the price hits LEVEL Y.
    As far as I understand to keep fire a stop order while condition is not true anymore I require to set a variable which is resided between the condition itself and SL order action. However, if my trigger condition is price and it steps away from the conditional level, the variable turns back to false as well. Hence order dies next bar.
    The algorithm that I require seems extremely simple, but in reality I have no idea how to realize it...

    I appreciate if you propose any operable logic. Pls see the illustration for better understanding what needs to be done.

    Thnx

    #2
    Hello Aporshnev,

    Thank you for the inquiry.

    What you are explaining is true and is also possible. To submit a stop or limit type order and keep it active would require that the condition remains true.

    One way to do this would be to use a variable and some conditions to toggle the variable. A separate condition could be used to check the state of the variable to determine if the order should or should not be placed. Because you want to toggle the live until cancelled a variable can be used for that purpose because you cannot toggle LiveUntilCancelled. If you choose to use LiveUntilCancelled you will need to cancel the order yourself rather than just not calling the entry method. Here is a quick example of one way to realize that goal:

    Code:
    private bool entryShouldBeActive = false;
    protected override void OnBarUpdate()
    {
         if(State == State.Realtime)
        {
            if(CrossAbove(Close, Open, 1))
            {
                entryShouldBeActive = true;
            } else if(CrossBelow(Close, Open, 1))
            {
                entryShouldBeActive = false;
            }
            if(entryShouldBeActive == true)
            {
                EnterLongStopLimit(1, Close[0] + 5 * TickSize, Close[0] + 1     * TickSize, "TestEntry");
            }
        }
    }
    This sample relies on being in realtime and is just used to demonstrate the toggling of the bool variable. You could expand on this however the main idea to take away from this is how the bool variable is used to enable/disable the entry order. While the variable is true the entry is submitted, once a cross below happens the entry condition is no longer true and will be cancelled on the next bar if not filled. The cross conditions could be replaced with your own conditions checking for prices, again the main take away is how the variable is toggled based on your conditions and how the variable is used in the third condition.



    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      It appears that position entry via SL order is too complicated. I decided to test the following: I made 3 user inputs (for test) with price meanings and set EnterLongPosition if Ask price equals user input. Stops and ProfitTakes were set as well, but this is not important so far. During the test I observed that on a few entry events the position was not opened. At least there are no historical execution markers on the chart. Moreover, on different timeframes the strategy reports different performance and it is unclear to me why - the entry condition is price and it has been crossed several times. One of my assumptions is the historical data is inaccurate, or testing on the Sim account is not 100% accurate, however, I would like to ask you how can this be?
      I marked the input prices (BuyTrigger1 etc.) on the test chart for convenience. I expected a long position on the fact of this levels cross (whatever above or below)

      If I set the inappropriate conditions to open the position on the fact of price touch, then how can this be realized differently?
      Attached Files

      Comment


        #4
        Hello Aporshnev,

        Checking if two prices are directly equal will often not work, this is due to how floating point numbers are stored in memory. Using a crossing condition or greater/lesser condition would be advised to be used.

        You could try checking a range of prices instead, for example, if the price is greater than or equal to 9140 and less than 9141. This would allow the condition to return true if the price lands on 9140.


        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks. The task is almost solved.
          What calculation method loads the system more - calculate on each tick of on price change?

          Comment


            #6
            Hello Aporshnev,

            OnEachTick would be the most processor intensive as that calls your script for each tick.


            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by samir, Yesterday, 09:27 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Marco  
            Started by elnoppo, Today, 12:32 AM
            0 responses
            3 views
            0 likes
            Last Post elnoppo
            by elnoppo
             
            Started by karolwatcher, Yesterday, 08:15 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChrisSch  
            Started by lwyatt100, Yesterday, 10:13 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_ChrisSch  
            Started by patpat, Yesterday, 10:45 PM
            0 responses
            3 views
            0 likes
            Last Post patpat
            by patpat
             
            Working...
            X