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

Strategy Analyzer - Next Bar

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

    Strategy Analyzer - Next Bar

    Hi, How can I see what the next bar after an entry will do. For example will it close int he green, will it make a new low etc?

    Thank You

    #2
    Hello Silver13,

    On each new bar, OnBarUpdate is triggered. You would need to wait for the next bar to close to know what the low of that bar will be.

    To print the low after an order:
    Code:
    private Order entryOrder;
    private bool triggerPrint;
    protected override void OnBarUpdate()
    {
    if (entryOrder == null)
    {
    entryOrder = EnterLong();
    triggerPrint = true;
    }
    else if (entryOrder != null && Position.MarketPosition == MarketPosition.Long && triggerPrint == true)
    {
    Print(Low[0]);
    triggerPrint = false;
    }
    }
    This would print the low once after an order is placed and the position has changed after the order fills.
    If Calculate is set to OnBarClose, this will print the low of the next bar. If Calculate is OnEachTick, this would be the Low after the first tick is received after the position has changed.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi, My question is: How can I see the statistics for the next bar after an entry.

      Like how many times historically did the next bar close higher or lower than the entry bar.

      Comment


        #4
        Hello Silver13,

        That sort of information you will have to extract on your own.

        If to want to monitor how many time the next bar closes above or below the entry price, you will want to create your own logic to a) record the CurrentBar in which the strategy entered, and b) to see if the CurrentBar following the entry is greater than or less than the close of the entry bar.

        As an example:

        private int lastEntry;
        Code:
        private int lastEntry;
        protected override void OnBarUpdate()
        {
        	
        	if (CurrentBars[0] <  BarsRequiredToTrade )
        		return;
        	
        	if (Position.MarketPosition == MarketPosition.Flat)
        	{
        		EnterLong(Convert.ToInt32(DefaultQuantity1), @" LongPosition ");
        		lastEntry = CurrentBar;
        	}
        	
        	if (CurrentBar == lastEntry + 1)
        		if(Close[0] > Close[1])
        			Print("Greater");
        		else if (Close[0] < Close[1])
        			Print("Less");
        }
        Based on that logic you can use Print()'s or log the files to a file for future analysis.

        CurrentBar - https://ninjatrader.com/support/help...currentbar.htm

        Print() - https://ninjatrader.com/support/help...n-us/print.htm

        Log() - https://ninjatrader.com/support/help.../en-us/log.htm

        Read and Write to a text file - http://ninjatrader.com/support/forum...ead.php?t=3477
        JimNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jim View Post
          Hello Silver13,

          That sort of information you will have to extract on your own.

          If to want to monitor how many time the next bar closes above or below the entry price, you will want to create your own logic to a) record the CurrentBar in which the strategy entered, and b) to see if the CurrentBar following the entry is greater than or less than the close of the entry bar.

          As an example:

          private int lastEntry;
          Code:
          private int lastEntry;
          protected override void OnBarUpdate()
          {
          
          if (CurrentBars[0] < BarsRequiredToTrade )
          return;
          
          if (Position.MarketPosition == MarketPosition.Flat)
          {
          EnterLong(Convert.ToInt32(DefaultQuantity1), @" LongPosition ");
          lastEntry = CurrentBar;
          }
          
          if (CurrentBar == lastEntry + 1)
          if(Close[0] > Close[1])
          Print("Greater");
          else if (Close[0] < Close[1])
          Print("Less");
          }
          Based on that logic you can use Print()'s or log the files to a file for future analysis.

          CurrentBar - https://ninjatrader.com/support/help...currentbar.htm

          Print() - https://ninjatrader.com/support/help...n-us/print.htm

          Log() - https://ninjatrader.com/support/help.../en-us/log.htm

          Read and Write to a text file - http://ninjatrader.com/support/forum...ead.php?t=3477
          Sorry for the late reply but I am still trying to figure this out. Where would I input the code for the logic?

          If I have a strategy builder custom strategy created for what happens if: I enter on a down close, and exit the next close - Can I see what the Fibonacci or other statistics are for what the next bar did, not just winning and losing trades, net profit, etc.

          Comment


            #6
            Hello Silver13,

            Something complex like counting a number of bars or subtracting a saved bar number from CurrentBar is beyond the capabilities of the Strategy Builder and would need to be coded by hand.

            The logic would likely be added to OnBarUpdate.

            Below I am providing a public link to a forum post with helpful information about getting started with NinjaScript.


            You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.


            That said, you would likely want to save the CurrentBar number when the event you are looking for occurs, that may also trigger an action such as placing an order.
            Then you would want to create a for loop from the CurrentBar back to CurrentBar minus the saved bar number. For each bar in the loop, you can get the Close[barsAgo], High[barsAgo], Low[barsAgo], etc.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi, I would like to replicate this type of output with the Fib retracements that I have seen on twitter.

              Thanks!
              Attached Files

              Comment


                #8
                Hello Silver13,

                This looks like some probability statistics.

                I can't assist with the math or logic, but I am happy to answer any questions you may have about NinjaScript if you decide to code this yourself.

                This thread will remain open for any community members that would like to assist with the math or logic.

                You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Mizzouman1, Today, 07:35 AM
                3 responses
                17 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by RubenCazorla, Today, 09:07 AM
                2 responses
                13 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by i019945nj, 12-14-2023, 06:41 AM
                7 responses
                82 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by timmbbo, 07-05-2023, 10:21 PM
                4 responses
                158 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by tkaboris, Today, 08:01 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X