Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to exit after 2 bars

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

    Trying to exit after 2 bars

    If I do not hit my profit target by or during the second day I want to get out at the end of the day? I am not sure how to code this? This is what I have so far.

    Thanks,
    Erik

    Code:
     
      protected override void Initialize() {
    [SIZE=2]    SetProfitTarget([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Long Limit Order"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], CalculationMode.Percent, 5);[/SIZE]
      }
     
      protected override void OnBarUpdate() {
       if (BarsInProgress != 0) return;
       if (Positions[0].MarketPosition != MarketPosition.Flat && BarsSinceEntry([COLOR=#a31515]"Long Limit Order"[/COLOR]) >= 2) {
        ExitLong([COLOR=#a31515]"Long Limit Order"[/COLOR]);
        return;
       }
       ...
       if (some condition) {
        ...
        if (some condition) {
         EnterLongLimit(100, SomePrice, [COLOR=#a31515]"Long Limit Order"[/COLOR]);
        }
       }
      }

    #2
    ErikHR,

    What you want to do is check the dates. Check the date you entered the market at against the date of the current bar. If it has been two days then you want to place an exit order when a certain time is met. You can do these time and date checks by using Time[0] along with ToDay() and ToTime().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,
      I Just have some EOD data loaded into NinjaTrader for learning how to code the tool. Since I am just using EOD Data does this mean that by the time I get to check the values of the Bar (day 2) the best I can do is put in an ExitLong for the next mooring (day 3) until I have more granular data? And when I start getting live data so long as I do not have CalculateOnBarClose = true; set I will be able to put the order in near the end of the day? Am I looking at this right?
      Thanks,
      Erik

      Comment


        #4
        ErikHR,

        That is correct.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        60 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        147 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        161 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        97 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        284 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X