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 am trying to learn how to use the strategy builder being a new user to NT8.
I am just trying to get a simple HMA (Hull moving avg) crossover and i can't get it to work.
I am just trying to state "when the 14 HMA crosses over the 14 HMA from bar ago, go long" and "when the 14 HMA crosses below the 14 HMA from bar ago, go short" and nothing is producing on the chart.
Any help would be appreciated. Attached is screen shots of the builder...
ran into that problem also.....no one had an answer.....so under NT7 i would create my strategy with strategy builder go in an copy the code that belonged to my strategy...then... you could just take the ATMStrategy ...copy it and incorporate the strategy inside of it.....give it a new name.....however..... I just did a copy and paste on the atm strategy in NT8....changed the name got an error.....not sure what it was....maybe a simple name does not match...should have gone into the compiler to see what the error was....worked under NT7
I read on NinjaTrader.com Support Forum that SampleATMStrategy is designed to work with Strategy Builder codes after they have been unlocked. So the question is, where is the ATMStategy code placed? Before or after the SB Code. If after, do I need the namespace and public class since they are already in the SB code? How much of the beginning if this is needed? Do I start at private string or do I need everything? I have copied the SampleATMStrategy code and placed it below. Any help will be appreciated.
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class SampleAtmStrategy : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDescriptionSampleATMStrategy;
Name = NinjaTrader.Custom.Resource.NinjaScriptStrategyNameSampleATMStrategy;
// This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = false;
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
// Make sure this strategy does not execute against historical data
if(State == State.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])
{
isAtmStrategyCreated = false; // reset atm strategy created check to false
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
isAtmStrategyCreated = true;
});
}
// Check that atm strategy was created before checking other properties
if (!isAtmStrategyCreated)
return;
// 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, please note you access the ATM strategy specific position object here
// the ATM would run self contained and would not have an impact on your NinjaScript strategy position and PnL
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));
}
}
}
}