Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

double exit strategy

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

    double exit strategy

    the following is "OnBarUpdate() which compliles but not giving the result intended.

    the goal is to have an exit either 10 ticks profit,10 ticks stop, or when price touches the SMA (10)
    Code:
    [SIZE=2][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2] (Position.MarketPosition == MarketPosition.Long)[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]ExitLongLimit(SMA(10)[[/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]
     
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Position.MarketPosition == MarketPosition.Long)[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]SetStopLoss([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], CalculationMode.Ticks, 10, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
     
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Position.MarketPosition == MarketPosition.Long);[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]SetProfitTarget([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], CalculationMode.Ticks, 10);[/SIZE][/FONT]

    #2
    The Set() methods need to be placed before you acquire a long position for them to take affect on the long position.

    You should call the Set() methods right before you call EnterLong().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      set methods

      is this considered a set method?
      Code:
      [COLOR=#0000ff]if[/COLOR][FONT=Courier New][SIZE=2] (Position.MarketPosition == MarketPosition.Long)[/SIZE][/FONT]
      [SIZE=2][FONT=Courier New]ExitLongLimit(SMA(10)[[/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]

      Comment


        #4
        Set() methods are SetStopLoss(), SetTrailStop(), and SetProfitTarget().
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          where does this exit go?

          Code:
          [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
          [FONT=Courier New][SIZE=2]CalculateOnBarClose = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];///does this need to be "false"?[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
          [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
          [SIZE=2][FONT=Courier New][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]( [/FONT][/SIZE]
          [SIZE=2][FONT=Courier New](High[0]>High[1][/FONT][/SIZE][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
          [SIZE=2][FONT=Courier New]SetStopLoss([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], CalculationMode.Ticks, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]SetProfitTarget([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], CalculationMode.Ticks, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]EnterLong(DefaultQuantity, [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
           
           
          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
          [/FONT][/SIZE]
          does this go into the "intialize()?
          Code:
          ExitLongLimit(SMA(10)[[FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]

          Comment


            #6
            No. No logic should ever be placed in Initialize().
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              does this correct?

              Code:
              [COLOR=#0000ff]protected[FONT=Courier New][SIZE=2]override[/SIZE][/FONT][/COLOR][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [FONT=Courier New][SIZE=2]CalculateOnBarClose = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];///does this need to be "false"?[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]( [/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]  (High[0]>High[1][/FONT][/SIZE][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New])[/FONT][/SIZE][/FONT][/SIZE]
              [SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]  SetStopLoss([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], CalculationMode.Ticks, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]  SetProfitTarget([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], CalculationMode.Ticks, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]  EnterLong(DefaultQuantity, [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE][/FONT][/SIZE]
              [SIZE=2][FONT=Courier New][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2]([/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]   (High[[/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]>SMA([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]18[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]) [/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]   ExitLong();[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [/FONT][/SIZE]

              Comment


                #8
                That should work.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                647 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                368 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                571 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X