Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I need to add profit target variable

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

    I need to add profit target variable

    #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 SampleMACDCross : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "SampleMACDCross";
    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;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
    {
    EnterShort(DefaultQuantity, "");
    }

    how do I add a proft target variable input to this strategy and a stop loss also. thxs nt8

    #2
    See 'Builder Screens in NT8 guide. 'Condition and Action Screen Layout.

    var ProfitTarget =15, then SetProfitTarget(CalculationMode.Ticks, 10); link https://ninjatrader.com/support/help...ofittarget.htm
    Last edited by Emma1; 08-15-2020, 06:14 AM.

    Comment


      #3
      Hello neilzep,

      I recommend that you generate the Input variable and the Set profit target from the Strategy Builder and then copy the code to your script.

      Below is a link to the Strategy Builder 301 training video that demonstrates.
      https://youtu.be/HCyt90GAs9k?t=1457

      The code generated from the strategy builder will appear as:

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="ProfitDistance", Description="Number of ticks from entry target is placed", Order=1, GroupName="Parameters")]
      public int ProfitDistance
      { get; set; }

      ProfitDistance = 7;

      SetProfitTarget("", CalculationMode.Currency, ProfitDistance);

      Also, below is a link to a forum post with helpful information about getting started with NinjaScript.
      https://ninjatrader.com/support/foru...040#post786040
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by TradingLoss, Today, 04:39 PM
      14 responses
      197 views
      1 like
      Last Post NinjaTrader_EricB  
      Started by Gille1983, Today, 09:27 PM
      0 responses
      3 views
      0 likes
      Last Post Gille1983  
      Started by localappleseed, Today, 02:41 PM
      3 responses
      17 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by wooofad, Today, 11:34 AM
      1 response
      26 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by mr_trade, Today, 08:41 AM
      1 response
      21 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X