Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 OllieFeraher, 05-09-2024, 11:14 AM
        5 responses
        16 views
        0 likes
        Last Post MisterTee  
        Started by jackiegils, Yesterday, 11:05 PM
        1 response
        9 views
        0 likes
        Last Post marcus2300  
        Started by Skifree, Today, 02:50 PM
        0 responses
        8 views
        0 likes
        Last Post Skifree
        by Skifree
         
        Started by owen5819, Today, 02:24 PM
        1 response
        11 views
        0 likes
        Last Post owen5819  
        Started by Skifree, 05-07-2024, 11:38 PM
        2 responses
        28 views
        1 like
        Last Post Skifree
        by Skifree
         
        Working...
        X