Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Delay Profit target on a daily basis

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

    Delay Profit target on a daily basis

    A have a Newbie question concerning delaying profittargets for the next bar=nextday. So no Profittarget on the same bar!
    My strategy is sofar daily and I created a simple approach.
    I thought that CalulateonBarclose = true always delays on the last daily bar.
    But for my Setprofittarget not. Why. I get on daily basis buys and sells on the same bar. Can you help me what I am doing wrong here. Thanks.

    [code]
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // 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")]
    public class TestDelay : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // 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>
    protected override void Initialize()
    {
    SetProfitTarget("", CalculationMode.Percent, 0.01);
    SetStopLoss("", CalculationMode.Percent, 10, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (RSI(14, 3).Avg[0] <= 35)
    {
    EnterLongLimit(DefaultQuantity, Close[0], "");
    }
    }

    #region Properties
    [Description("")]
    [Category("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }
    [code]

    #2
    Hello Munichtrader,

    Welcome to our forums.

    SetStopLoss() and SetProfitTarget() are submitted upon entry execution and the values set carry over from position to position.

    What you should consider doing is setting one value when flat and another after you have been in a position for one bar.

    The snippet below resets these values when flat:

    Code:
     
    if (Position.MarketPosition == MarketPosition.Flat)
    { 
    SetProfitTarget("", CalculationMode.Percent, 1);      // 1= 100%
    SetStopLoss("", CalculationMode.Percent, 1, false); //  1= 100%
    }
    Then this snippet will submit more realistic targets and stops once you have been in a position one bar.

    Code:
     
    if (BarsSinceEntry() == 1)
    {
    SetProfitTarget("", CalculationMode.Percent, .01);      // .01= 1%
    SetStopLoss("", CalculationMode.Percent, .01, false); //  .01= 1%
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Do set this in the code. Is this correct with this add function between?
      [CODE]
      protected override void Initialize()
      {
      Add(RSI(RSIPARA, 1));

      if (BarsSinceEntry() == 1)
      {

      SetProfitTarget("", CalculationMode.Percent, PROFITPER);
      SetStopLoss("", CalculationMode.Percent, 20, false);
      }

      CalculateOnBarClose = true;
      }
      [CODE]

      Comment


        #4
        Hello Munichtrader,

        If you are continuing my suggestion from earlier:

        The "Add" and "CalculateOnBarClose" statements belong in the Initialize() method.

        The Set statements belongs in OnBarUpdate().

        One additional thing to check is the values used for CalculationMode.Percent
        This should be a decimal value representing percent. In your example a value of 20 means 2000% For 20% use .2

        Please keep in mind the nature of these orders. My suggestion is good for backtesting but may not work properly in a live environment. This is because the SetMethods will carry their value from position to position unless reset. If you try to submit orders that are 100% away from price these orders are likely to be rejected by your broker.

        A different approach is to not use "Set" orders and instead conditionally submit ExitLongStop() or ExitLongLimit() orders.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hello again,

          but little confusing, if I use the editor then it places the stops in the initialize field.
          So I tried to follow your advise and change it, but no solution. it buys and sell on the same bar.
          [code]
          namespace NinjaTrader.Strategy
          {
          /// <summary>
          /// Enter the description of your strategy here
          /// </summary>
          [Description("Enter the description of your strategy here")]
          public class System : Strategy
          {
          #region Variables
          // Wizard generated variables
          private int rSIPARA = 5; // Default setting for RSIPARA
          private int rSILEVEL = 35; // Default setting for RSILEVEL
          private double pROFITPER = 0.017; // Default setting for PROFITPER
          // 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>
          protected override void Initialize()
          {
          Add(RSI(RSIPARA, 1));

          //SetProfitTarget("", CalculationMode.Percent, PROFITPER);
          //SetStopLoss("", CalculationMode.Percent, .1, false);


          CalculateOnBarClose = true;


          }


          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          if (Position.MarketPosition == MarketPosition.Flat)
          {
          SetProfitTarget("", CalculationMode.Percent, PROFITPER); // 1= 100%
          SetStopLoss("", CalculationMode.Percent, .1, false); // 1= 100%
          }
          // Condition set 1
          if (RSI(RSIPARA, 1).Avg[0] <= 35)

          {
          EnterLongLimit(DefaultQuantity, Close[0] , "");

          //if (BarsSinceEntry() >= 1)
          //ExitLongLimit(Close[0]* (1+PROFITPER));

          }
          if (BarsSinceEntry() == 1)
          {
          SetProfitTarget("", CalculationMode.Percent, PROFITPER); // .01= 1%
          SetStopLoss("", CalculationMode.Percent, .1, false); // .01= 1%
          }




          and another try, but this doesn´t work either.
          I added behind teh EnterLongLimit
          [code]
          if (BarsSinceEntry() >= 1)
          ExitLongLimit(Close[0]* (1+PROFITPER));

          I am looking for an profittarget but not on the same daily bar!

          Comment


            #6
            Please ignore my previous advice about using the Set methods in OnBarUpdate() This is mainly applicable when you want to do something to stop loss and profit target values once in a position.

            Start over with a new strategy and just use Exit statements. Don't include any "Set" methods so you can see the behavior without this. Add the BarsSinceEntry check if you want to be sure they are not submitted on the same bar.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Thanks. Good advice. Now it is working.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Unsuitable, Today, 07:26 PM
              0 responses
              1 view
              0 likes
              Last Post Unsuitable  
              Started by jvanelli, Today, 06:36 PM
              1 response
              6 views
              0 likes
              Last Post jeronymite  
              Started by twitch251, Today, 05:14 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by robforee2, Today, 05:07 PM
              0 responses
              4 views
              0 likes
              Last Post robforee2  
              Started by blar58, Today, 03:16 PM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Melissa  
              Working...
              X