Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How Can I Program: Go Long on first bull candle after the event?

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

    How Can I Program: Go Long on first bull candle after the event?

    Hi Guys
    I am trying to program that after the event (which I have already programmed) then go long on the close of the first bull candle (close > open). I thought it should be something like:
    EnterLongLimit(Close [n]);
    But I need to specify what n is: n=first bull candle after "event". So if my event is: Close [0] < Close [1] for example then it should be something like:
    {
    (Close [0] < Close [1]
    && Close [n] > Open [n]
    n=any candle after 0)
    }

    EnterLongLimit(Close [n]);

    I am not sure how this can be accomplished using the programming language of Ninja. So some guidelines would be appreciated, or the actual code.

    Reading through some code I found that there is a statement : bullFound = true;
    I am wondering if I can use this to accomplish what I am trying to do. If so please guide me in how and where this statement has to be entered to accomplish what I am trying to do.

    Thankyou.
    Last edited by bijan; 12-22-2013, 12:44 PM.

    #2
    Hello,

    There are a couple ways to handle this. I've put together a small example which takes use of your "bullFound" flag you can add.

    Code:
                     #region Variables
    		private bool bullFound = false;
    		private double entryPrice = 0;
                     #endregion
    
    		protected override void OnBarUpdate()
    		{
    			
    			//checks for bull candle
    			if(Close[0] > Open[0])
    			{
    				bullFound = true;
    			}
    			
    			while(bullFound)
    			{
    				//stores close price of bull candle
    				entryPrice = Close[0];
    				//resets bullFound to be checked again on the next OnBarUpdate call
    				bullFound = false;
    			
    			}
    			
    			//when condition is true...
    			if(Close[0] < Close[1])
    			{
    				//...enter limit order at entry price from bullFound bool
    				EnterLongLimit(entryPrice);
    				
    				//you may want to use some draw objects to visual on the chart that the entry was where you wanted it to be
    				DrawDot("entryPrice"+CurrentBar, false, 0, entryPrice, Color.Blue);
    			}
    			
    		}
    If you're new to C# and NinjaScript, I'd suggest going through some of the basic tutorials we've developed to help you get started with some of these concepts:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Matthew thanks for the reply.

      I am trying to change the sample code you wrote to what I am trying to code. I like to know where do I place this portion of your code, under what heading (for example under protected override void Initialize ( ):
      #region Variables
      private bool bullFound = false;
      private double entryPrice = 0;
      #endregion

      Also for one of the things I am trying to do I need to find a bar that has a certain value of an indicator. So for example its time duration is of a certain length. How can I accomplish this. In other words how can I tell the program to "find" the bar that has this character?
      Last edited by bijan; 12-25-2013, 12:07 PM.

      Comment


        #4
        Bijan,

        There should be a Region variables section in your strategy.

        I've attached a copy to help demonstrate.

        Regarding your second task, there are a number of ways to accomplish this. Please have a look at our reference sample on Getting indicator values from a specified time



        You may also be interested in methods used in our sample on Referencing the correct bar

        Attached Files
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        367 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        571 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X