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

"Heiken-Ashi" like Entry

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

    "Heiken-Ashi" like Entry

    Can someone help me write the code to place a limit or market order at the half way point of the body of a candle that just closed?

    Or...

    How can one get a strategy to place orders respective to heiken-ashi bars?
    Last edited by Rogue_Two; 05-07-2018, 03:51 PM.

    #2
    Hello Rogue_Two,

    Thanks for your inquiry.

    This can be accomplished by performing some math on the price you want to calculate, and then to submit the order at that price level using an order method of either the Managed Approach or the Unmanaged Approach.

    Referencing the previous bar can be done with a BarsAgo index of 1, (or 2 if you are using a Calculate mode other than OnBarClose.) Please see the Working with Price Series documentation and please reference the Calculate documentation. I also have a demonstration video that can be referenced. The video is my own, but the other information is publicly available.

    Working with Price Series - https://ninjatrader.com/support/help...ice_series.htm

    Calculate - https://ninjatrader.com/support/help...?calculate.htm

    Calculate Demo - https://www.screencast.com/t/IezPWUzQZvE

    As a rough example for calculating midpoint of a previous bar: (Close[1] - Open[1])/2 + Close[1]. This math will need to be applied appropriately for up and down bars.

    After you have calculated your price level, the order may be submitted using an order method of the Managed Approach or Unmanaged Approach.

    Order Methods (Managed Approach and Unmanaged Approach) - https://ninjatrader.com/support/help...er_methods.htm

    EDIT: You may also use a Heiken Ashi indicator or the built in Heiken Ashi Bartype to submit orders to Heiken Ashi price levels. If you are new to programming I may suggest referencing the Strategy Builder 301 tutorial to see how the Strategy Builder can create the programming syntax for what you would like to accomplish. Keep in mind, the Builder is only meant for simple strategies. More robust code should be programmed by hand.

    Heiken Ashi indicator - https://ninjatrader.com/support/foru...atid=7&lpage=1

    Strategy Builder 301 - https://www.youtube.com/watch?v=HCyt90GAs9k

    If you are interested in services to write this code for you, we can have a representative of our EcoSystem reach out with more information on NinjaScript Consultants who would be happy to write this or any other code at your request.

    Please let us know if we can be of further assistance.
    Last edited by NinjaTrader_Jim; 05-07-2018, 04:09 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you Jim!

      Within this strategy I am trying to get
      long entries when the MACD is below 0 and crossing above the Avg line.

      and

      short entries when the MACD is above 0 and when it is crossing below the Avg line.

      I don't get an error during the compiling process but the strategy will not run in the analyzer nor will it "enable" when the code is written this way:

      Code:
      if (IsFirstTickOfBar)
      			{
      				 
      				// Long when MACD is below zero
      				if (MACD1.Default[0] < 0)
      				{
      					if (MACD1.Default[1] > MACD1.Avg[2])
      					{
      					EnterLong(Convert.ToInt32(Position.Quantity), @"Long");
      					Draw.Square (this, "testb"+CurrentBar, true, 0, Low[0] - 8 * TickSize, Brushes.Blue);
      					}
      				}	
      				
      				// Short Entry
      				if (MACD1.Default[0] > 0)
      				{
      					if (MACD1.Default[1] < MACD1.Avg[2])
      					{
      					EnterShort(Convert.ToInt32(Position.Quantity), @"Short");
      					Draw.Dot (this, "testc"+CurrentBar, true, 0, High[0] + 8 * TickSize, Brushes.Magenta);
      					}
      				}
      			}
      I have this portion in (IsFirstTickOfBar) since I have an additional stop loss process calculating on tick in the strategy.

      Any ideas what could be wrong?

      Comment


        #4
        Originally posted by Rogue_Two View Post
        Thank you Jim!

        Within this strategy I am trying to get
        long entries when the MACD is below 0 and crossing above the Avg line.

        and

        short entries when the MACD is above 0 and when it is crossing below the Avg line.

        I don't get an error during the compiling process but the strategy will not run in the analyzer nor will it "enable" when the code is written this way:

        Code:
        if (IsFirstTickOfBar)
        			{
        				 
        				// Long when MACD is below zero
        				if (MACD1.Default[0] < 0)
        				{
        					if (MACD1.Default[1] > MACD1.Avg[2])
        					{
        					EnterLong(Convert.ToInt32(Position.Quantity), @"Long");
        					Draw.Square (this, "testb"+CurrentBar, true, 0, Low[0] - 8 * TickSize, Brushes.Blue);
        					}
        				}	
        				
        				// Short Entry
        				if (MACD1.Default[0] > 0)
        				{
        					if (MACD1.Default[1] < MACD1.Avg[2])
        					{
        					EnterShort(Convert.ToInt32(Position.Quantity), @"Short");
        					Draw.Dot (this, "testc"+CurrentBar, true, 0, High[0] + 8 * TickSize, Brushes.Magenta);
        					}
        				}
        			}
        I have this portion in (IsFirstTickOfBar) since I have an additional stop loss process calculating on tick in the strategy.

        Any ideas what could be wrong?
        Are there any errors in your log? If so, what are they?

        Comment


          #5
          Strangely, there are no errors.

          Comment


            #6
            Hello Rogue_Two,

            The Strategy Analyzer uses historical data for processing and NinjaScripts will be forced to use Calculate.OnBarClose behavior for historical data unless Tick Replay is activated. It sounds like your logic is processing, but since it is processing differently, trades aren't opening or closing.

            You could enable Tick Replay to allow your strategy to calculate with OnEachTick/OnPriceChange for historical data like in the Strategy Analyzer. I'd also suggest enabling TraceOrders, and maybe adding debugging prints if you need to look into the logic further.

            We have some resources on debugging and using Trace Orders that can currently be found on our forums, as well as our help guide. I'll provide help guide links below.


            Please note that simulated order fills using Tick Replay will still use the primary data series for order fills. To get order fills more consistent with when the order was placed, your orders will need to be submitted to a 1 tick data series. High Order Fill Resolution provides this behavior, but cannot be used in conjunction with Tick Replay, so the script will need to implement the additional data series for your orders to submit to. The example below may be referenced, and I may also would like to point out the Multi Time Frame and Instruments documentation for reference when building a Multi Series NinjaScript.


            If you have any additional questions, please don't hesitate to ask.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Fran888, 02-16-2024, 10:48 AM
            3 responses
            43 views
            0 likes
            Last Post Sam2515
            by Sam2515
             
            Started by martin70, 03-24-2023, 04:58 AM
            15 responses
            114 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by The_Sec, Today, 02:29 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by jeronymite, 04-12-2024, 04:26 PM
            2 responses
            31 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by Mindset, 05-06-2023, 09:03 PM
            10 responses
            265 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X