NexusFi: Find Your Edge


Home Menu

 





ADJUST ATR IN NQ


Discussion in NinjaTrader

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




 
Search this Thread

ADJUST ATR IN NQ

  #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: 0

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?
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
How to apply profiles
Traders Hideout
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 BERN Algos 
Bologna Italy
 
Experience: Advanced
Platform: nt8
Broker: NinjaTrader
Trading: futures
Posts: 42 since Jun 2022
Thanks Given: 11
Thanks Received: 38


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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts