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

SetStopLoss and SetProfitTarget in Initialize

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

    SetStopLoss and SetProfitTarget in Initialize

    The NT6 manual recommends to put SetStopLoss and SetProfitTarget in the Initialize part. However,any of the statements below generate an exception:

    "Positions property can not be accessed from 'Initialize' method"



    SetStopLoss(LongEntrySignal, CalculationMode.Ticks, stoploss,
    false);

    SetStopLoss(ShortEntrySignal, CalculationMode.Ticks, stoploss,
    false);

    SetProfitTarget(LongEntrySignal, CalculationMode.Ticks, profitTarget);

    SetProfitTarget(ShortEntrySignal, CalculationMode.Ticks, profitTarget);

    #2
    imported post

    We recently fixed an issue related. Could you please:
    - uninstall NT6 via control panel
    - install latest custom build from here: http://www.ninjatrader-support.com/n...er.Install.msi

    You then need to inspect the logs after starting you strategy. There likely are issues reported which then are related to strategy code.

    Comment


      #3
      imported post

      Dierk Droth wrote:
      We recently fixed an issue related. Could you please:
      - uninstall NT6 via control panel
      - install latest custom build from here: http://www.ninjatrader-support.com/n...er.Install.msi

      You then need to inspect the logs after starting you strategy. There likely are issues reported which then are related to strategy code.
      I installed build 10 just days ago. I guess that is still the latest?

      I cannot run the strategy at all when I put these lines in 'Initialize' (if I continue after the exception, NT6 crashes). However, everything is fine if I move the statements to the OnBarUpdate section (so that's what I'm doing now).

      Comment


        #4
        imported post

        Please proceed as per below. The custom build fixes issues in NT6B10.

        Comment


          #5
          imported post

          I have uninstalled NT6 and installed the latest version (your link).

          NT6 doesn't crash anymore, but the strategy cannot be executed. The logfile shows the following message:

          "4/6/2007 14:18 Strategy Failed to call method 'Initialize' for strategy 'ORBELCID001': Object reference not set to an instance of an object."

          Everything is fine when I move the StopLoss- and ProfitTarget statements to the OnBarUpdate section





          Comment


            #6
            imported post

            Right, as I suspected there is a problem with the Initialize method. Could you please post your complete code of the Initialize method as the strategy crashes. Thanks

            Comment


              #7
              imported post

              Dierk Droth wrote:
              Right, as I suspected there is a problem with the Initialize method. Could you please post your complete code of the Initialize method as the strategy crashes. Thanks
              Nothing fancy in there...


              protectedoverridevoid Initialize()

              {

              CalculateOnBarClose =
              true;

              EntriesPerDirection =
              1;

              EntryHandling = EntryHandling.AllEntries;

              TraceOrders =
              true;



              SetStopLoss(LongEntrySignal, CalculationMode.Ticks, stoploss,
              false);

              SetStopLoss(ShortEntrySignal, CalculationMode.Ticks, stoploss,
              false);

              SetProfitTarget(LongEntrySignal, CalculationMode.Ticks, profitTarget);

              SetProfitTarget(ShortEntrySignal, CalculationMode.Ticks, profitTarget);

              }

              Comment


                #8
                imported post

                Great.

                Hmm, I would need more information. Do you mind posting the complete strategy (e.g. as attachment)? You may consider blanking out the OnBarUpdate method (if you want to keep your strategy secret), which is not relevent for researching this issue.

                Comment


                  #9
                  imported post

                  I've sent you a pm with the code

                  Comment


                    #10
                    imported post

                    This is bug which will be fixed with next beta/release. As you figured you cand get around by moving your stop/target settings to OnBarUpdate method.

                    Thanks for providing your strategy and pointing this out.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by trilliantrader, 04-18-2024, 08:16 AM
                    7 responses
                    27 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by samish18, 04-17-2024, 08:57 AM
                    17 responses
                    64 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by rocketman7, Today, 02:12 AM
                    2 responses
                    17 views
                    0 likes
                    Last Post rocketman7  
                    Started by briansaul, Today, 05:31 AM
                    1 response
                    13 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by PaulMohn, Today, 03:49 AM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Working...
                    X