• 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 cashinvestor, Today, 04:40 AM
    0 responses
    2 views
    0 likes
    Last Post cashinvestor  
    Started by wildwex, Yesterday, 11:55 AM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Marco  
    Started by pancho_r, 07-11-2020, 04:01 PM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_Marco  
    Started by D Trader, 07-11-2020, 09:43 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by cassiano_sanches, 07-10-2020, 07:37 PM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X