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

help with simple strategy

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

    help with simple strategy

    I'm looking at the YM now using 10 tick SbS Renko bars (attachment).
    (Does anyone at support know of a similar question asked recently
    that I can look at in a thread? see below)

    The idea is to put on a long trade with a stop, for a up Rekno, assuming up market.
    Exit the trade should the stop be hit on the first bar.
    Wait until next bar and enter long if up bar, or short, if down bar (with stop of course)
    and then just stay with the trade if it goes up (or if short, down).

    If long trade was entered, let's just say, then exit at the first down bar, go short,
    with a stop of course, and just stay short.


    I've tried with IF statements only. Should I use WHILE, or ????, or ????
    Any hint(s) would help at this point. I know this is simple really.

    - Stephen
    Attached Files

    #2
    You would use if-statements. Check if the close > open for up bars and close < open for down bars.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      You would use if-statements. Check if the close > open for up bars and close < open for down bars.
      Thanks. That's what I did. I've got something like this, see below.
      I've tried different things, but you might get the idea below of where I'm
      trying to go in general.
      (The BarsSinceExit, is so that the strategy doesn't enter long (or short)
      a second time in the bar it just got stopped out of.)


      if (BarsSinceExit()>0 && (BarsSinceExit()<2 && (Close[0]>Close[1])))
      EnterLong();
      SetStopLoss(CalculationMode.Ticks,10);

      || if (BarsSinceExit()>0 && (BarsSinceExit()<2&& (Close[0]<[1])))
      EnterShort();
      SetStopLoss(CalculationMode.Ticks,10);

      if (Close[0]<Close[1])
      ExitLong();
      EnterShort();
      SetStopLoss(CalculationMode.Ticks,10);

      if (Close[0]>Close[1])
      ExitShort();
      EnterLong()
      SetStopLoss(CalculationMode.Ticks,10);

      I don't know. Still thinking (or what passes for it). I guess I need to get this
      code into a loop of some sort?

      Comment


        #4
        Please describe exactly what part you feel does not work as expected. Thank you.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Well after this...

          if (Close[0]<Close[1])
          ExitLong();
          EnterShort();
          SetStopLoss(CalculationMode.Ticks,10);

          ...the long trade is exited and a short trade is entered with it's stop.
          But then if I get stopped out on the short trade that I just entered, let's say,
          stopped out immediately
          (the short trade entered right now at the trend change).

          So I must re-enter short trade on NEXT bar...
          {I don't want to keep entering short (or long) on the same bar I just
          got stopped out of.}

          ...IF it happens to be a down bar

          OR else enter long trade on next bar IF a up bar.

          (I'm going through various combinations here that have no relevance
          to the attachment.)


          I need to loop back on all this I assume somehow, using BarsSinceExit with
          the stop loss parameters.

          Comment


            #6
            You need to limit your if-statement. That condition you have there does not care whether or not you just entered. You need to prevent it from evaluating to true again and again.

            Some ideas.
            Code:
            if (Close[0] > Open[0] && enteredLong == false)
            {
                // place trades;
                enteredLong = true;
                enteredShort = false;
            }
            
            if (Close[0] < Open[0] && enteredShort == false)
            {
               // trades
               enteredLong = false;
               enteredShort = true;
            }
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Does this seem like it would work (see code below)? It's doing something now.
              I appreciate the help so far.

              Should I always see a trade in the DOM if the chart is showing that a trade has
              been executed? I wonder about that. The YM is selected on the DOM yet it is
              indicating flat now. Chart plots a long trade currently.


              I noticed you used Open, as in,
              if(Close[0]> OPEN[0] && enteredLong==false) using OPEN may be better than
              using close. Anyway there is no such
              thing as Renkos (that work). Even
              roonius hasn't solved that yet. So
              I'm looking at the SbSRenko as I said earlier.
              (even though it's not what I want, it may
              not even be possible for NT to do generic Renkos)



              ================================================== ================
              ================================================== ================

              protected override void Initialize()
              {
              // Be sure to use TRUE here!
              CalculateOnBarClose = true;
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              bool enteredLong=false;
              bool enteredShort=false;
              if (Close[0]>Close[1]&& enteredLong==false)
              {
              EnterLong();
              SetStopLoss(CalculationMode.Ticks,10);

              }
              if (Close[0]<Close[1]&& enteredShort==false)
              {
              EnterShort();
              SetStopLoss(CalculationMode.Ticks,10);

              }

              }

              ================================================== ================
              ================================================== ================

              Comment


                #8
                You would probably want to create those bools in the Variables region of your code before OnBarUpdate().
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  You would probably want to create those bools in the Variables region of your code before OnBarUpdate().
                  Ok, trying that now.

                  I spent a few minutes with the DOM's properties, but I
                  still think it's not showing me long as it should. Will the DOM, if set up correctly,
                  always confirm the plots/executions on a chart running a strategy?

                  - Stephen

                  Comment


                    #10
                    Not sure what you mean. What a strategy has in terms of positions can be seen in the Strategies tab of the Control Center.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Josh View Post
                      Not sure what you mean. What a strategy has in terms of positions can be seen in the Strategies tab of the Control Center.
                      Used BarChart today (first day) and NT crashed at the end of the day.
                      I checked on the box 'store real-time bar data' and it was checked but
                      that was after the fact. It looks like the day's data was recorded but then lost.
                      No big deal.
                      Well this computer is old so that's probably the reason. I might not be able
                      to get into this again for a few days, however I accomplised much more than
                      I ever thought I would with all your help today.

                      - Stephen

                      Comment


                        #12
                        Stephen, I'm not sure I follow why you would need this option checked for BarChart - they provide historical data on theirs servers for backfilling, thus you could leave this unchecked for better performance.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Bertrand View Post
                          Stephen, I'm not sure I follow why you would need this option checked for BarChart - they provide historical data on theirs servers for backfilling, thus you could leave this unchecked for better performance.
                          Thanks. I will be looking into this today. So you say that I can get tick data, going back
                          XX days... ONLY during market hours, for the YM? This is exactly what I would want so
                          I can use market replay on the strategy.

                          - Stephen

                          Comment


                            #14
                            (The only video of Market Replay I've seen at the NT site is for an older version
                            so it doesn't help too much.)

                            I've gone to Tools|Options|Data| and clicked on Market Replay recorder.
                            I've gone to File| Connect | Market Replay connection...the Market Replay
                            connection words will not highlight, so obviously it will not activate.
                            I do have a chart up of Friday's YM but "Strategies" can not be engaged.

                            - Stephen

                            I finally got Market Replay to activate but I'm still trying to get it to see some
                            of the data I collected from last week.
                            Last edited by stephenszpak; 12-06-2009, 02:42 PM.

                            Comment


                              #15
                              Last try for help on this thread

                              In Control Center|Tools|Options|Data ....

                              is it necessary to simultaneously have both these checked:

                              Store real-time bar data AND Run market replay recorder

                              I can display in a chart the last few days of the YM but the
                              file:

                              MyDocuments|NinjaTrader6.5|db|data will only show:

                              20091206


                              I did connect to BarChart.com briefly today. I guess this is that.
                              Apparently I have data is SOME format, since I can display a multi-day
                              SbS Renko chart but I'm going to assume MarketReplay can't use it unless
                              I'm told otherwise.

                              - Stephen

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ETFVoyageur, 05-11-2024, 10:13 PM
                              4 responses
                              31 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by wuannetraam, Today, 02:40 AM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
                              17 responses
                              80 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Tradereh2020, Today, 06:29 AM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by ryan_21, Yesterday, 08:46 PM
                              2 responses
                              6 views
                              0 likes
                              Last Post ryan_21
                              by ryan_21
                               
                              Working...
                              X