Running my strategy in historical mode, I have the following problem: The strategy places the first order "ST1_L_EX-RV__XTRA1_1.105R_1" and there comes a point where I have to close it in loss, when I do it, the ExitLong() order is executed (seen in the graph), in that same bar I am placing another order ("ST1_L_EX-RV__XTRA1_1.105V_2"). The order is recorded correctly but, apparently before, the ExitLong() of the previous one gives error, as seen in the log the second order raises the price and I put it in BE (SetStopLoss (ST1_L_EX-RV__XTRA1_1.105V_2, CalculationMode.Price, 1859 , 25, true)), without errors. But as you can see, the price goes up and does not take the exit order. After this the price falls and the strategy manages an exit price that is equal to BE and does not change the Profit to BE, then it goes to waste and the ExitLong () kills me. Any idea? Thanks Mariano!
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
SetStopLoss() don't working, before an internal error
Collapse
X
-
SetStopLoss() don't working, before an internal error
Hello community!!!
Running my strategy in historical mode, I have the following problem: The strategy places the first order "ST1_L_EX-RV__XTRA1_1.105R_1" and there comes a point where I have to close it in loss, when I do it, the ExitLong() order is executed (seen in the graph), in that same bar I am placing another order ("ST1_L_EX-RV__XTRA1_1.105V_2"). The order is recorded correctly but, apparently before, the ExitLong() of the previous one gives error, as seen in the log the second order raises the price and I put it in BE (SetStopLoss (ST1_L_EX-RV__XTRA1_1.105V_2, CalculationMode.Price, 1859 , 25, true)), without errors. But as you can see, the price goes up and does not take the exit order. After this the price falls and the strategy manages an exit price that is equal to BE and does not change the Profit to BE, then it goes to waste and the ExitLong () kills me. Any idea? Thanks Mariano!1 PhotoTags: None
-
Hello mbcito,
You are receiving an error message?
What is the full error message?
Are you asking about the behavior of the strategy?
Print the values used in the conditions that trigger the behavior, print the order object from OnOrderUpdate(), and enable TraceOrders.
Chelsea B.NinjaTrader Customer Service
Comment
-
Chelsea, please view de screenshot I've taked and uploaded in the post.
The full error is "Strategy 'XXXXXX-1': An Set() method to submit an exit order at '27/1/2016 04:40:00' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation." This error occurs asynchronously.
In the image you have the chart and the output.
Code:Orden (i=0) -- onBar: 100 || 9 Contratos= ST1_L_EX-RV__XTRA1_1.105R_1 -- EntryPrice= 1879,75 -- TP= 1883 -- SL= 1873,25 GestionTrade() 1.50 MTRA LONG: Time 27/1/2016 04:35:00 -- SetProfitTarget(ST1_L_EX-RV__XTRA1_1.105R_1, CalculationMode.Price, 1880,25, true) -- cierreMinimo=1876,5 -- oValTrampa[i]= 1879 OnBarUpdate()_1.10 CurrentBars[0]= 103 -- barBody= 3,75 - expresion= False OnBarUpdate()_1.12 CurrentBars[0]= 103 -- barBody= 3,75 - ( ( (( (1880,5-1876) / 2)*1.1) >= (1880,25-1876) ) && ( (( (1880,5-1880,5) / 2)*0.9) <= (1880,25-1876) ) ) OnBarUpdate()_1.30 CurrentBars[0]= 103 -- barBody= 3,75 - myHammer= False analizaPivotes(1)_2.7 nPivot[I]= 80 -- (Bars.GetHigh(nPivot[I]) == maxPivot[I])= False -- Bars.GetHigh(nPivot[I])= 1881,75 -- maxPivot[I]= 1883 analizaTrade()_1.8 -27/1/2016 04:40:00 -- oTakeProfit[norder]= 1883 Orden (i=1) -- onBar: 103 || 5 Contratos= ST1_L_EX-RV__XTRA1_1.105V_2 -- EntryPrice= 1877,25 -- TP= 1883 -- SL= 1865,75 GestionTrade() 2.00 SL LONG: Order : ST1_L_EX-RV__XTRA1_1.105R_1 -- Close=1877,25 < R50%=1877,5 - Ask=1877,25 -- Bid=1877,25 GestionTrade() 2.10 SL LONG: Order : ST1_L_EX-RV__XTRA1_1.105R_1 i= 0-- oEntryPrice[i]=1880,25 -- oTakeProfit[i]=1883 GestionTrade() 2.20 SL LONG: ExitLong(ST1_L_EX-RV__XTRA1_1.105R_1) Strategy 'XXXXXX/-1': An Set() method to submit an exit order at '27/1/2016 04:40:00' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation. Pos Closed OnBar: 103 - Trade= ST1_L_EX-RV__XTRA1_1.105R_1, Entry time: 27/1/2016 04:25:00 | tradePnL: -1270,26 | Bid: 1877,25- Ask: 1877,25 | currentPnL: -1270,26 GestionTrade() 5.30 R50%M LONG: Time[0]=27/1/2016 04:55:00 - SetStopLoss(ST1_L_EX-RV__XTRA1_1.105V_2, CalculationMode.Price, 1877,5, true) - CurrentBars[0]= 106 GestionTrade() 1.50 MTRA LONG: Time 27/1/2016 05:05:00 -- SetProfitTarget(ST1_L_EX-RV__XTRA1_1.105V_2, CalculationMode.Price, 1877,5, true) -- cierreMinimo=1875,5 -- oValTrampa[i]= 1876 Orden (i=0) -- onBar: 131 || 6 Contratos= ST1_L_EA-45%N__XTRA1_1.105V_3 -- EntryPrice= 1875 -- TP= 1879,5 -- SL= 1866 GestionTrade() 5.30 R50%M LONG: Time[0]=27/1/2016 07:30:00 - SetStopLoss(ST1_L_EA-45%N__XTRA1_1.105V_3, CalculationMode.Price, 1875,5, true) - CurrentBars[0]= 137 GestionTrade() 4.40 R50%M_H LONG: SetStopLoss(ST1_L_EA-45%N__XTRA1_1.105V_3, CalculationMode.Price, 1875,5, true) -- TipoGestion: GES_BE Pos Closed OnBar: 141 - Trade= ST1_L_EA-45%N__XTRA1_1.105V_3, Entry time: 27/1/2016 07:00:00 | tradePnL: 1253,16 | Bid: 1878- Ask: 1878 | currentPnL: -17,1000000000001 Orden (i=0) -- onBar: 153 || 5 Contratos= ST1_L_EA-100__HAMM_1.105V_4 -- EntryPrice= 1875,25 -- TP= 1880,75 -- SL= 1864,25 GestionTrade() 5.30 R50%M LONG: Time[0]=27/1/2016 09:10:00 - SetStopLoss(ST1_L_EA-100__HAMM_1.105V_4, CalculationMode.Price, 1875,5, true) - CurrentBars[0]= 157 GestionTrade() 4.40 R50%M_H LONG: SetStopLoss(ST1_L_EA-100__HAMM_1.105V_4, CalculationMode.Price, 1875,5, true) -- TipoGestion: GES_BE Pos Closed OnBar: 161 - Trade= ST1_L_EA-100__HAMM_1.105V_4, Entry time: 27/1/2016 08:50:00 | tradePnL: 1356,8 | Bid: 1879,75- Ask: 1879,75 | currentPnL: 1339,7 Pos Closed OnBar: 271 - Trade= ST1_L_EX-RV__XTRA1_1.105V_2, Entry time: 27/1/2016 04:40:00 | tradePnL: -1580,7 | Bid: 1870,5- Ask: 1870,5 | currentPnL: -241
Thanks!
Comment
-
Hello mbcito,
TraceOrders is not appearing in the output you have posted.
Also, please comment out all other prints you may be using so that we may focus on the issue at hand.
Why was the order ignored?
Was this before BarsRequiredToTrade was met?
Was an order placed while another order was working?
Below is a link to the help guide on internal handling rules.
Which rule is being violated?Chelsea B.NinjaTrader Customer Service
Comment
-
Here the log
The problem is with "ST1_L_EX-RV__XTRA1_1.105R_1" order after do an ExitLong the "ST1_L_EX-RV__XTRA1_1.105V_2'" order becomes unmanaged it seems like active because I use this code to do my managing:
When I'm submitting an order, always set up (Profit and Loss) my orders and I do this without conditionals.
Code:protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition) { for (int i = 0; i < entryOrders.Length; i++) { // if this order is not null and is filled if (entryOrders[i] != null && entryOrders[i].OrderState == OrderState.Filled ) { // Correct entryprice // look through all all trades to see if this order matches of those trades entry orders foreach (Trade thisTrade in SystemPerformance.AllTrades) { // if found, collect the performance, set the IOrder to null and break the loop if (thisTrade.Entry.Order == entryOrders[i]) { // here my code } ...
Thanks!
Attached Files
Comment
-
Hello mbcito,
I am seeing the error:
"Strategy 'CodigoTradingBALTA/-1': An Set() method to submit an exit order at '27/1/2016 04:40:00' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation."
Is this the error in question?
From the help guide:
"Set() methods that generate orders to exit a position will be ignored if:
•A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
•A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active"
Is there an entry order working?
Is there an exit order working?
Chelsea B.NinjaTrader Customer Service
Comment
-
Hi Chelsea.
These error occurs when the algo makes an ExitLong() ( but the order is still active, because the system constantly finds it active at every OnPositionUpdate(), as if the trade doesn't exist, which the same log indicates no, rejecting the following ExitLong ever and ever) , in the same bar another entry order is generated ( both orders come crazy, ).
This problem only occurs when one position is closed and another is opened in the same bar OnBarUpdate().
Thank you!
Comment
-
Hello mbcito,
I do not think the error occurs when calling ExitLong().
The message is stating the error is with a set method like SetStopLoss() and not with an exit method like ExitLong().
If there is a position and there is a working entry order or a working exit order, the Set method call will be ignored.
Having an entry and an exit in the same pass of OnBarUpdate does not allow for enough time for the order to be submitted, be received and become working, fill, send an message back to NinjaTrader that the order has filled, the execution to be processed in OnExecutionUpdate(), and then the position to change in OnPositionUpdate().
Either wait until the next bar, or submit the order in OnPositionUpdate() / OnExecutionUpdate() after the position has updated.Chelsea B.NinjaTrader Customer Service
- Likes 1
Comment
-
Yes Chelsea, I think the same about what StopLoss(). This error only happens once in 3 years of backtest. The strange thing is that order 2 is crazy and I can't control it with the Sets ... I'm going to continue investigating until I can control this.
Since I have a basic question: The OnBarUpdate (), OnPositionUpdate () ... events, Do they are executed in different threads?
Thanks a Lot!!!
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Net Change
by Segwin
Started by Segwin, 05-07-2018, 02:15 PM
|
14 responses
1,788 views
0 likes
|
Last Post
by aligator
Today, 11:47 AM
|
||
Started by Jimmyk, 01-26-2018, 05:19 AM
|
6 responses
837 views
0 likes
|
Last Post
by emuns
Today, 11:27 AM
|
||
Started by jxs_xrj, 01-12-2020, 09:49 AM
|
6 responses
3,292 views
1 like
|
Last Post
by jgualdronc
Today, 10:56 AM
|
||
Started by Touch-Ups, Today, 10:36 AM
|
0 responses
12 views
0 likes
|
Last Post
by Touch-Ups
Today, 10:36 AM
|
||
Started by geddyisodin, 04-25-2024, 05:20 AM
|
11 responses
62 views
0 likes
|
Last Post Today, 10:08 AM |
Comment