I have noticed that I have mixed up breakeven and trailing. I apologize for this. I am having also some difficulties in understanding how to reaplce tick values as user inputs for stop, target, and trailing, with percent values as user inputs. I have to review back the script changes I made. Thank you for your patience and assitance.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Request Breakeven Functions in Strategy Builder
Collapse
X
-
Hello Chelsea,
I have noticed that I have mixed up breakeven and trailing. I apologize for this. I am having also some difficulties in understanding how to reaplce tick values as user inputs for stop, target, and trailing, with percent values as user inputs. I have to review back the script changes I made. Thank you for your patience and assitance.
-
Hello guidoisot,
As example you can have a double variable used as an input.
[Range(1, double.MaxValue), NinjaScriptProperty]
[Display(Name = "DistancePercentInput", GroupName = "NinjaScriptParameters", Order = 0)]
public double DistancePercentInput
{ get; set; }
Set the default value for this in State.SetDefaults.
DistancePercentInput = .5;
Then supply this to SetStopLoss().
SetStopLoss(CalculationMode.Percent, DistancePercentInput);
https://ninjatrader.com/support/help...etstoploss.htmChelsea B.NinjaTrader Customer Service
- Likes 1
Comment
-
Hello guidoisot,
I am responding on behalf of Chelsea who is out of the office today.
These sorts of order submission behaviors with strategies will involve taking debugging steps to see why the orders have not been submitted. We can see the bar the strategy goes long after the bar where the order submission tok place. This bar where we see the execution marker will be the bar where the stop will be submitted. Processing historical data is always done with Calculate.OnBarClose, so backtesting in the Strategy Analyzer will always process the script logic in this fashion unless Tick Replay is used and another Calculate mode is forced in the strategy.
Since we are processing on bar close, the close of the bar where we see the execution marker will be the Close[0] used when submitting the stop.
For the first case, the bar did have a High 81 ticks up, but the strategy uses Calculate.OnBarClose so the order was submitted after the bar had climbed 81 ticks. Having the strategy calculate OnPriceChange or OnEachTick will have Close[0] update intrabar and allow the strategy to submit the order midbar. This would have allowed for the breakeven to be triggered. We don't see the initial stop for the same reason as the second case.
For the second case, the stop was submitted a specific distance below the Average Entry Price and since this was processed on the next bar, the stop was submitted to an invalid level which is noted when enabling TraceOrders.
To debug issues like this with your scripts, TraceOrders should be used to display issues with order submission in the output window. Since backtests pass over many bars at once, I would recommend opening the data box on the Strategy Analyzer Chart and enable Bar Indexes. You can then go back to the strategy code and add prints when CurrentBar equals that bar so you can identify specific information about what is going on in the strategy.
Publicly available information for debugging tips are linked below.
TraceOrders - https://ninjatrader.com/support/help...aceorders2.htm
Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm
Debugging with the Strategy Builder - https://www.screencast.com/t/8uvjfM8h
Please let us know if you haven any additional questions.Last edited by NinjaTrader_Jim; 01-16-2019, 03:18 PM.JimNinjaTrader Customer Service
- Likes 1
Comment
-
Thank you. Debugging is definetly a methodology a beginner as myself should learn! Regarding this breakeven script, I understand that it is an issue raising when there is a too wide open-to-close range for the first bar on the trade (unfortunately IB data are not tick by tick) . In the meantime I have been testing various inputs and in order to compensate for these not too frequent wide range 1st bars I am attaching to the script a wide stop: 350 in the sample test attached (either a stop loss or a trailing, I am not sure yet what works better). I am testing this method on a set of main futures and "IN THEORY" the first results do not look too bad (attached is print from the analyzer). A solution perhaps is in finding a way to tell the builder to treat the first bar in the trade in a different way from the following ones, but I have not yet figured out anything about this. Finally, with regard to this breakeven and/or trailing approach, another thing I wish to look at is attaching an ATM by unlocking the strategy created on the Builder. Thank you to both of you.
Comment
-
Hello guidoisot,
The main issue is the strategy is backtested with Calculate.OnBarClose and the stop is submitted to a level that becomes invalid once the first bar closes. If you enable Tick Replay and force the strategy to use another Calculate mode, OnBarUpdate will update on the price change or on a new tick which would submit the order at an appropriate level before that bar closes and the order's price level becomes invalid.
I edited my previous post for more clarity.
If you would like to still have the strategy use OnBarClose and not worry about using Tick Replay, I would recommend using our OnExecutionUpdate() method to submit your target and stop.
An example that demonstrates using OnExecutionUpdate and moving the Stop Loss is linked below. This example is publicly available.
SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm
I look forward to being of further assistance.JimNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jim View Post
I can see the plots "Trend Dots" and "Trend Bars" of the indicator in the chart "Data Box" , so I understand they should be printed.
Thank you.
Comment
-
Hello guidoisot,
The Data Box will show values for plots and Open, High, Low, Close values for the Data Series. These values will reflect where your mouse cursor is. I recommend using the Crosshair when using the Data Box. The Data Box can also have Bar Indexes and Bars Ago indexes added which can help with NinjaScript development. These can be enabled when right clicking on the data box.
Prints are displayed in the NinjaScript Output window, and I don't see this window open in your screenshot. A NinjaScript Output window can be opened by selecting New > NinjaScript Output from the Control Center. Any prints that are reached will then be displayed in the Output window. If you are not seeing prints, I would suggest to check for errors in the log tab of the Control Center and to check the logic to make sure the prints can be reached.
Let us know if there is anything else we can do to help.JimNinjaTrader Customer Service
- Likes 1
Comment
-
NinjaTrader_ChelseaB Attempted to duplicate NT8 MA crossover with the Break Even and Trail Stops. Truly would like to use the same Stop Market order in your examples but for some reason they do not trigger. Set7 & 8 both should use the stop market that is listed as first exit. Unfortunately since they do not seem to fire I backed them up with Stop Limit orders under a different name to distinguish which one fires.
If the second limit orders are removed the stop market still does not fire.
May I request you test to ensure Strategy Builder's stop market order is working correctly? Thank you.Last edited by JMont1; 07-21-2019, 06:04 AM.
Comment
-
Originally posted by NinjaTrader_ChelseaB View PostHello JMont1,
To confirm the issue is stop limit orders are not being submitted?
Are you receiving an error message?
(If so what is the error message?)
If you remove the final exit, neither of the other exit types are working. Thank you for taking a look.
Sunday 3pm update: Removing script to update iit again.Last edited by JMont1; 07-21-2019, 01:08 PM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Graci117, Today, 09:02 PM
|
1 response
4 views
0 likes
|
Last Post Today, 09:09 PM | ||
Started by ETFVoyageur, Today, 07:55 PM
|
0 responses
7 views
0 likes
|
Last Post
by ETFVoyageur
Today, 07:55 PM
|
||
Started by janio973, Today, 07:24 PM
|
1 response
7 views
0 likes
|
Last Post Today, 07:35 PM | ||
Started by aligator, 01-06-2022, 12:14 PM
|
4 responses
246 views
0 likes
|
Last Post
by john_44573
Today, 06:11 PM
|
||
Started by reynoldsn, Today, 05:56 PM
|
0 responses
14 views
0 likes
|
Last Post
by reynoldsn
Today, 05:56 PM
|
Comment