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
No suitable method found to override...
Collapse
X
-
Hello itrader46, thanks for your reply.
The code you posted is OK as long as 'y' in this formula is not returning a whole number: stopPriceLong - y. 'y' would be some calculation of ticks. They do this in the example because doubles can sometime return non-whole numbers. If you did not want to do this you can confirm that 'y' is a whole number by taking the floor or ceiling of that number. See these two pages on the floor and ceiling methods:
https://docs.microsoft.com/en-us/dot...tframework-4.8 - Math.Floor()
https://docs.microsoft.com/en-us/dot...tframework-4.8 Math.Ceiling()
-
Hello
I have a question about the floating point arithmetic: in the Sample On Order Update strategy is explained that rather than setting 4 ticks, we should be using (7 * (TickSize / 2)).
Can you please tell me why not (8 * (TickSize / 2)) and, more importantly, should I use the same method myself?
Would that have to be instead of " currentAsk <= stopPriceLong - CancelOffsetTicks * TickSize " something like " currentAsk <= stopPriceLong - ((CancelOffsetTicks + 1) * TickSize / 2) "?
In case (8 * (TickSize / 2)) would not be fine, than how would I need to rewrite my syntax in case CancelOffsetTicks = 3, 5... etc
Leave a comment:
-
Hello itrader46, thanks for your reply.
I was replying to this issue here in my last post:
Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
For high volatility, you can either run some code on the bar close using IsFirstTickOfBar or you can add a low period SMA (2-4 period) to your condition and compare the current price and that SMA. That can reduce the number of times a condition is hit. Sorry, I didn't your questions about OnOrderUpdate/ExecutionUpdate. Those will not be applicable when using ATM strategies in your script. When the script submits an ATM order it executes a command for the NinjaTrader core to carry out. We have an example here that uses OnOrderUpdate/ExecutionUpdate to submit protective orders:
https://ninjatrader.com/support/help...and_onexec.htm
Leave a comment:
-
I posted issues with two errors, so which are you referring to?
Also, what about my questions about the timing and OnOrder/ExecutionUpdate?
Leave a comment:
-
Hello itrader46, thanks for your reply.
That error is coming up just because the script is calculating on each tick. There is a certain amount of time between the ATM order creation and getting back to OnBarUpdate that causes the strategy to not recognize the order ID. The error won't affect anything about the strategy. The only way around that would be to use your own stop and target orders.
Leave a comment:
-
Hello
I've sorted out the compile error now, but I am still getting the following errors when using OnEachTick calculation mode.
This is a strategy I've adapted after the Sample Atm Strategy Reversal from NT User App Share and the original strategy prints the same errors when calculating on each tick, but when in On Bar Close, it doesn't print the errors.
I've downloaded the executions into an Excel format and looked for that order ID missing and true enough, it's not there, so what am I missing?
Is this even an issue, given that the strategy seems to run fine anyway?
Short condition at: 52.76 @ 17/10/2019 14:41:00
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
'GetAtmStrategyEntryOrderStatus' method error: Order ID '97e93dd5cbe94cdbb27d8592c977b317' does not exist
Short ATM created at: 52.76
This is my code:
if(State == State.Historical)
return;
currentBid = GetCurrentBid(0);
currentAsk = GetCurrentAsk(0);
// Check any pending long or short orders by their Order Id and if the ATM has terminated.
// Check for a pending long order.
if (longOrderId.Length > 0)
{
// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements.
string[] status = GetAtmStrategyEntryOrderStatus(longOrderId);
if (status.GetLength(0) > 0)
{
// If the order state is terminal, reset the order id value.
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
longOrderId = string.Empty;
// longOrderResetPrice = GetCurrentAsk(0);
// Print(Time[0] + " - " + "Long Order ID Reset Price: " + Convert.ToString(longOrderResetPrice));
}
}
// If the strategy has terminated reset the strategy id.
else if (longAtmId.Length > 0 && GetAtmStrategyMarketPosition(longAtmId) == Cbi.MarketPosition.Flat)
{
longAtmId = string.Empty;
isLongAtmStrategyCreated = false;
// longAtmResetPrice = GetCurrentAsk(0);
// Print(Time[0] + " - " + "Long ATM ID Reset Price: " + Convert.ToString(longAtmResetPrice));
}
if(LONG CONDITION TRUE)
{
if (longAtmId.Length == 0)
{
Print("Long condition at: " + Convert.ToString(currentAsk) + " @ " + Time[0]);
}
// If there is a short ATM Strategy running close it.
if(shortAtmId.Length != 0 && isShortAtmStrategyCreated)
{
AtmStrategyClose(shortAtmId);
isShortAtmStrategyCreated = false;
}
// Ensure no other long ATM Strategy is running.
if(longOrderId.Length == 0 && longAtmId.Length == 0 && !isLongAtmStrategyCreated)
{
longOrderId = GetAtmStrategyUniqueId();
longAtmId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.StopLimit, (GetCurrentAsk(0) + (StopOffsetTicks * TickSize)), (GetCurrentAsk(0) + (StopOffsetTicks * TickSize)),
TimeInForce.Day, longOrderId, "3C", longAtmId, (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 == longAtmId)
isLongAtmStrategyCreated = true;
stopPriceLong = GetCurrentAsk(0);
Print("Long ATM created at: " + Convert.ToString(stopPriceLong));
});
}
}
else if (longAtmId.Length != 0 && isLongAtmStrategyCreated && LONG CONDITION FALSE && currentAsk <= stopPriceLong - CancelOffsetTicks * TickSize
/*|| SHORT CONDITION TRUE*/)
{
AtmStrategyClose(longAtmId);
isLongAtmStrategyCreated = false;
cancelPriceLong = GetCurrentAsk(0);
Print("Long ATM cancel price: " + Convert.ToString(cancelPriceLong));
}
Also, when I add in the " else if " cancellation code the bit that says " || SHORT CONDITION TRUE ", I'm getting some additional errors about missing ID parameter in the close method:
I can't quite get it how does it get to this error here, when I just copy-paste the syntax I am using in triggering the Short positions.
Long condition at: 52.96 @ 17/10/2019 14:21:00
'AtmStrategyClose' method error: Missing ATM strategy ID parameter
Short ATM cancel price: 52.95
'GetAtmStrategyEntryOrderStatus' method error: Order ID '74792d13770b42dbb564d32909c841f6' does not exist
Long condition at: 52.96 @ 17/10/2019 14:20:16
'AtmStrategyClose' method error: Missing ATM strategy ID parameter
Short ATM cancel price: 52.95
Long ATM created at: 52.97
Long condition at: 52.97 @ 17/10/2019 14:21:00
'AtmStrategyClose' method error: Missing ATM strategy ID parameter
Short ATM cancel price: 52.95
Long condition at: 52.97 @ 17/10/2019 14:20:16
'AtmStrategyClose' method error: Missing ATM strategy ID parameter
Short ATM cancel price: 52.95
Long condition at: 52.97 @ 17/10/2019 14:21:00
'AtmStrategyClose' method error: Missing ATM strategy ID parameter
Short ATM cancel price: 52.95
Long condition at: 52.97 @ 17/10/2019 14:20:16
'AtmStrategyClose' method error: Missing ATM strategy ID parameter
Short ATM cancel price: 52.95
Long condition at: 52.97 @ 17/10/2019 14:21:00
'AtmStrategyClose' method error: Missing ATM strategy ID parameter
Finally, in times of high volatility, it submits and cancels so many orders in such a quick succession, that most of the times it gets it wrong eventually.
Do I have the possibility to enter an additional timing filter on top of my pullback condition given by " ...&& LONG CONDITION FALSE && currentAsk <= stopPriceLong - CancelOffsetTicks * TickSize "?
Something like: if the triggering condition becomes false and the price pulled back X ticks and more than X seconds passed, then cancel the entry order?
Should I try using the OnOrderUpdate or OnExecutionUpdate, or these methods don't apply to orders triggered by ATM? I'm not quite sure of that.
Thank you
Leave a comment:
-
Hello itrader46,
TraceOrders will only show information for orders that affect the NinjaScript Strategy. Atm Strategy method orders do not affect the strategy, or the strategy performance, or the strategy position, and do not trigger any order methods.
Think of these as the same as triggering a manual order.
First, what is the compile error message and what line is it on?
What is the code on that line?
Regarding the ID, what is the ID string you are supplying to the method GetAtmStrategyUnrealizedProfitLoss() call?
If you test the script included with NinjaTrader without making modifications are you able to reproduce the behavior?
Do you have an Atm Strategy template with the specific name 'AtmStrategyTemplate'?
Leave a comment:
-
...And these are the error messages the system SampleAtmStrategy prints plus, just like I said, there are no Trace order prints, even when I copy the logic and add TraceOrders = true
The entry order average fill price is: 1491.3
The entry order filled amount is: 3
The entry order order state is: Filled
The current ATM Strategy market position is: Long
The current ATM Strategy position quantity is: 3
The current ATM Strategy average price is: 1491.3
The current ATM Strategy Unrealized PnL is: -29.9999999999727
The current ATM Strategy market position is: Long
The current ATM Strategy position quantity is: 3
The current ATM Strategy average price is: 1491.3
The current ATM Strategy Unrealized PnL is: -60.0000000000136
'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
The current ATM Strategy market position is: Flat
'GetAtmStrategyPositionQuantity' method error: Missing ATM strategy ID parameter
The current ATM Strategy position quantity is: 0
'GetAtmStrategyPositionAveragePrice' method error: Missing ATM strategy ID parameter
The current ATM Strategy average price is: 0
'GetAtmStrategyUnrealizedProfitLoss' method error: Missing ATM strategy ID parameter
The current ATM Strategy Unrealized PnL is: 0
'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
The current ATM Strategy market position is: Flat
Leave a comment:
-
I'm struggling to do the condition of cancelling the order before execution, no matter how many variants I am doing
When I use the syntax below, from the help guide, I get the compiling error that || cannot be used with 'char' and 'string'
protected override void OnBarUpdate()
{
// ATM strategy methods only work during real-time
if (State != State.Realtime)
return;
string[] entryOrder = GetAtmStrategyEntryOrderStatus("orderId");
// checks if the entry order exists
// and the order state is not already cancelled/filled/rejected
if (entryOrder.Length > 0 && entryOrder[2] == "Working")
{
AtmStrategyCancelEntryOrder("orderId");
}
}
... while this (from Sample ATM strategy), doesn't reset the ATM id
else if (longAtmId.Length > 0 && isLongAtmStrategyCreated && (CONDITION) && (currentAsk <= stopPrice - CancelOffsetTicks * TickSize))
/*|| (longOrderId.Length != 0 && isLongAtmStrategyCreated && currentBid > stopPrice))*/
{
longAtmId = string.Empty;
... and neither do
AtmStrategyCancelEntryOrder(longOrderId);
OR
AtmStrategyClose(longAtmId);
Leave a comment:
-
Hi itrader46,
This error means you are accessing an ATM ID that doesn't exist in the system: GetAtmStrategyEntryOrderStatus' method error: Order ID 'ce5a...' does not exist.
Is seems like you're not using the most up to date ID for the ATM strategy. Can you confirm you are performing the ATM order submission similar to how it is done in the SampleATMStrategy code?
Leave a comment:
-
Can you please tell me what these errors mean?
'GetAtmStrategyEntryOrderStatus' method error: Order ID 'ce5a6d56af3142229b78055ca009f4da' does not exist
Bid: 1488.1 - Ask: 1488.2
'GetAtmStrategyEntryOrderStatus' method error: Order ID 'ce5a6d56af3142229b78055ca009f4da' does not exist
09/10/2019 23:01:00 - Trigger Price Long: 1488.2
Bid: 1488 - Ask: 1488.2
Bid: 1488 - Ask: 1488.2
Bid: 1488 - Ask: 1488.2
Bid: 1488 - Ask: 1488.2
Bid: 1488 - Ask: 1488.2
Bid: 1488 - Ask: 1488.2
Bid: 1488 - Ask: 1488.2
Bid: 1487.9 - Ask: 1488
Bid: 1487.9 - Ask: 1488
Bid: 1487.9 - Ask: 1488
Bid: 1487.9 - Ask: 1488
11/10/2019 19:30:00 - Cancel Price Long: 1488
Bid: 1487.9 - Ask: 1488
11/10/2019 19:30:00 - Cancel Price Long: 1488
Bid: 1487.9 - Ask: 1488
11/10/2019 19:30:00 - Cancel Price Long: 1488
Bid: 1487.9 - Ask: 1488
11/10/2019 19:30:00 - Cancel Price Long: 1488
Bid: 1487.9 - Ask: 1488
11/10/2019 19:30:00 - Cancel Price Long: 1488
Bid: 1487.9 - Ask: 1488
11/10/2019 19:30:00 - Cancel Price Long: 1488
Bid: 1487.9 - Ask: 1488
'AtmStrategyCancelEntryOrder' method error: Missing order ID parameter
11/10/2019 19:30:00 - Cancel Price Long: 1488
Bid: 1487.9 - Ask: 1488
Long ATM Reset
Leave a comment:
-
Hi itrader46,
The GetAtmStrategyEntryOrderStatus method returns an array of three strings where the order is as such:
Print("Average fill price is " + entryOrder[0].ToString());
Print("Filled amount is " + entryOrder[1].ToString());
Print("Current state is " + entryOrder[2].ToString());
This will be a good time to Print out whatever status[0] status[1] and status[2] is in your script to make sure you're making the right comparisons. The Price series collection just happens to be arrays as well, and the way you access prior data would be to iterate through the indices, but that is not applicable here.
Leave a comment:
-
I managed in the meantime to make it reset again. It was down to me changing the "status[2]" below to "status[0]", but I can't find in the help guide what that does. Can you help me with that, please? I thought [2] is two bars ago, but it obviously isn't
string[] status = GetAtmStrategyEntryOrderStatus(shortOrderId);
if (status.GetLength(0) > 0)
{
// If the order state is terminal, reset the order id value.
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
shortOrderId = string.Empty;
}
Leave a comment:
-
Hello itrader46, thanks for your reply.
The Print statements need to be placed deliberately to focus on a specific part of your script. They will be called whenever the logic processes them. If you would like to limit how often you see the prints, you can use logic to control when they are called or remove the prints all together. It is often useful to add prints specifically for a section you are working on so your output is only relevant to the issue you are looking into. I'm unable to debug individual code, but I think focusing on one issue and addressing it would be the best way forward. I wanted to attach this "ATMStrategyMonitor" script that identifies and reports data on an ATM strategy using OnOrderUpdate, it could prove useful.Attached Files
Leave a comment:
-
Also, the strategies don't reset, so after a short and a long order, there is no other order in any direction
Leave a comment:
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rhyminkevin, Today, 04:58 PM
|
4 responses
52 views
0 likes
|
Last Post
by dp8282
Today, 06:13 PM
|
||
Started by iceman2018, Today, 05:07 PM
|
0 responses
5 views
0 likes
|
Last Post
by iceman2018
Today, 05:07 PM
|
||
Started by lightsun47, Today, 03:51 PM
|
0 responses
7 views
0 likes
|
Last Post
by lightsun47
Today, 03:51 PM
|
||
Started by 00nevest, Today, 02:27 PM
|
1 response
14 views
0 likes
|
Last Post
by 00nevest
Today, 03:48 PM
|
||
Started by futtrader, 04-21-2024, 01:50 AM
|
4 responses
50 views
0 likes
|
Last Post
by futtrader
Today, 03:01 PM
|
Leave a comment: