Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple Strategy question

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

    Simple Strategy question

    Hi, i would like to sell 2 contract once the last price is 10 ticks above the low of the previous bar , take profit at 9 tiicks and stop loss at 10 ticks, would this be the correct code for it:

    #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.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")]
    publicclass Yoram1 : Strategy
    {
    #region Variables
    // Wizard generated variables
    privateint 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>
    protectedoverridevoid Initialize()
    {
    SetProfitTarget(
    "", CalculationMode.Ticks, 9);
    SetStopLoss(
    "", CalculationMode.Ticks, 10, false);
    CalculateOnBarClose =
    true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (GetCurrentBid() + -10 * TickSize == Low[1])
    {
    EnterShort(
    2, "");
    }
    }
    #region Properties
    [Description(
    "")]
    [Category(
    "Parameters")]
    publicint MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    At a quick glance that should work. If you don't care about the "bid" price and want to just use the last closing price you can use Close[0] with CalculateOnBarClose set to false.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Determine the timrframe for bars to be used in strategy

      Ok, thanks for the answer, however i did not fnd where i can tell the analyzer to backtest my strategy using 1 day bar timeframe.

      Comment


        #4
        You can choose that when you are loading the strategy. In the dialog window that pops up for you to choose which strategy to backtest on there is a section near the top that allows you to choose timeframe. You can choose Daily from there.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I have a set of rules for two strategies. I wonder if I can do it in the condition builder. I managed to do some part but not all. Is here someone who can help me how to do them in the condition builder?

          Here are the rules:

          Strategy1: Should be run on a 5min chart. The first 5 min candle of the day will provide a range. If the current price ONE HOUR LATER is grater than the first candle's high, then enter a long position. If the current price is lower than the first candle's low then enter a short position. Close any position 30 minutes before the market closes.
          Example: first candle of the day on 5min chart: High:60 Low:55
          One hour later (lets say that the market opens at 8.00AM that would mean 9.00AM just to clear it) the price is at 61,23. That is grater then the high so it should enter a long position. If the price is at 54,80 then it would enter a short position. If the price is in between the high and low, there is no trade that day! The market closes at 4.30 PM. So the strategy should close any position at 4PM! Only one trade per day.

          Strategy2: I am looking for a bar that is: Its high is LOWER than the high of the previous bar. Its low is HIGHER than the previous bar's low.Lets name this bar X. So, bar "X"'s high-low should be the smallest amount. For example the high is 50;the low is 45.That would mean 5 for bar "X". I do this calculation for the past three bars. That would made the "X" bar the smallest among these for bars including the "X" bar.
          Now, when the current price is above the high of the "X" bar than enter long. If the current price is lower than the low of the "X" bar it should enter short. Closing price should be the low of the current bar and it should move up as the price does. High for short and it should move down with the price.

          Can someone help me to generate these two strategies?

          Comment


            #6
            If someone does not provide some help you can always -

            - Check with a NinjaScript Consultant
            - Attend our upcoming training class for strategy wizard development - http://www.ninjatrader.com/webnew/ev...evelopment.htm
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            646 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            367 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X