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 kevenconster, Yesterday, 11:58 PM
    0 responses
    9 views
    0 likes
    Last Post kevenconster  
    Started by kttoprsht, Yesterday, 10:52 PM
    0 responses
    7 views
    0 likes
    Last Post kttoprsht  
    Started by kttoprsht, Yesterday, 10:51 PM
    0 responses
    6 views
    0 likes
    Last Post kttoprsht  
    Started by normanreeduscbdoil, Yesterday, 10:08 PM
    0 responses
    10 views
    0 likes
    Last Post normanreeduscbdoil  
    Started by herbalgrown1, Yesterday, 10:01 PM
    0 responses
    4 views
    0 likes
    Last Post herbalgrown1  
    Working...
    X