• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 RandanAL, Today, 05:13 PM
    0 responses
    0 views
    0 likes
    Last Post RandanAL  
    Started by timko, Today, 05:06 PM
    0 responses
    2 views
    0 likes
    Last Post timko
    by timko
     
    Started by ballboy11, Today, 01:04 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by Linda1507, Today, 01:22 PM
    2 responses
    15 views
    0 likes
    Last Post Linda1507  
    Started by ntbone, Today, 12:15 PM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X