Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Newbie in need of help

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

    Newbie in need of help

    I'd like to make a simple strategy that just looks at the last 2 bars (or current and previous, I'm not sure) and enters a order in the direction of the previous two like bars. I know this is a very simple strategy but I'm new and i want to build off this idea.

    Ex. If bar 2 and bar 1 are bullish place order at x-target and y-stop loss.

    #2
    Hello BTBX,

    Welcome to the NinjaTrader forums!

    What you want to do can be accomplished with a NinjaScript automated strategy. Using the strategy wizard is the best place to get started creating strategies. You can define conditions and actions in a point and click interface, with no coding required.

    Please see the following link


    There is a similar example to what you're looking for in the section How to make price data comparisons

    That will compare current close to 1 bar ago. You could create an additional condition then that compares close 1 bar ago to close 2 bars ago.

    Help with strategy action for order placement is available here:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the speedy reply

      Yes, I found that site by looking around on similar questions. But now I'm stuck with trying to figure out how to get it to work. I have the buy code set but the mark on the graph isn't showing up and its not placing the order. = ( This may take a while lol

      Comment


        #4
        Yes, there can definitely be a learning curve at first but it's also really powerful once you get the hang of it.

        Share the code you have so far and we can take a quick look. You can either copy / paste the code after hitting View code, or attach the .cs file from
        My Documents\NinjaTrader\bin\custom\strategy
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Here what i have so far

          #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>
          /// After two consecutive same color bars it scalps for 2 ticks.
          /// </summary>
          [Description("After two consecutive same color bars it scalps for 2 ticks.")]
          public class RuleOftwo : Strategy
          {
          #region Variables
          // Wizard generated variables
          // 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()
          {
          SetTrailStop("", CalculationMode.Ticks, 2, false);

          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (Close[0] > Close[1])
          {
          EnterLong(DefaultQuantity, "In");
          DrawArrowDown("Enter" + CurrentBar, true, 0, Close[0], Color.Blue);
          }
          }

          #region Properties
          #endregion
          }
          }

          #region Wizard settings, neither change nor remove
          /*@
          <?xml version="1.0" encoding="utf-16"?>
          <NinjaTrader>
          <Name>RuleOftwo</Name>
          <CalculateOnBarClose>True</CalculateOnBarClose>
          <Description>After two consecutive same color bars it scalps for 2 ticks.</Description>
          <Parameters />
          <State>
          <CurrentState>

          Comment


            #6
            note

            Keep in mind that's what i copied out of the code screen in the wizard. I don't know how to code that from scratch = p

            Comment


              #7
              That looks like it should produce some trades for you. You have a narrow trailstop set so you might run into issues where the stop loss is triggered on the same bar as the entry.

              I would make sure the strategy is enabled - Right Click on chart > Strategies > Select your strategy and set enabled to true.

              Scroll to the beginning of chart so you can then see how it behaves at the earliest historical point.
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Stanfillirenfro, Yesterday, 09:19 AM
              7 responses
              51 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by TraderCro, 04-12-2024, 11:36 AM
              4 responses
              69 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Mindset, Yesterday, 02:04 AM
              1 response
              15 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by agclub, 04-21-2024, 08:57 PM
              4 responses
              18 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by Irukandji, Today, 04:58 AM
              0 responses
              6 views
              0 likes
              Last Post Irukandji  
              Working...
              X