Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarClose and OnFirstTick

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

    OnBarClose and OnFirstTick

    I am trying to implement a simple pullback strategy based of EMA and the condition are as follows. I am giving Long condition and long exit requirements only here -

    1. The last 3 bars before the entry bar should have closed above the EMA and no wicks shoud have touched the ema.(bar close)
    2. After that any time the bar touches the EMA take a long condition (on price change)
    3. Have a stop loss of 40 and tp of 40

    Exit condition
    1, If the bar closes below the EMA exit the trade (even if it is less than 40 ticks) - on bar close

    Could someone please help me with this? Thanks!!
    Last edited by Graci117; 12-10-2024, 09:59 PM.

    #2
    Hello Graci117,

    Below I am providing a link to a support article with helpful resources on getting started with C# programming and NinjaScript.


    Be sure to watch the 'Automate Your Trading with NinjaTrader's Strategy Builder' training video to learn how to use the Strategy Builder.

    "The last 3 bars before the entry bar should have closed above the EMA and no wicks shoud have touched the ema.(bar close)"

    If you are using the strategy builder, add three conditions to a condition set. On the left select Price > Close with Bars ago set to 0, Greater, Indicators > EMA with Bars ago set to 0.
    Then for the second condition in the set use Bars ago 1 for both the close and the ema.
    Then for the third condition in the set use Bars ago 2 for both the close and the ema.

    "After that any time the bar touches the EMA take a long condition (on price change)"

    Add a bool variable with a default value of false.
    When the first condition set is true set the bool to true. (meaning the first condition has evaluated as true)

    In a separate condition set check the bool is true, and add conditions for the close crossing above or below the ema.

    "Have a stop loss of 40 and tp of 40"

    Stops and targets can be added on the stops and targets page.

    "If the bar closes below the EMA exit the trade (even if it is less than 40 ticks) - on bar close"

    In a separate condition compare the Price > Close to be less than Indicator > EMA.


    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 a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea for your response. I do the coding too and my question is more about how to handle this OnBarClose vs OnPriceChange. I want a trigger for a long as soon as the price touches the EMA. It should not wait for the bar to close. I want to check the OnBarClose to make sure that last 3 bars are above the EMA and the low of the bar has not touched the EMA. This one would be a OnBarClose. Any thoughts??

      Comment


        #4
        Hello Graci117,

        The calculate setting doesn't affect the ability to get information about previous bars. This is done with a Bars ago index.

        When Calculate is OnPriceChange or OnEachTick, Bars ago 0 is the currently building bar, Bars ago 1 is the most recent fully closed bar, Bars ago 2 is the bar previous to the most recently fully closed bar, etc.
        When Calculate is OnBarClose, Bars ago 0 is the most recently fully closed bar, Bars ago 1 is the bar previous to the most recently fully closed bar, etc.

        Use Calculate.OnPriceChange if you want the logic evaluated on each price change, before the bar closes. If you want logic only evaluated after a bar close, require Misc > IsFirstTickOfBar to be true.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        110 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        59 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        37 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        41 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        78 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X