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

SImple System Only Did 2 Trades?

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

    SImple System Only Did 2 Trades?

    Hi,

    I know this is probably going to be something simple that I have missed, but I just wanted to test a simple strategy, it did 2 trades 3 years ago then never traded again. It is just simply selling yesterdays high at market and buying yesterdays low at market.

    This is basically the code (not sure best way to share it on here?)

    Code:
    }
       else if (State == State.Configure)
       {
        SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
        SetProfitTarget("", CalculationMode.Ticks, ProfitTarget);
       }
      }
    
      protected override void OnBarUpdate()
      {
       if (BarsInProgress != 0)
        return;
    
       if (CurrentBars[0] < 1)
        return;
    
        // Set 1
       if (GetCurrentBid(0) == High[1])
       {
        EnterShort(Convert.ToInt32(DefaultQuantity), "");
       }
    
        // Set 2
       if (GetCurrentAsk(0) == Low[1])
       {
        EnterLong(Convert.ToInt32(DefaultQuantity), "");
       }
    [LEFT][COLOR=#4D4D4D][FONT=Helvetica][/FONT][/COLOR][/LEFT]

    Many thanks
    Tom



    #2
    Hello Tomhgriff1,

    Thanks for your post.

    It sounds like you are using the strategy analyzer to backtest. Please run a test with the SampleMACrossover strategy in your platform using the same time frame, bars type and range of test dates. This strategy should produce continuous trades over the test period and is a good way to ensure that you have the data to support the trading period.

    Are you connected to your live data feed when running the backtest?

    What instrument, timeframe, bar type and range of test dates are you using?

    Please note that when backtesting, both GetCurrentAsk() and GetCurrentBid() will be returning the "close" value of the candle.
    References: https://ninjatrader.com/support/help...currentask.htm https://ninjatrader.com/support/help...currentbid.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      thanks very much for the reply. I am using this strategy on a daily chart. I am currently just testing out the platform on the free EOD data that comes free with the platform. So this system is selling the pervious bars high at market with the previous bar being the daily bar of yesterday. I am testing it from Dec2015 to Jan 2018 currently. This is on the CL futures contract.

      I'm not sure why it should be an issue but im wondering if the fact I only have EOD data that is causing this?

      Thanks again,
      Tom

      Comment


        #4
        Hello Tomhgriff1,

        Thanks for your reply.

        The Kinetick end of Day data will work for backtesting of daily bars.

        As previously advised, GetCurrentAsk() and GetCurrentBid() will return the "Close' value of the bar. If you change your conditions to be Close[0] = High[1] and Close[0] = Low[1], you will find that only two trades would be made as there are only two times where that specific exact condition occurs.

        In summary, for backtesting, you would need to change your conditions for entry, perhaps using "Greater Equal" or "less Equal" as appropriate.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks again for that. That solved the issue of not producing anymore trades. However, the entries are appearing in the wrong place. The system should just be buying the previous days low when/if the price reaches it. However, it seems to just be buying at the open of the next day

          Copying in the code again in case there is anything there I have done incorrectly?

          I used the strategy building to say if ask[0] < low[1] then go long at market.

          Code:
          protected override void OnBarUpdate()
            {
             if (BarsInProgress != 0)
              return;
          
             if (CurrentBars[0] < 1)
              return;
          
              // Set 1
             if ((GetCurrentBid(0) >= High[1])
               && (Close[1] > SMA1[1]))
             {
              EnterShort(Convert.ToInt32(DefaultQuantity), "");
             }
          
              // Set 2
             if ((GetCurrentAsk(0) <= Low[1])
               && (Close[1] < SMA1[1]))
             {
              EnterLong(Convert.ToInt32(DefaultQuantity), "");
             }
          
            }

          Comment


            #6
            Hello Tomhgriff1,

            Thanks for your reply.

            "The system should just be buying the previous days low when/if the price reaches it. However, it seems to just be buying at the open of the next day" This would be expected because with historical data, the strategy code is run once at the end of the bar. If the strategy conditions to place an entry are met the entry is placed but cannot be filled until the next bar because the bar that was just evaluated has closed (meaning nothing to drive the entry). This would also be the case with live data with a strategy that is running with the calculate mode of Calculate.OnBarClose.

            With only daily bars data you would not have any options for placing an order earlier. This could be done with a Ninjascript created strategy AND an intraday data series (not available with Kinetick end of day datafeed). Here is a link to an example of the Ninjascript strategy coding: https://ninjatrader.com/support/help...ipt_strate.htm
            To accomplish this in the strategy builder, you would need to have intraday data and apply the strategy to the intraday data and add the daily bars to the strategy. The strategy builder can only apply trades to the primary series (which would be the chart bars) and in this case would need to be intraday data.

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Thanks Paul, makes sense. I guess I need to get the intraday data. Thanks

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by geddyisodin, Today, 05:20 AM
              2 responses
              16 views
              0 likes
              Last Post geddyisodin  
              Started by hazylizard, Today, 08:38 AM
              0 responses
              6 views
              0 likes
              Last Post hazylizard  
              Started by Max238, Today, 01:28 AM
              5 responses
              43 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by giulyko00, Yesterday, 12:03 PM
              3 responses
              13 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by habeebft, Today, 07:27 AM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_ChristopherS  
              Working...
              X