Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Wrong ticker setup after importing historical data

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

    Wrong ticker setup after importing historical data

    Good morning,
    I have this problem and I dont know how to solve.
    I am backtesting a simple strategy on past data so:
    1) I have download soybean continuous contract data from QUANDL
    2) Create a symbol (ZS_C) into Instruments as the original ZS future
    3) Imported data and check the imported data was hooked to correct symbol

    Until here, everything is fine.

    Now when I run the backtester and I check "include commissions", I get 0 commissions and more important the backtester is not taking the correct "multiplier" that is 50 in case of soybean.

    For example: entry at 526 and exit at 615, profit is 89$ instead of 4450 $!!

    1) How to fix the problem of "multiplier" ( I check into Instruments and it is correctly configured at 50)
    2) How to setup the right commissions?

    #2
    Hello alexgiul, thank you for the post and welcome to the NinjaTrader forum.

    For the first question, are you talking about the contract quantity that your strategy is using? In the strategy analyzer, under "Order properties", if "Set Order Quantity" is set to "Strategy", the strategy will decide the quantity through its order entry methods (EnterLong(50)). If you set it to "Default Quantity", it will use the selected value.

    On the commission issue, do you have commissions template applied to the Sim101 account? You can check that by going to the Accounts tab of the Control Center>Right Click the account>Edit account>Commissions Template.

    Thanks in advance, I look forward to your reply.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      for first question, I am talking about a future instrument, so I will buy just one contract at time, but the "leverage" for this instrument is 50. if I run the simulation with original data, I got the right profit&loss.In order to have the correct amount, I have to put 50 into EnterLong() function.
      If I use the original future ZS xx-xx, I put 1 and the platform compute the right P&L

      Comment


        #4
        Hello alexgiul,

        Thanks for the reply.

        My statement was about the order contract quantity. I believe you are referring to the Tick Size of the instrument. Below is a screenshot of my ZS futures instrument configuration. Could you confirm that you have this set up properly? You can reach this window via Tools>Instruments>query the ZB.



        I look forward to your reply.
        Last edited by NinjaTrader_ChrisL; 09-24-2018, 09:03 AM.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Chris,
          thanks for reply.
          Maybe it's better if I share the whole setup.
          This is the "continuous soybean from 12-2004 to 12-2009" : https://www.dropbox.com/s/cpn6f8966k....Last.txt?dl=0 that after creating a new instrument "ZS_C" copying settings from the Soybean future (configured as yours)

          Now, I have just opened "Instruments" and I found 2 instruments (a future - wanted - and a stock...why???)

          https://www.dropbox.com/s/t1vkpucdby...mbols.PNG?dl=0

          This is the current configuration of future Soybean:
          https://www.dropbox.com/s/mr0vxn3bmw...oyben.PNG?dl=0

          My goal is load an external datafeed (like quandl) and perform some backtesting

          Comment


            #6
            Hello alexgiul,

            Thanks for the reply. Since the ZB is already in the platform by default, importing the file under the name of ZS_C will create a new instrument and you can not have duplicate instrument mappings. You must import the file under the name "ZS 11-18.Last.txt". After this, you can remove the ZS_C instrument from the Instruments menu.

            Please let me know if I can assist futher.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Thanks Chris,
              I have done as you told me and now commissions are ok as well the multiplier.


              The only problem I have now is the following:


              the data importend into ZS 11-18 start from 15-12-2004 and ends on 15-12-2009 but when I run the strategy into the same period, the engine execute backtest only on 2009.
              You may see the image of Strategy configuration in the link below:



              Comment


                #8
                Hello alexgiul,

                Thanks for the reply.

                I tested your data file, and I was able to get the backtest to work by importing the file as "ZS ##-##.Last.txt" and running a backtest on ZS ##-##. If you did not import it as a continuous contract, you would need to split up the data into their own contract months.

                Please let me know if I can assist further.
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Chris,
                  thanks this solved the biggest issue.


                  Last question (as you may immagine I am a newbie)...


                  This is the strategy code:


                  namespace NinjaTrader.NinjaScript.Strategies
                  {
                  public class Davey1 : Strategy
                  {
                  private SMA SMA1;

                  protected override void OnStateChange()
                  {
                  if (State == State.SetDefaults)
                  {
                  Description = @"Enter the description for your new custom Strategy here.";
                  Name = "Davey1";
                  Calculate = Calculate.OnBarClose;
                  EntriesPerDirection = 1;
                  EntryHandling = EntryHandling.AllEntries;
                  IsExitOnSessionCloseStrategy = true;
                  ExitOnSessionCloseSeconds = 30;
                  IsFillLimitOnTouch = false;
                  MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                  OrderFillResolution = OrderFillResolution.Standard;
                  Slippage = 0;
                  StartBehavior = StartBehavior.WaitUntilFlat;
                  TimeInForce = TimeInForce.Gtc;
                  TraceOrders = false;
                  RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                  StopTargetHandling = StopTargetHandling.PerEntryExecution;
                  BarsRequiredToTrade = 20;
                  // Disable this property for performance gains in Strategy Analyzer optimizations
                  // See the Help Guide for additional information
                  IsInstantiatedOnEachOptimizationIteration = true;
                  Sma = 30;
                  }
                  else if (State == State.Configure)
                  {
                  //SetStopLoss(CalculationMode.Currency, 1000);
                  }
                  else if (State == State.DataLoaded)
                  {
                  SMA1 = SMA(Close, Convert.ToInt32(Sma));
                  AddChartIndicator(SMA1);

                  }
                  }

                  protected override void OnBarUpdate()
                  {
                  if (BarsInProgress != 0)
                  return;

                  if (CurrentBars[0] < 1)
                  return;

                  // Set 1
                  if (CrossAbove(Close, SMA1, 1))
                  {
                  EnterLong(1, "LONG");
                  }

                  // Set 2
                  if (CrossBelow(Close, SMA1, 1))
                  {

                  if (Position.MarketPosition == MarketPosition.Long && CrossBelow(Close, SMA1, 1)) {
                  ExitLong(1);
                  }


                  }


                  /*
                  if (Position.MarketPosition == MarketPosition.Short && CrossAbove(Close, SMA1, 1)) {
                  ExitShort();
                  }
                  */
                  }

                  #region Properties
                  [NinjaScriptProperty]
                  [Range(30, int.MaxValue)]
                  [Display(Name="Sma", Description="sma length", Order=1, GroupName="Parameters")]
                  public int Sma
                  { get; set; }
                  #endregion

                  }
                  }



                  if I uncomment this line " SetStopLoss(CalculationMode.Currency, 1000);" for unknow reason the backtest stop at end of 2005


                  This is the screenshot of error: https://www.dropbox.com/s/f4h4eyhn5n...error.PNG?dl=0


                  What is going on?

                  Comment


                    #10
                    Hello alexgiul,

                    Thanks for your patience.

                    This is coming from using ExitLong and SetStopLoss in tandem. This is expected from the Strategy Analyzer and will not happen while running the strategy on real-time data or on the Playback connection.

                    Please let me know if you have any questions.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Chris, for reply,
                      so which is the est way to code these cases for exit from a long/short position:
                      1) stop loss due to a fixed amount
                      2) exit according a specific condition on indicator
                      3) Take profit


                      In my case, suppose I am long and the price price crossbelow SMA, :
                      1) close the long trade (exit as stated at above point 2)
                      2) open a short one


                      Chris, maybe I have solved it: I have increased the "Entries for direction" to 2 and it generates all trades...but many are "stop loss" with wrong amount...(https://www.dropbox.com/s/avjyt3vbgw...ttura.PNG?dl=0)


                      This is the code: https://www.dropbox.com/s/5fh9lvlbiy..._ninja.cs?dl=0
                      Last edited by alexgiul; 09-26-2018, 09:31 AM.

                      Comment


                        #12
                        So which is the easiest way to code these cases for exit from a long/short position:
                        1) stop loss due to a fixed amount
                        I would use SetStopLoss() here
                        2) exit according a specific condition on indicator
                        I would us one of the Exit methods here
                        3) Take profit
                        Could use SetProfitTarget() or an Exit method depending on how you want to build your logic

                        In my case, suppose I am long and the price price crossbelow SMA, :
                        1) close the long trade (exit as stated at above point 2)
                        2) open a short one
                        Are you saying that you want to reverse your position, or the above is what is occurring?

                        I do not believe that setting EntriesPerDirection to 2 will be the answer to this.
                        Last edited by NinjaTrader_JoshG; 09-26-2018, 01:44 PM.
                        Josh G.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Josh,


                          yes I would revert my position.


                          This is the basic rule I would try to code on ninja:
                          1. Go long (and exit shorts) at tomorrow’s open if today’s closing price crosses above the 30-day SMA.
                          2. Sell short (and exit longs) at tomorrow’s open if today’s closing price crosses below the 30-day SMA.
                          3. Exit any trade if its open loss climbs to $1,000 per contract.

                          Comment


                            #14
                            In my case, suppose I am long and the price price crossbelow SMA, :
                            1) close the long trade (exit as stated at above point 2)
                            2) open a short one
                            In that case, if you are already in a long position, the following snippet would close the long position and enter short after crossing below the 30 period SMA.

                            Code:
                            if (CrossBelow(Close[0], SMA(30), 1))
                            {
                            	EnterShort();
                            }
                            Please see the following link for more information on NinjaTrader order handling. You can also see an example of this working by backtesting the built in SampleMACrossover strategy.

                            Last edited by NinjaTrader_JoshG; 09-27-2018, 09:27 AM.
                            Josh G.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by dltxpro, Today, 02:45 PM
                            0 responses
                            9 views
                            0 likes
                            Last Post dltxpro
                            by dltxpro
                             
                            Started by Mr Bread, Today, 02:06 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post Mr Bread  
                            Started by Diane1202, Today, 02:02 PM
                            0 responses
                            9 views
                            0 likes
                            Last Post Diane1202  
                            Started by klaxtoncapital, Today, 12:31 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post klaxtoncapital  
                            Started by PatutLee, Today, 11:59 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post PatutLee  
                            Working...
                            X