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

building my first strategy

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

    building my first strategy

    hello,
    getting to know the strategy wizard on ninja and trying to put together a simple buy/sell strategy to get a handle on building strategys..

    what i want is...is to enter a trade when price closes outside the bollinger band AND stochastics is oversold/overbot. so if price is outside the upper bb AND stochastics is >75 then i would enter a short(SET 1).... and if price is below the lower bb AND stoch is <25 then enter long.. (SET 2)
    and i would exit using a trailing stop of one point which i believe is 4 ticks.
    I want only one trade per overbot/oversold event because often such overbot/oversold conditions occur for more than one bar in a row.
    and a one point stop loss.
    i would also like to put arrow markers on the chart when the overbot/oversold event occurs for n bars.

    what i got is.... something close, but i am not sure it is quite what i want.
    first off, i dont get the arrow heads over the overbot/oversold event..?
    is it placing two trades when it says for example, "close position [email protected] sell short [email protected]".?
    third, i am not sure the entry is occurring at the first event of the overbot/oversold ?
    and my autotrail stop doesnt seem to stopping me out after 4 ticks.. assuming a tick is a quarter point?
    this attached screen shot shows an example.




    Attached Files

    #2
    and here is the code from the strategy builder

    here is the code from the strategy..hope this is enough info..
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    ///<summary>
    /// entry on over extension of price...
    ///</summary>
    [Description("entry on over extension of price... ")]
    publicclass overbotsold : 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()
    {
    SetStopLoss(
    "", CalculationMode.Ticks, 4, false);
    CalculateOnBarClose =
    true;
    }

    Comment


      #3
      and here is the second half of the code

      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      // Condition set 1
      if (High[0] >= Bollinger(2, 20).Upper[0]
      && StochasticsFilled(
      3, 9, 3).K[0] >= 75)
      {
      DrawArrowDown(
      "My down arrow" + CurrentBar, false, 0, 0, Color.Red);
      EnterShort(DefaultQuantity,
      "");
      }

      Comment


        #4
        and the third and final bit of code.

        sorry for having to do it this way, i dont know of a way to shorten it up..
        // Condition set 2
        if (Low[0] >= Bollinger(2, 20).Lower[0]
        && StochasticsFilled(
        3, 9, 3).K[0] <= 25)
        {
        DrawArrowUp(
        "My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
        EnterLong(DefaultQuantit

        Comment


          #5
          lightfoot500, welcome to the forums!

          So first step is to get the arrows drawn to verify your trading conditions, this can fixed with assigned a correct Y axis value to the DrawArrow call you use (you use 0 now, so that's why they do not show up at all) -

          Last edited by NinjaTrader_Bertrand; 08-13-2009, 04:59 AM.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            thanks bertrand, drawing arrows is working now.
            i would like to work with the slope of one of the indicators. lets say the lower bb. i got it to print an "arrow" for a slope <= n .
            how can i specify the absolute value of n, or do i need two statements in there to work with the absolute value.
            second, is there a way to just print the slope value on the chart in place of the arrow so i can see what the slope value should be?
            my objective is to place markers where the slope of my indicator is flat or near flat. what i have now are markers at near flat or falling because i am using a statement saying mark where the slope is <= n ... hope this clarifys why i want to use the absolute value,.
            thanks
            Last edited by lightfoot500; 08-12-2009, 07:07 PM. Reason: add more info

            Comment


              #7
              For getting the absolute value, you can use Math.Abs().

              For plotting the slope you could use this inside an indicator or in realtime for the strategy, please try this -

              When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability
              BertrandNinjaTrader Customer Service

              Comment


                #8
                ok, using the strategy wizard, i put the slope value of .05 inside the math.abs (.5) like this and it gave error message.
                what is the proper way to use that function?

                Comment


                  #9
                  Please provide the error message.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    well, the error message is property value is not valid.
                    but i realize now that using the absolute value will not work for what i want to do anyways.
                    what i want is to "put an arrow" at each bar for which the upper bollinger band, for example, is between -.5 and .5 ..

                    right now, i have an arrow for slope <= .5....
                    Last edited by lightfoot500; 08-13-2009, 04:31 PM.

                    Comment


                      #11
                      Please provide the complete and exact text of the error along with the complete and exact line causing the error.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        thanks,
                        but i realize now that using the absolute value will not work for what i want to do anyways.
                        what i want is to "put an arrow" at each bar for which the upper bollinger band, for example, is between -.5 and .5 ..

                        Comment


                          #13
                          lightfoot500, ok the Bollinger Band value compared to what? You could use for example the Close price and calculate the difference between it and the Bollinger Band and then DrawArrowUp / Dn if it's within your set limits as mentioned.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            thanks, bertrand, i would be comparing the bb value to bb band value n periods before and looking at the slope.

                            Comment


                              #15
                              Hello,

                              Give it a try using index values in []'s. Here is an example of getting the value of the upper band 3 bars ago:
                              upperValue = Bollinger(2, 20).Upper[3];
                              This link will help:


                              Also, this link may help:
                              DenNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by claxxical, 05-30-2017, 12:30 PM
                              37 responses
                              4,452 views
                              0 likes
                              Last Post Padan
                              by Padan
                               
                              Started by SugarDefwebsite, Today, 02:18 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post SugarDefwebsite  
                              Started by usglucofreeze, Today, 01:19 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post usglucofreeze  
                              Started by f.saeidi, Today, 01:12 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post f.saeidi  
                              Started by NinjaTrader_ChelseaB, 03-14-2017, 10:17 AM
                              227 responses
                              34,319 views
                              7 likes
                              Last Post rare312
                              by rare312
                               
                              Working...
                              X