Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need some help

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

    Need some help

    I've tried to write a simple strategy (using wizard) that takes positions based on signals given by PSAR indicator and encountered one problem. I have mechanical target for each trade (fixe amount of ticks) and I wanted to limit number of signals per direction to just one, however after closing the first trade strategy immediately reenters position in the same direction and does it as long as the condition (PSAR > Last Price) is true. I don't want to have another position opened until PSAR changes from Buy to Sell or vice versa. Is there a simple way to fix this ? Thanks for help

    Matt

    #2
    You will have to get a little clever with setting user defined variables under the action section. Once you go long, set some value, then check if this value is set when the condition to go long is true, if it is set to some value (maybe 1) ignore the entry condition, when psar goes short, reset this value.

    Something like that.
    RayNinjaTrader Customer Service

    Comment


      #3
      Where is the loop ?

      How do I make it stop checking if the condition is still true on the next bar (after closing the first trade) when there's no loop in the code generated by wizard. I'd have to exit that loop but such doesn't exist. Below is the code created by wizard:

      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      ///<summary>
      /// Enter the description of your strategy here
      ///</summary>
      [Description("Enter the description of your strategy here")]
      publicclass PSAR : Strategy
      {
      #region Variables
      // Wizard generated variables
      // User defined variables (add any user defined variables below)
      #endregion
      ///<summary>
      /// This method is used to configure the strategy and is called once before any strategy method is called.
      ///</summary>
      protectedoverridevoid Initialize()
      {
      SetProfitTarget(
      "", CalculationMode.Ticks, 4);
      CalculateOnBarClose =
      true;
      }
      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      // Condition set 1
      if (ParabolicSAR(0.02, 0.2, 0.02)[0] <= GetCurrentBid())
      {
      ExitShort(
      "", "");
      EnterLong(DefaultQuantity,
      "");
      }
      // Condition set 2
      if (ParabolicSAR(0.02, 0.2, 0.02)[0] >= GetCurrentBid())
      {
      ExitLong(
      "", "");
      EnterShort(DefaultQuantity,
      "");
      }
      }
      #region Properties
      #endregion

      Comment


        #4
        Confused

        Where exactly in the user guide I can find this info ? Also, sample crossover strategy is always in the market so how can it be of help here ? I'm wondering if I can fix my strategy using just wizard or some hardcoding will be nessesery here ?

        Comment


          #5
          See post #2, I provide you an approach which you can use to filter out taking subsequent triggers. Ultimately this is a logic question.
          RayNinjaTrader Customer Service

          Comment


            #6
            Doesn't work

            I tried to do it this way but it doesn't work:

            namespace NinjaTrader.Strategy
            {
            ///<summary>
            /// Enter the description of your strategy here
            ///</summary>
            [Description("Enter the description of your strategy here")]
            publicclass PSAR1 : Strategy
            {
            #region Variables
            // Wizard generated variables
            // User defined variables (add any user defined variables below)
            #endregion
            ///<summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            ///</summary>
            protectedoverridevoid Initialize()
            {
            Add(ParabolicSAR(
            0.02, 0.2, 0.02));
            SetProfitTarget(
            "", CalculationMode.Ticks, 5);
            CalculateOnBarClose =
            true;
            }
            ///<summary>
            /// Called on each bar update event (incoming tick)
            ///</summary>
            protectedoverridevoid OnBarUpdate()
            {
            // Condition set 1
            if (ParabolicSAR(0.02, 0.2, 0.02)[0] <= GetCurrentBid()
            && Variable0 ==
            0)
            {
            ExitShort(
            "", "");
            EnterLong(DefaultQuantity,
            "");
            Variable0 =
            1;
            }
            // Condition set 2
            if (ParabolicSAR(0.02, 0.2, 0.02)[0] >= GetCurrentBid())
            {
            Variable0 =
            0;
            }
            // Condition set 3
            if (ParabolicSAR(0.02, 0.2, 0.02)[0] >= GetCurrentBid()
            && Variable0 ==
            0)
            {
            ExitLong(
            "", "");
            EnterShort(DefaultQuantity,
            "");
            Variable0 =
            1;
            }
            // Condition set 4
            if (ParabolicSAR(0.02, 0.2, 0.02)[0] <= GetCurrentBid())
            {
            Variable0 =
            0;
            }
            }

            Comment


              #7
              You will have to try different things until you figure out how to get it to do what you want. I know this can be frustratinig but its part of programming/logic design.
              RayNinjaTrader Customer Service

              Comment


                #8
                I understand, just please tell me strategy wizard is sufficient tool for solving this problem or it requires hardcoding, playing with loops and nested conditions. Thanks

                Matt

                Comment


                  #9
                  Personally, I would manually program it.
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    Realized P/L

                    How do I reference reailzed P/L from current trading session (as specyfied in the wizard) ?? Expression created by wizard seems to have some bug:

                    // Condition set 1
                    if (ParabolicSAR(0.02, 0.2, 0.02)[0] <= GetCurrentBid()
                    && Performance.AllTrades.Performance.Points.CumProfit < Variable0)

                    Message I get says:

                    Strategy\PSAR.cs 'NinjaTrader.Strategy.TradeCollection' does not contain a definition for 'Performance' CS0117 - click for info 46 42

                    What do I do with this ??

                    Thanks

                    Comment


                      #11
                      Please make sure you are on latest 6.5.1000.3. Then delete this strategy and create it again. Please let us know if issue persists.

                      Comment


                        #12
                        I'm running 6.5.0.4 version

                        Comment


                          #13
                          Wow...this is outdated since months. Please update to 6.5.1000.3 (see download page in web site) and proceed as per below.

                          Comment


                            #14
                            I downloaded newest version and I'm still getting the same kind of error . Can you please take a look at code and tell me where the mistake is ??

                            Comment


                              #15
                              a) What do you see in Help->About?
                              b) Please delete your strategy and create it again.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by quantismo, Today, 05:13 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post quantismo  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              8 responses
                              167 views
                              0 likes
                              Last Post jeronymite  
                              Started by cre8able, Today, 04:22 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X