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

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:	170
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.
    JesseNinjaTrader Customer Service

    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:	177
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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mangel2000, Today, 02:23 AM
        0 responses
        3 views
        0 likes
        Last Post mangel2000  
        Started by mangel2000, Today, 01:30 AM
        0 responses
        8 views
        0 likes
        Last Post mangel2000  
        Started by Doxxxx, Today, 01:24 AM
        0 responses
        5 views
        0 likes
        Last Post Doxxxx
        by Doxxxx
         
        Started by ezekilany, Today, 01:10 AM
        0 responses
        4 views
        0 likes
        Last Post ezekilany  
        Started by usjavaburn, Today, 12:59 AM
        0 responses
        3 views
        0 likes
        Last Post usjavaburn  
        Working...
        X