NexusFi: Find Your Edge


Home Menu

 





ADJUST ATR IN NQ


Discussion in NinjaTrader

Updated
    1. trending_up 1,089 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 1 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
 vicentecortess 
Benidorm Espaņa
 
Experience: Intermediate
Platform: ninjatrader
Trading: es nq mnq mes
Frequency: Daily
Duration: Minutes
Posts: 3 since Oct 2021
Thanks Given: 1
Thanks Received: 1

I WOULD LIKE TO KNOW HOW I CAN ADJUST MY STOP AND MY PROFIT TO THE ATR INDICATOR IN NINJATRADER WITH THE NQ.
I also wanted to know what unit the atr gives you in the NQ (points, dollars, etc.)


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
TradingView Opens Volume Footprint Data to Pine Script - …
TradingView
Day 97: Israel-Lebanon Ceasefire Struck Overnight -- WTI …
Traders Hideout
The Confluence Meter: A Multi-Layered Signal Framework B …
The Elite Circle
Hungary Called for Magyar at 97pct, Ending 16-Year Orban …
Prediction Markets & Event Contracts
Bookmap Global Plus Lifetime + Lifetime Addons For Sale
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
  #2 (permalink)
 BERN Algos 
Bologna Italy
 
Experience: Advanced
Platform: nt8
Broker: NinjaTrader
Trading: futures
Posts: 58 since Jun 2022
Thanks Given: 12
Thanks Received: 54


vicentecortess View Post
I WOULD LIKE TO KNOW HOW I CAN ADJUST MY STOP AND MY PROFIT TO THE ATR INDICATOR IN NINJATRADER WITH THE NQ.
I also wanted to know what unit the atr gives you in the NQ (points, dollars, etc.)

Hi vicentecortess,
here you are.
For more info NT has great online support. For example:
https://ninjatrader.com/it/support/helpGuides/nt8/NT%20HelpGuide%20English.html?setstoploss.htm


 
Code
#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;
using System.IO;
#endregion


/////////////////////////////////////////////////////////////////////////////////////
// Test_ATR_TP_SL 
// By BERN Algos
/////////////////////////////////////////////////////////////////////////////////////


namespace NinjaTrader.NinjaScript.Strategies
{
	public class Test_ATR_TP_SL : Strategy 
	{
		private ATR 			MyATR;

		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description = @"Test_ATR_TP_SL";
				Name = "Test_ATR_TP_SL";
				Calculate = Calculate.OnBarClose;
				EntriesPerDirection = 1;
				EntryHandling = EntryHandling.AllEntries;
				IsExitOnSessionCloseStrategy = true;
				ExitOnSessionCloseSeconds = 4230;
				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;
				IncludeTradeHistoryInBacktest = true;

				// Parameters initialization
				ATRPeriod	= 24;

			}
			else if (State == State.Configure)
			{
			}
			else if (State == State.DataLoaded)
			{				
				MyATR = ATR(ATRPeriod);
			}
			else if (State == State.Historical)
			{	
			}
		}

		protected override void OnBarUpdate()
		{
			if (BarsInProgress != 0) {return;}
			if (CurrentBars[0] < BarsRequiredToTrade) {return;}
			
			if ( Position.MarketPosition == MarketPosition.Flat) // set Take Profit and Stop Loss 
			{
				int appvar;
				appvar = (int)(MyATR[0]/TickSize);
				SetProfitTarget(CalculationMode.Ticks, appvar); //Take Profit equal to ATR
				SetStopLoss(CalculationMode.Ticks, 2*appvar);  //Stop Loss equal to twice the ATR
			}
			
			if (Close[0] > (Close[1] + MyATR[0]))		// enter long if close is higher than previous close + ATR 
				EnterLong();
				
			if (Close[0] < (Close[1] - MyATR[0]))		// enter short if close is lower than previous close - ATR
				EnterShort();
		}

		#region Properties
		
		[NinjaScriptProperty]
		[Range(1, int.MaxValue)]
		[Display(Name="ATRPeriod", Order=1, GroupName="Parameters")]
		public int ATRPeriod
		{ get; set; }			
		
		#endregion
	}
}


Attached Files
Elite Membership required to download: Test_ATR_TP_SL.zip
Reply With Quote
Thanked by:




Last Updated on February 13, 2023


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts