Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Strategy based on ATR

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

    Strategy based on ATR

    Hi,

    I'm trying to build a strategy based on ATR. So when a stock is coming for 7 days in a row I want to buy it. Based on ATR I Want to use a stop loss and profit traget is 50% of the atr.

    I tried a few hours to put tis in code but i'm stuck at this point:

    My code so far:


    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class Cesear7 : Strategy
    {
    ATR _atr;

    double _lowClose, _highClose;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Look for a 7 lower closes";
    Name = "Cesear7";
    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;
    HigherLowerNumberOfDays = 7;
    ATRPeriod = 10;
    ATRMultiple = 0.1;
    InitialCapital = 100000;
    }
    else if (State == State.Configure)
    {
    _atr = ATR(this.ATRPeriod);

    base.AddChartIndicator(_atr);

    base.ClearOutputWindow();
    }
    }

    protected override void OnBarUpdate()
    {
    SetState();

    if (isFlat)
    {
    if (ReachedNewLowClose)
    {
    Buy();
    }
    }
    else
    {
    if (IsLong && ReachedATR)
    base.ExitLong();
    }

    }

    void SetState()
    {
    _LowClose = MIN(this.Close, this.HigherLowerNumberOfDays)[0];
    _LowClose = MAX(this.Close, this.HigherLowerNumberOfDays)[0];

    Draw.Line(this, "high"+CurrentBar, 0, _highClose 0, _highClose, Brushes.Orange);
    Draw.Line(this, "low"+CurrentBar, 0, _lowClose 0, _highClose, Brushes.Orange);
    }

    I'm looking for some help in the right direction

    thx

    kristof

    #2
    Hello cube1984,

    Thank you for your note.

    We do not build custom indicators or strategies for customers however if you’d like I could have someone from our business development team pass over a list of professional Ninja Script consultants that you could contact about developing this for you.

    Please let us know if you’d like that information.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by selu72, Today, 02:01 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Started by WHICKED, Today, 02:02 PM
    2 responses
    10 views
    0 likes
    Last Post WHICKED
    by WHICKED
     
    Started by f.saeidi, Today, 12:14 PM
    8 responses
    21 views
    0 likes
    Last Post f.saeidi  
    Started by Mikey_, 03-23-2024, 05:59 PM
    3 responses
    51 views
    0 likes
    Last Post Sam2515
    by Sam2515
     
    Started by Russ Moreland, Today, 12:54 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Erick  
    Working...
    X