Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing Entry bar's Min(low)

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

    Accessing Entry bar's Min(low)

    Hello,

    I want to keep the initial stop 1 point lower than MIN2 = MIN(Low, 10) by saving the value on entrybar (bold text in the code). Unfortunately I get an error code in playback mode that tells me orders can't be placed above market and ninja immediately sells my long position. Can someone kindly help me in getting the correct code for this? Without saving the variable it actually works, but then of course the Stop is moving each 10 bars. I want to have it fixed. Thanks in advance!

    Click image for larger version

Name:	initialstop.png
Views:	204
Size:	11.3 KB
ID:	1158464

    Code:
    // Entry & Initial Stop
    if ((SMA1[1] > EMA1[1])
    {
    EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), (High[1] + 1) , @"Long Einstieg");
    [B]entrybar = MIN2[CurrentBar];[/B]
    }
    
    ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), ([B]entrybar - 1[/B]) , @"Initial Stop", @"Long Einstieg");
    PS. I used

    private double entrybar;

    #2
    Hello MarcelloXi,

    From the given code it looks like the way MIN is being used is not correct for what you described that you want.

    The CurrentBar represents the current index of the processing bar, if you are on bar 100 the CurrentBar is 100. Using MIN2[CurrentBar] would be the same as saying get the min bars ago from the beginning of the chart.
    To get the current MIN at the time of the entry it should be 0 bars ago:

    Code:
    entrybar = MIN2[0]
    I look forward to being of further assistance.

    Comment


      #3
      Hello Jesse,

      that helped! Thank you very much. One more question, now I'm trying to implement a trailing stop which is 1 point below the low of the latest bar (Low[1] - 1) that closes below the Low of the previous bar ((Close[1] < Low[2]), as highlighted in the screenshot.

      I already did that with the code below, but obviously Ninjatrader removes the order once the condition is not true anymore. But I need the stop to stay until it gets triggered or if it does not trigger trail it to the next event of (Close[1] < Low[2]).

      Do you have any idea? Thanks so much!

      Click image for larger version

Name:	trailstop.png
Views:	205
Size:	7.3 KB
ID:	1158597

      Code:
      // Stop when High get's triggered
      if (CrossAbove(High, entrybarhigh, 100)
      && [B](Close[1] < Low[2])[/B]
      )
      {
      ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), Low[1] - 1 , @"Long Exit", @"Long Einstieg");
      }

      Comment


        #4
        Hello MarcelloXi,

        You would need to use a variable to control the order in that situation.

        For example:

        Code:
        private bool orderActive = false; 
        protected override void OnBarUpdate()
        {
        
            if (CrossAbove(High, entrybarhigh, 100) && [B](Close[1] < Low[2])[/B] )
           {
               orderActive = true;
           }
        
           if (orderActive == true)
           {
               ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), Low[1] - 1 , @"Long Exit", @"Long Einstieg");
           }
        }

        You could then use the orderActive variable to control if the order should expire later by setting it back to false.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        93 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        138 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        123 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        73 views
        0 likes
        Last Post PaulMohn  
        Working...
        X