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

Custom Simple Code

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

    Custom Simple Code

    Hi All,


    I have no coding experience at all but im sure this is a simple fix.


    How would I create the following indicater with the rules.


    1. If Prior Bar is RED ( close is below open


    2. And Current bar open's 1 tick below close of prior bar


    3. and Current bar closes 1 tick above prior bar


    Create alert! (on occurrence)


    And opposite for short.


    Any help would be great.

    #2
    Hello kyamato,

    Thanks for the post.

    This code would be written as follows:

    Code:
    OnBarUpdate()
    {
    
        if((Close[1] < Open[1]) && (Open[0] <= Close[1]-TickSize) && (Close[0] >= Close[1]+TickSize))
        {
    	//Condition true. 
        }
    
    }
    Notably, I am not using strictly equal to in (Open[0] <= Close[1]-TickSize) && (Close[0] >= Close[1]+TickSize). If you wanted to evauate if the current open is exactly equal to the prior bars close - 1 tick, use the == operator.

    Here is the help guide section to the TickSize property:


    If I may be of any further assistance, please let me know.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chris,

      Does this code work for both short and long or is this code just long?

      Also how to i use the code to create an indicator where it would put an arrow or something on the candle.

      Finally can i set this in the market analyzer to alwet when the condition oxxurs?

      Comment


        #4
        Hello kyamato,

        Thanks for the reply.

        If you describe the short conditions, I can write it out in NinjaScript as well.

        To draw an arrow when this occurs, you would do something like this:

        Code:
        OnBarUpdate()
        {
        
            if((Close[1] < Open[1]) && (Open[0] <= Close[1]-TickSize) && (Close[0] >= Close[1]+TickSize))
            {
        	Draw.ArrowDown(this, "tag1", true, 0, High[0] + TickSize, Brushes.LimeGreen);
            }
            
        
        }
        To set up a Market Analyzer alert for this, you would need to create a plot that is either 0 or 1 for any bar, then create an alert in the market analyzer for that column to play a sound when the plot is equal to 1 (or -1 for short). For an example of an implemented plot, see the SMA indicator.

        EX:

        Code:
        OnBarUpdate()
        {
        
            if((Close[1] < Open[1]) && (Open[0] <= Close[1]-TickSize) && (Close[0] >= Close[1]+TickSize))
            {
        	Draw.ArrowDown(this, "tag1", true, 0, High[0] + TickSize, Brushes.LimeGreen);
                MyPlot[0] = 1;
            }
            else
             {
                MyPlot[0] = 0;
            }
        
        }


        Please let me know if you have any questions.
        Last edited by NinjaTrader_ChrisL; 05-21-2018, 09:02 AM.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by RookieTrader, Today, 09:37 AM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by kulwinder73, Today, 10:31 AM
        0 responses
        5 views
        0 likes
        Last Post kulwinder73  
        Started by terofs, Yesterday, 04:18 PM
        1 response
        23 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by CommonWhale, Today, 09:55 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Gerik, Today, 09:40 AM
        2 responses
        7 views
        0 likes
        Last Post Gerik
        by Gerik
         
        Working...
        X