Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Stoploss not hitting per strategy
Collapse
X
-
Hello pyraxic,
Thanks for your reply.
When you are using Calculate.OnEachTick and using live data, the bar references change so that [0] is the currently forming bar.
If you want to use the previous bar then you would change it to [1] which would be the last/just closed bar.
-
Thank you, Paul. What is the best way to set stoploss one tick below the last closed bar? I am usingCode:SetStopLoss(@"Long", CalculationMode.Price, Low[0] - TickSize, false);
Leave a comment:
-
Hello pyraxic,
Thanks for your reply.
What you can do is to create a class level double type variable and store the stop price into it in OnOrderUpdate. Then in the OnBarUpdate() you can add a print statement to print out the time, the stop price, and the close price (current price) (you can comment out the print statement in OnOrderUpdate() as you will now be printing the same thing except in OnbarUpdate()). This then should help you see what is happening on a per-trade basis, to understand where the price is relative to the stop price as well as what the stop price is.
Leave a comment:
-
It gives me output like the following which isn't helpful.
stop price is: 3577.5
stop price is: 3577.5
stop price is: 3577.5
stop price is: 3577.5
stop price is: 3577.25
stop price is: 3577.25
stop price is: 3577.25
stop price is: 3577.25
stop price is: 3577
stop price is: 3577
stop price is: 3577
stop price is: 3577
stop price is: 3576.75
stop price is: 3576.75
stop price is: 3576.75
stop price is: 3576.75
stop price is: 3576.5
stop price is: 3576.5
stop price is: 3576.5
stop price is: 3576.5
stop price is: 3576.25
stop price is: 3576.25
stop price is: 3576.25
stop price is: 3576.25
stop price is: 3576
stop price is: 3576
stop price is: 3576
stop price is: 3576
stop price is: 3575.75
stop price is: 3575.75
stop price is: 3575.75
stop price is: 3575.75
stop price is: 3575.5
stop price is: 3575.5
stop price is: 3575.5
stop price is: 3575.5
stop price is: 3575.25
stop price is: 3575.25
stop price is: 3575.25
stop price is: 3575.25
stop price is: 3575
stop price is: 3575
stop price is: 3575
stop price is: 3575
stop price is: 3575
stop price is: 3575
stop price is: 3575
stop price is: 3578.75
stop price is: 3578.75
stop price is: 3578.75
stop price is: 3578.75
stop price is: 3578.75
stop price is: 3578.75
Leave a comment:
-
Hello pyraxic,
Thanks for your reply.
Everything looks correct.
Please recompile, remove strategy from the chart and then reapply the strategy and enable the strategy.
Leave a comment:
-
Hmm...it's not providing any output in the NinjaScript Output window. Here is my code. Am I missing anything?
Code:protected override void OnBarUpdate() { if (CurrentBar < BarsRequiredToTrade) return; if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; if (IsFirstTickOfBar){ TradeTaken = false; } // Enter Long if ((CrossAbove(MACD1.Default, MACD1.Avg, 1)) && Close[0] > Close[1] && TradeTaken == false) { EnterLong(Convert.ToInt32(DefaultQuantity), @"Long"); TradeTaken = true; } SetStopLoss(@"Long", CalculationMode.Price, Low[0] - TickSize, false); // Enter Short if ((CrossBelow(MACD1.Default, MACD1.Avg, 1)) && Close[0] < Close[1] && TradeTaken == false) { EnterShort(Convert.ToInt32(DefaultQuantity), @"Short"); TradeTaken = true; } SetStopLoss(@"Short", CalculationMode.Price, High[0] + TickSize, false); } protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment) { if (order.Name == "Stop loss") { Print ("stop price is: " + order.StopPrice); } }
Leave a comment:
-
Hello pyraxic,
Thanks for your reply.
Yes, it will work in the Strategy analyzer as well as live.
Leave a comment:
-
Originally posted by NinjaTrader_PaulH View PostHello pyraxic,
Thanks for your reply.
I would suggest debugging your strategy with print statements to help understand what is happening with the stop price.
In OnOrderUpdate() you can check to see if the order.Name is "Stop loss" and then print the price it is set to.
Here is an example:
protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
{
if (order.Name == "Stop loss")
{
Print ("stop price is: "+order.StopPrice);
}
}
The print statement sends it output to the new>Ninjascript output window.
Leave a comment:
-
Hello pyraxic,
Thanks for your reply.
I would suggest debugging your strategy with print statements to help understand what is happening with the stop price.
In OnOrderUpdate() you can check to see if the order.Name is "Stop loss" and then print the price it is set to.
Here is an example:
protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
{
if (order.Name == "Stop loss")
{
Print ("stop price is: "+order.StopPrice);
}
}
The print statement sends it output to the new>Ninjascript output window.
Leave a comment:
-
-
Originally posted by NinjaTrader_PaulH View PostHello pyraxic,
Thanks for your post.
Please check the "log" tab of the control center for any errors related to your strategy.
Is the screenshot from a live trade, or playback with market replay data, or just a historical trade on the chart or a historical trade in the Strategy analyzer?
What Calculate setting does the strategy run with? (Calculate.OnBarClose, Calculate.OnEachTick, Calculate.OnPriceChange)
Do you have any other code that could be setting the stop-loss to another value unexpectedly?
Code:SetStopLoss(@"Long", CalculationMode.Price, Low[0] - TickSize, false);
Leave a comment:
-
Hello pyraxic,
Thanks for your post.
Please check the "log" tab of the control center for any errors related to your strategy.
Is the screenshot from a live trade, or playback with market replay data, or just a historical trade on the chart or a historical trade in the Strategy analyzer?
What Calculate setting does the strategy run with? (Calculate.OnBarClose, Calculate.OnEachTick, Calculate.OnPriceChange)
Do you have any other code that could be setting the stop-loss to another value unexpectedly?
Leave a comment:
-
Stoploss not hitting per strategy
Hello,
I am trying to set the Stop-Loss one tick above the last bar and have the following code.
Code:// Enter Short if ((CrossBelow(MACD1.Default, MACD1.Avg, 1)) && TradeTaken == false && Close[0] < Close[1]) { EnterShort(Convert.ToInt32(DefaultQuantity), @"Short"); TradeTaken = true; } SetStopLoss(@"Short", CalculationMode.Price, High[0] + TickSize, false);
Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Taddypole, Today, 10:27 AM
|
1 response
3 views
0 likes
|
Last Post
|
||
Started by Unsuitable, Today, 10:20 AM
|
0 responses
4 views
0 likes
|
Last Post
![]()
by Unsuitable
Today, 10:20 AM
|
||
Started by sinpeople, Today, 09:36 AM
|
3 responses
6 views
0 likes
|
Last Post
|
||
Started by punkiy2111, Today, 09:17 AM
|
4 responses
13 views
0 likes
|
Last Post
![]()
by punkiy2111
Today, 10:03 AM
|
||
Started by Devside_Victor, Today, 08:43 AM
|
1 response
8 views
0 likes
|
Last Post
|
Leave a comment: