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

CalculationMode.Price - strange results?

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

    CalculationMode.Price - strange results?

    I am attempting to set profits and targets on price - see attached screenshot:

    I thought the follwing code would set a stop loss/target 5 points away from entry?

    There are some funny graphics plotted as a result


    if (trailStopOn == 0)
    {
    SetStopLoss(signalLong, CalculationMode.Price,
    5, false);
    }
    else
    {
    SetTrailStop(signalLong, CalculationMode.Price, Trail,
    false);
    }
    SetProfitTarget(signalLong, CalculationMode.Price,
    5);

    if (trailStopOn == 0)
    {
    SetStopLoss(signalShort, CalculationMode.Price,
    5, false);
    }
    else
    {
    SetTrailStop(signalShort, CalculationMode.Price, Trail,
    false);
    }
    SetProfitTarget(signalShort, CalculationMode.Price,
    5);
    Attached Files

    #2
    Please check your Control Center log for errors. Note that your usage model for the Set() methods is improper. Once you call one Set() method it will ALWAYS be applied to all orders with that signal name. You don't need to call the Set() again for it to be applied.

    You also cannot use a stop loss along with a trail stop, but ultimately your code would have both because its like a flag. Once switched on it won't be turned off for both your SetStopLoss() and SetTrailStop().

    From what it seems like you are trying to do you may be better served using the Exit() methods directly.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      Please check your Control Center log for errors. Note that your usage model for the Set() methods is improper. Once you call one Set() method it will ALWAYS be applied to all orders with that signal name. You don't need to call the Set() again for it to be applied.

      You also cannot use a stop loss along with a trail stop, but ultimately your code would have both because its like a flag. Once switched on it won't be turned off for both your SetStopLoss() and SetTrailStop().

      From what it seems like you are trying to do you may be better served using the Exit() methods directly.
      I am setting that in initialise - it used to work for calculationmode.ticks.
      I think i might be getting confused with the idea that it would add 5 points instead of doing a static price calcluation..

      What i need to do then is turn points into ticks and use calculationmode.ticks

      Yep a condtional test sets the stop or the trail not both.

      The ultimate aim is to set a dynamic number of points to a stoploss or trail and target - i guess onexecute?

      Comment


        #4
        Trail stop will not work in Price mode. If you want a dynamic amount I recommend you use Exit() directly instead.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Yep - i got it the model is wrong - -not price calculationmode must be ticks..
          So if i do seomthing like the following to get proper points size:

          dblPoints = Instrument.MasterInstrument.Round2TickSize(someATR Value)
          how do i convert this to ticks?

          Comment


            #6
            You would need to do the math by your own code.

            $100 at a TickSize of 0.01 = 10000 ticks (100/0.01), but this is likely not what you are trying to use. CalculationMode.Tick is an offset from whatever the price is. Offsetting it by 10000 ticks is likely not what you are trying to do. You will need additional math in place to get the difference from the price you want and the current price to determine your amount of tick offset.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              straight points to ticks conversion:
              I'm thinking something like:
              privateint ticks(double points)
              {
              if (TickSize < 1)
              {
              return (int)(TickSize * points);
              }
              else
              {
              return (int)(TickSize / points);
              }
              }

              E.g if i want to add 5 points on to the current price as a stop - i would:
              convert 5 points to ticks and use this as the offset

              Comment


                #8
                You can get the point value of your instrument through this: http://www.ninjatrader-support.com/H...ointValue.html
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  that's cool but i dont want the point value.
                  What i want to do is to convert points to ticks. e.g
                  10 points on the ES is 40 ticks -
                  therefore my profittarget will be 40ticks offset from the trade entry..

                  i need to convert a variable to ticks and use it at some point. ticksize should do this. provided it is outside of the init..

                  thanks for your help

                  Comment


                    #10
                    You just need to do the math. You convert the point value to ticks with whatever conversion rate is required for whatever instrument you are trading.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      so points/TickSize is not going to work in all cases?
                      eg
                      ES: = 10/0.25 = 40 ticks

                      Comment


                        #12
                        Would not know. You would need to check on a per instrument basis for the ones you are working with.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          ok sure - will test that out - i'm pretty sure it will work -- sounds plausible --
                          works for nq,es,fdax - i need to try it for currenciy futures such as 6e

                          Is there an alternative snippet? i'm still not clear on how one would do the math using pointvalue and ticks to convert points to ticks ---

                          Comment


                            #14
                            Using PointValue and TickSize is just using the base values would give you the conversion rate. I do not know what conversion you want to use so just use whatever math you feel works for the instruments you will be trading.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              I'm completely stumped will have to re assess the business requirements

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by llanqui, Today, 03:53 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post burtoninlondon  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              14 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Yesterday, 08:42 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Yesterday, 07:51 PM
                              0 responses
                              14 views
                              0 likes
                              Last Post strategist007  
                              Working...
                              X