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

MACD Histogram bar update

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

    MACD Histogram bar update

    Hi,

    New to Ninjascript and was wondering if I can enlist some help as I build my strategy =)

    I am trying to set up a variable that updates when MACD histogram rebounds from the lowest lows (conversely retraces from highest high).

    My question is this:

    1. Can we set the boundaries of user defined variables? (I would need two variables, one with min -1, max 0, the other with min 0, max 1)

    2. What would be the east way to retrieve MACD histogram bar value for the most recent bar update? I'm having a hard time getting the model to return the last MACD bar value.

    3. I want the model to always have a position in the market (either always long or always short), thus is there a simple command that would reverse the long position and turn it into short and vice versa?

    many thanks....

    #2
    boomasta,

    1. Yes. You can simply check that if its larger than 1, reset to 1, if its less than 0, reset to 0.

    2. Do you mean you want it tick-by-tick or do you want the last closed bar MACD value? MACD(fast,slow,smooth).Diff[0] is the most current value.

    3. Using the managed approach, using a EnterShort() after an EnterLong() will cause the long position to close, and a short position to open.

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hi Adam,

      Many thanks for your quick response.

      I got that set up now its great. Did not know there was a simple .diff to return the histogram value.

      I have a few further questions if you dont mind.

      1. Is there a check position code that allows me to check whether I am currently long or currently short? This is to simplify the process that if my current position is long then I would not have to worry about negative MACD but instead focus on positive values of MACD

      2. The EnterLong() function. If for example we start with a EnterLong(50,000), then by default if the system executes with a EnterShort(50,000), does that mean the position is now square? or does it mean it is now net SHORT 50K?

      Many thanks for your help

      Comment


        #4
        Originally posted by boomasta View Post
        Hi Adam,

        Many thanks for your quick response.

        I got that set up now its great. Did not know there was a simple .diff to return the histogram value.

        I have a few further questions if you dont mind.

        1. Is there a check position code that allows me to check whether I am currently long or currently short? This is to simplify the process that if my current position is long then I would not have to worry about negative MACD but instead focus on positive values of MACD

        2. The EnterLong() function. If for example we start with a EnterLong(50,000), then by default if the system executes with a EnterShort(50,000), does that mean the position is now square? or does it mean it is now net SHORT 50K?

        Many thanks for your help
        boomasta,

        1. Yes, this is called MarketPosition, here is a link for more info : http://www.ninjatrader.com/support/h...etposition.htm

        2. This is known at the managed approach and it will essentially close your long position, and put you in a short position of 50,000.

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Hi Adam,

          Many thanks again.

          I am having some issues trying to establish which state I am currently in.

          The simple code i have right now is this:

          if(Position.MarketPosition.ToString = Short)

          However, it looks like the system does not recognize this.

          I'm building if clauses to check if current positions are long or short, then act accordingly but the system does not seem to pick up on this. Most likely the syntax is wrong and was wondering what is the right syntax to check if my positions are currently long or short?

          thanks

          Comment


            #6
            boomasta,

            You probably want to use something like this :

            Position.MarketPosition == MarketPosition.Short

            Please let me know if I may assist further.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Hi Adam,

              Many thanks and I was able to get it to execute trades in the simulations.

              However, after a few long/shorts the system stops what its supposed to do.

              Example.

              the system would long 100K, short 200K (to flip direction), long 200K(flip direction), and all of the sudden short 100K and does not flip. Therefore in my executed trades I only have long trades and 1 short trade. Do you know what could be wrong here?

              many thanks...

              Comment


                #8
                Hi boomasta,

                You will need to debug the strategy using TraceOrders output to follow any messages related to strategy order submission. The following link can help with TraceOrders:


                Use Print() statements to follow code flow and confirm values. More information on this is available here:
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by CortexZenUSA, Today, 12:53 AM
                0 responses
                1 view
                0 likes
                Last Post CortexZenUSA  
                Started by CortexZenUSA, Today, 12:46 AM
                0 responses
                1 view
                0 likes
                Last Post CortexZenUSA  
                Started by usazencortex, Today, 12:43 AM
                0 responses
                5 views
                0 likes
                Last Post usazencortex  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                168 responses
                2,265 views
                0 likes
                Last Post sidlercom80  
                Started by Barry Milan, Yesterday, 10:35 PM
                3 responses
                11 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X