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 sjsj2732, Yesterday, 04:31 AM
        0 responses
        38 views
        0 likes
        Last Post sjsj2732  
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        287 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        289 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        134 views
        1 like
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        95 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Working...
        X