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 arvidvanstaey, Today, 02:19 PM
    4 responses
    11 views
    0 likes
    Last Post arvidvanstaey  
    Started by samish18, 04-17-2024, 08:57 AM
    16 responses
    61 views
    0 likes
    Last Post samish18  
    Started by jordanq2, Today, 03:10 PM
    2 responses
    9 views
    0 likes
    Last Post jordanq2  
    Started by traderqz, Today, 12:06 AM
    10 responses
    18 views
    0 likes
    Last Post traderqz  
    Started by algospoke, 04-17-2024, 06:40 PM
    5 responses
    48 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X