Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I would like a user input in my strategy to be a previously defined Ninja ATM. Is this possible to do with the strategy builder or does anyone have any code samples of how to do it.
Thanks,
Mark
Can you help answer these questions from other members on NexusFi?
There is an ATM Strategy in NT....Strategy Examples....you have to add your code to it....Ive got one under NT7...have to go copy it and include it here....
Went into Strategy analyzer...created the strategy inside that....then copied the code into the ATM Strategy from NT....didnt have to write any code....
first is the original strategy from NT....ATM Sample......second is the same program with my code added to it...again the code was just copied from the analyzer once I created the strategy inside the wizard.....
Strategy..... to be executed from 9:30 - 3:30
Had to break the supertrendu11 and breakout of the dynamic SR color Band....then apply the ATM....note the Stop and Profit are not used because they are in the ATM Strategy.....
ON another note while putting this together during the last hour....was running the program in background(sim)...came up with $325......guess I should do some more testing....LOL
//
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
///
/// </summary>
[Description("")]
public class SampleAtmStrategy : Strategy
{
#region Variables
private string atmStrategyId = string.Empty;
private string orderId = string.Empty;
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// HELP DOCUMENTATION REFERENCE: Please see the Help Guide section "Using ATM Strategies"
// Make sure this strategy does not execute against historical data
if (Historical)
return;
// Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
// **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****
if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
}
// Check for a pending entry order
if (orderId.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderId);
// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// Print out some information about the order to the output window
Print("The entry order average fill price is: " + status[0]);
Print("The entry order filled amount is: " + status[1]);
Print("The entry order order state is: " + status[2]);
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderId = string.Empty;
}
} // If the strategy has terminated reset the strategy id
else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
atmStrategyId = string.Empty;
if (atmStrategyId.Length > 0)
{
// You can change the stop price
if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
// Print some information about the strategy to the output window
Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));
Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
}
}
#region Properties
#endregion
}
}
Sample of Program......the above program with my code inserted into it...….Note!! no backtesting just forward testing no History.....
//
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
///
/// </summary>
[Description("")]
public class TestATM : Strategy
{
#region Variables
private string atmStrategyId = string.Empty;
private string orderId = string.Empty;
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
private int profit = 10; // Default setting for Profit
private int stop = 8; // Default setting for Stop
private int sRParm = 9; // Default setting for SRParm
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(DynamicSR_ColorBand(true, Color.Silver, SRParm));
Add(anaSuperTrendU11(3, 2.5, 15, false, anaSuperTrendU11BaseType.Median, anaSuperTrendU11OffsetType.Default, anaSuperTrendU11VolaType.Simple_Range));
Add(DynamicSR_ColorBand(true, Color.Silver, 3));
Add(anaSuperTrendU11(3, 2.5, 15, false, anaSuperTrendU11BaseType.Median, anaSuperTrendU11OffsetType.Default, anaSuperTrendU11VolaType.Simple_Range));
SetProfitTarget("", CalculationMode.Ticks, Profit);
SetStopLoss("", CalculationMode.Ticks, Stop, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// HELP DOCUMENTATION REFERENCE: Please see the Help Guide section "Using ATM Strategies"
// Make sure this strategy does not execute against historical data
if (Historical)
return;
// Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
// **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****
if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
// Condition set 1
if (Close[0] > DynamicSR_ColorBand(true, Color.Silver, SRParm).Resistance[0]
&& Close[0] > anaSuperTrendU11(3, 2.5, 15, false, anaSuperTrendU11BaseType.Median, anaSuperTrendU11OffsetType.Default, anaSuperTrendU11VolaType.Simple_Range).StopDot[0]
&& ToTime(Time[0]) > ToTime(9, 30, 0)
&& ToTime(Time[0]) < ToTime(15, 30, 0)
&& Variable0 < MyInput0)
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Market, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
Variable0 = 1;
}
// Condition set 2
if (Close[0] < DynamicSR_ColorBand(true, Color.Silver, SRParm).Support[0]
&& Close[0] < anaSuperTrendU11(3, 2.5, 15, false, anaSuperTrendU11BaseType.Median, anaSuperTrendU11OffsetType.Default, anaSuperTrendU11VolaType.Simple_Range).StopDot[0]
&& ToTime(Time[0]) > ToTime(9, 30, 0)
&& ToTime(Time[0]) < ToTime(15, 30, 0)
&& Variable1 < MyInput0)
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Market, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
Variable1 = 1;
}
// Condition set 3
if (Close[0] < DynamicSR_ColorBand(true, Color.Silver, SRParm).Resistance[0])
{
Variable0 = 0;
}
// Condition set 4
if (Open[0] > DynamicSR_ColorBand(true, Color.Silver, SRParm).Support[0])
{
Variable1 = 0;
}
// Check for a pending entry order
if (orderId.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderId);
// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// Print out some information about the order to the output window
Print("The entry order average fill price is: " + status[0]);
Print("The entry order filled amount is: " + status[1]);
Print("The entry order order state is: " + status[2]);
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderId = string.Empty;
}
} // If the strategy has terminated reset the strategy id
else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
atmStrategyId = string.Empty;
if (atmStrategyId.Length > 0)
{
// You can change the stop price
// if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
// AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
// Print some information about the strategy to the output window
Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));
Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int Profit
{
get { return profit; }
set { profit = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int Stop
{
get { return stop; }
set { stop = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int SRParm
{
get { return sRParm; }
set { sRParm = Math.Max(1, value); }
}
#endregion
}
}
Trading: 6C (Low Margin,) 6E, CL, GC, ES and Maybe DX for smaller tick value
Posts: 1,394 since May 2011
Thanks Given: 1,719
Thanks Received: 1,020
@markbb10, @loantelligence probably means strategy wizard or builder reference to Strategy Analyzer to cull that code. But LoanIntelligence's plan does require you to break the NT8 SB code which means it limits your ability to keep throwing "What Ifs" at the strategy. Apologize if I am misreading it loantelligence.
If you want to stay within the Strategy Builder and have an ATM sort of capability it can be a bit difficult because Strategy Builder is never expected to add an ATM call even though many have requested it.
So the forum created a thread for how to do it "manually" in strategy builder so you can continue to do "what If's."
It can build out to 26 or more steps for a complex manual ATM. Plus there is no way to cancel them without ending the strategy while in a trade.
If you find a moderately successful BOT - please post here for others to help build it out better and point to it in free strategy thread. Unfortunately, apparently when a GOOD/Great strategy is developed - we stop hearing about it and it is lost to the people whom may have assisted in getting there.
Remember there are MILLIONS of traders out there. It is unlikely that sharing something on Futures.io will kill your profitability. In fact assuming you enliven multiple people trying to enter where you do -- it supports your entry level. But try to front run them on the exit --
The Dynamic SR Color Band is actually from 6.5....works fine in NT7 though....go to Indicators, Ninja Trader, 6.5, page 18....Dynamic SR....you can change the parms to anything my example is 3, I believe the norm is 21...I also use 9....you can also color the inside of the bands to make them stand out....as I did on my example...
Jmont1....Thanks...I have been looking for something like that for years.....no one has ever mentioned it before.... theyd all said just code it inside of the ATM example, however no ever knew how......will put some of those examples to work...Steve
Trading: 6C (Low Margin,) 6E, CL, GC, ES and Maybe DX for smaller tick value
Posts: 1,394 since May 2011
Thanks Given: 1,719
Thanks Received: 1,020
@markbb10, No one replied with how to fix the Trend but that may be OK.
Since I do not code, I understand how frustrating it can be to think you have a great setup but cannot find a way to automate it. So I went a bit further and created a Strategy builder for you. It probably has a better method than the trend signal since it can be adjusted based on the volume.
The indicator has a count that you can see on the Data box for Down and up. So rather than just rely on the standard -1, +1 - I am using the count on the up and down. They are both set to zero now. So below zero is short and above is long. BUT they zero can be adjusted to a number so you could say down needs to be at least -500 or up needs at least 250. This should work better for your testing and can be used for strategy optimization.
As always, if you set this up better and think we all could be helped from other settings OR more likely additional settings on other indicators, PLEASE post. It is highly unlikely in these markets that suddenly you will miss trades from others using similar BOTs.
If you need help figuring this out - you may contact me through a DM.