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 cmoran13, Yesterday, 01:02 PM
        0 responses
        29 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        21 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        160 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        95 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        148 views
        2 likes
        Last Post CaptainJack  
        Working...
        X