Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Codes

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

    Codes

    Hi

    I am new to NT7. Have tried the Strategy Builder wizard but found it allows only Long or Short, but not both. Am I correct?

    Can someone help me find codes for -
    a. Long when current price > Open + user defined value (e.g. 5 bps)
    b. Short when current price < Open - user defined value
    c. Stop loss when -
    1. long : lowest low when bought
    2. short : highest high when bought

    Thank you

    #2
    Hello /\|/\,

    Thank you for writing in. You can create a strategy that reverses (goes from long to short and short to long) in the strategy wizard. You would set this up by using separate condition sets in the strategy wizard.

    I recommend going through our strategy wizard tutorial here to get a better understanding of how the strategy wizard works: https://www.youtube.com/watch?v=FmBiNYsf1e8

    For everything you mentioned however, I would recommend coding this rather than using the strategy wizard. To get started coding in NinjaTrader, I recommend the following video tutorial:
    https://www.youtube.com/watch?v=K8v_2ONBbqI
    As well as the following help guide resources:
    http://ninjatrader.com/support/helpG..._resources.htm

    In NinjaScript code, what you are trying to do might look something like this:
    Code:
    #region Variables
    private int plusMinusOpen;;
    #endregion
    protected override void Initialize()
    {
      CalculateOnBarClose = true;
      plusMinusOpen = 5;
    }
    protected override void OnBarUpdate()
    {
      if(GetCurrentAsk() > Open[0] + plusMinusOpen * TickSize)
      {
        EnterLong("Long");
        SetStopLoss("Long", CalculationMode.Price, Low[LowestBar(Low, CurrentBar)], false);
      }
      else if(GetCurrentAsk() < Open[0] - plusMinusOpen * TickSize)
      {
        EnterShort("Short");
        SetStopLoss("Short", CalculationMode.Price, High[HighestBar(High, CurrentBar)], false);
      }
    }
    #region Properties
        [Description("The number of ticks above the open to enter long or below the open to enter short.")]
        [GridCategory("Parameters")]
        public int PlusMinusOpen
        {
            get { return plusMinusOpen; }
            set { plusMinusOpen = Math.Max(1, value); }
        }
    #endregion
    Please let me know if you have any questions or if I may be of further assistance.
    Last edited by NinjaTrader_MichaelM; 11-15-2015, 04:20 PM.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Thanks Michael.

      When I backtest the following code I see all trades are executed at Open. Can this be amended to execute as per the code? Thanks.
      if (GetCurrentAsk() > High[1])
      {
      EnterLong("Long");
      }
      else if (GetCurrentBid() < Low[1])
      {
      EnterShort("Short");
      }

      Comment


        #4
        Hello /\|/\,

        Thank you for the update. When backtesting using the strategy analyzer in NinjaTrader 7, strategies will always be run with CalculateOnBarClose = true meaning that orders will always be executed on the open of the next bar. To get around this, you would want to add a smaller timeframe to your strategy and submit orders to that instead.

        An example of how to do this can be found don our forums here: http://ninjatrader.com/support/forum...ead.php?t=6652

        Here is a helpguide document to help you understand how multi-time frame strategies work in NinjaTrader 7: http://ninjatrader.com/support/helpG...lightsub=multi

        Please let me know if you have any questions or if I may be of further assistance.
        Michael M.NinjaTrader Quality Assurance

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by alifarahani, Today, 09:40 AM
        6 responses
        25 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Kaledus, Today, 01:29 PM
        5 responses
        13 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Waxavi, Today, 02:00 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by gentlebenthebear, Today, 01:30 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X