Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Displacement parameter

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

    Displacement parameter

    Hi! I was wondering if there's any way to "displace" an indicator when building a strategy? I have only found this parameter in indicators menu on the chart ... any idea ?

    Thanks!

    #2
    Try this:

    Comment


      #3
      Thanks gregid, but I only know the very basics of programming so I wouldn't know how to implement this, when I'm looking at the code though, it looks like it might be the same function as "bars ago" in strategy builder wizard.

      Update: I've tried the bars ago parameter, but then when I backtest the strategy it doesn't generate any trade and the displaced SMA isn't even shown on the chart.

      Update 2: When I try adding the above code to the strategy I get an error message: The name 'Displacement' does not exist in the current context
      Last edited by George09; 07-10-2011, 02:08 AM.

      Comment


        #4
        Hi George

        Can you post your full code you have inside of:

        protected override void Initialize()

        Comment


          #5
          George, the Displacement property would only be for indicators visually - in your strategy you would reference to a certain series value x bars ago to create the same effect - do you see any errors in the log tab if you apply your script to the chart you're testing on? If you attach it here we could take a quick look at it as well then and guide further.

          Thanks,
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Grrrr, sry guys, just found out the problem was that I didn't have any open data connection, so that's why it didn't generate any trade, thanks for your help though!

            BTW, Do you know where I can find a code that would execute profit target on SMA cross? As far as I know it's possible to set only fixed profit targets in strategy wizard.

            Comment


              #7
              Hello,

              No problem.

              Right only static stoploss and profit target in the strategy wizard. If you wanted to unlcok the code you can add the dynamic stop loss/profit target with the below sample:



              Let me know if I can be of further assistance.

              Comment


                #8
                I've tried to edit the original script from wizard, where T/P was fixed:

                SetProfitTarget("", CrossBelow(EMA(34), EMA(50), 1));
                And a few error messages pop up:

                The best overloaded method match for 'NinjaTrader.Strategy.StrategyBase.CrossBelow(doub le, NinjaTrader.Data.IDataSeries, int)' has some invalid arguments Argument '2': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries' The best overloaded method match for 'NinjaTrader.Strategy.StrategyBase.SetProfitTarget (NinjaTrader.Strategy.CalculationMode, double)' has some invalid arguments Argument '1': cannot convert from 'string' to 'NinjaTrader.Strategy.CalculationMode' Argument '2': cannot convert from 'bool' to 'double'

                Comment


                  #9
                  Hello,

                  Right. CrossBelow() method returns a value of true or false. Not a number which you need a number here.

                  You would need to use a number here instead. Such as EMA(24)[0] for example would return the indicator value for the current bar.

                  Let me know if I can be of further assistance.

                  Comment


                    #10
                    Ok, so if I understand it right, this code should work? Because I got the same error messages with it as before. It actually doesn't necessarily have to be crossbelow, it can be "<" as well.
                    SetProfitTarget("", CrossBelow(EMA(34)[0], EMA(50)[0], 1));

                    Comment


                      #11
                      George09,

                      That line of code will not work.

                      CrossBelow() does not return a price value. It returns either true or false for if something crossed below something else.

                      If you want to try and set a new profit target price when something crossed below something else you need to do this:

                      Code:
                      if (CrossBelow(EMA(34), EMA(50), 1))
                           SetProfitTarget(CalculationMode.Price, somePriceLevel);
                      Please realize that once code has been called once for SetProfitTarget() it will attach itself going forward to any new orders at the prior defined level. This means you need to reset that level when you are no longer in a trade to your initial profit target level. For more information on this please see this reference sample: http://www.ninjatrader.com/support/f...ead.php?t=3222
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi, thanks for the info Josh. Actually I don't really need to set a new profit target when 2 EMAs cross, but I would rater have the crossing point as profit target. So I this case, should I use this code:
                        if (CrossBelow(EMA(34), EMA(50), 1)) SetProfitTarget(CalculationMode.Ticks, 0);

                        Comment


                          #13
                          That looks like an interesting trick. It should take you out of the market, with your current profit/loss, as soon as the EMAs cross.

                          Kindly let me know if that is what happens.

                          Comment


                            #14
                            This should work though I have no personally done this in any of my strategies. This is what we do on our ATM Strategies though. Is move the profit target down to be filled.

                            Let me know if I can be of further assistance.

                            Comment


                              #15
                              Works like a charm, thanks for your help guys!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by frankthearm, Today, 09:08 AM
                              5 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              43 views
                              0 likes
                              Last Post jeronymite  
                              Started by yertle, Today, 08:38 AM
                              5 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by adeelshahzad, Today, 03:54 AM
                              3 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by bill2023, Yesterday, 08:51 AM
                              6 responses
                              27 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Working...
                              X