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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X