Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't get this exit strategy to work....

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

    Can't get this exit strategy to work....

    Hi-

    While the below code compiles fine, it does not send out any exit orders.....



    if (BarsInProgress == 1)
    {ExitLongStop(1, true, 1, Position.AvgPrice - 8 * TickSize, "LONGstop", "LONG");}
    {ExitLongLimit(
    1, true, 1, Position.AvgPrice + 6 * TickSize, "LONGtarget", "LONG");}



    {
    // If a long position is open, allow for stop loss modification to breakeven
    if (Position.MarketPosition == MarketPosition.Long)

    {
    // Once the price is greater than entry price+12 ticks, set stop loss to breakeven + 2 ticks
    if (High[0] > Position.AvgPrice + 12 * TickSize)

    {

    ExitLongStop(
    1, true, 1, Position.AvgPrice + 2 * TickSize, "LX", "LONG");

    }




    }


    Any thoughts?

    #2
    Originally posted by CoopGeko View Post
    Hi-

    While the below code compiles fine, it does not send out any exit orders.....



    if (BarsInProgress == 1)
    {ExitLongStop(1, true, 1, Position.AvgPrice - 8 * TickSize, "LONGstop", "LONG");}
    {ExitLongLimit(
    1, true, 1, Position.AvgPrice + 6 * TickSize, "LONGtarget", "LONG");}



    {
    // If a long position is open, allow for stop loss modification to breakeven
    if (Position.MarketPosition == MarketPosition.Long)

    {
    // Once the price is greater than entry price+12 ticks, set stop loss to breakeven + 2 ticks
    if (High[0] > Position.AvgPrice + 12 * TickSize)

    {

    ExitLongStop(
    1, true, 1, Position.AvgPrice + 2 * TickSize, "LX", "LONG");

    }




    }


    Any thoughts?
    Looking only at the code that you have posted, you cannot exit a position unless a position already exists. Your block brackets also seem to be strange, but without seeing your entry code, it is hard to say for sure.
    Last edited by koganam; 01-19-2013, 11:32 PM.

    Comment


      #3
      Here's the entry code......it calls a different BarsArray....(2)......


      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()




      {
      if (BarsInProgress == 0)
      {

      // Condition set 2- LONG SETUP
      if (Lows[2][0] <= -375)
      {
      EnterLong(DefaultQuantity,
      "LONG");

      }
      }

      Last edited by CoopGeko; 01-19-2013, 10:05 PM.

      Comment


        #4
        Like Koganam suggested, just to confirm - you are in a position and there are no exits being generated?

        Can you post something that is 'complete' but not related to your strategy that we could reproduce?



        Have you tried using the output window with Print statements to print the values of the conditions or if you are entering the conditional area?


        if (BarsInProgress == 1)
        {
        Print ( "BIP==1 ExitLongStop Entering $" + (Position.AvgPrice - 8 * TickSize ));
        ExitLongStop(1, true, 1, Position.AvgPrice - 8 * TickSize, "LONGstop", "LONG");
        }

        {
        Print ("BIP==1 ExitLongLimit Entering $" + (Position.AvgPrice + 6 * TickSize ));
        ExitLongLimit(1, true, 1, Position.AvgPrice + 6 * TickSize, "LONGtarget", "LONG");
        }

        (and did you really mean to not use an ELSE in there ?)



        Originally posted by CoopGeko View Post
        Here's the entry code......it calls a different BarsArray....(2)......


        ///<summary>
        /// Called on each bar update event (incoming tick)
        ///</summary>
        protectedoverridevoid OnBarUpdate()




        {
        if (BarsInProgress == 0)
        {

        // Condition set 2- LONG SETUP
        if (Lows[2][0] <= -375)
        {
        EnterLong(DefaultQuantity,
        "LONG");

        }
        }

        Comment


          #5
          Thanks Koganam and Sledge.....

          I've attached the script here.....

          I'm brand new to this and I'm sure there are many ways of coding this idea where the final result would be the same, but in a nutshell what I'm trying to do is enter one instrument at the exact time another instrument breaks a predetermined level. And then have the script full manage the exit. The exit is is a bracket order with an adjustable break even stop so that after primary instrument has moved most of the way to the target, then the stop is moved to a tick above breakeven.

          I'm probably mixing oranges and apples in the code...

          I use the strategy on a 1-day, 5-min chart with ES as primary bars object and SPY as Secondary (1).

          The Idea is that if SPY breaks to a new intraday low (for example 147.50 on Friday), I want to go long ES with a market order.
          Attached Files

          Comment


            #6
            Originally posted by CoopGeko View Post
            I use the strategy on a 1-day, 5-min chart with ES as primary bars object and SPY as Secondary (1).
            I'm seeing you add two SPY series and a 1 minute series for the Primary (ES as you stated)

            If you're running on a 1 day chart you will need to type 5 instead of 1 on your line 44: Add(PeriodType.Minute, 1);

            You then have 4 bar series in the strategy but I'm only seeing you handle the BIP 0 (primary series) and BIP 1 (in this case its a 1 minute chart of the primary series)

            Additionally you have some oddly placed brackets.

            Code:
            if (BarsInProgress == 1)
                        {ExitShortStop(1, true, 1, Position.AvgPrice + 8 * TickSize, "SHORTstop", "SHORT");}
                        {ExitShortLimit(1, true, 1, Position.AvgPrice - 6 * TickSize, "SHORTtarget", "SHORT");}
                        {ExitLongStop(1, true, 1, Position.AvgPrice - 8 * TickSize, "LONGstop", "LONG");}
                        {ExitLongLimit(1, true, 1, Position.AvgPrice + 6 * TickSize, "LONGtarget", "LONG");}
            You should not be bracketing your exit orders like this.

            Please see the following as an example of how to use BarsInProgress: http://www.ninjatrader.com/support/h...nstruments.htm

            Let me know if I can be of further assistance.
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            3 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X