Using range 1 instead of tick 1 is much more efficient and will still manage the trade every 1 tick of price movement. Helpful for trailing stops or etc.
my idea is :
to cancel a limitorder if i get no fill and the price is running away.
i have a strategy that is working OK.
now i add
Add(PeriodType.Range, 1) In the Initialize section -- a basic thing.
now i found out that i have to use if (BarsInProgress == 0)
at the biginning to keep my strategy in the basic timeframe for checking the entryconditions.
Once my limit-order is in the market, i want to use the second timeframe (1 Range) to manage the order-canceling if needed.
i tried different ways - also with if (BarsInProgress == 1) or Highs[1] [0] to have a switch to the 1 Range timeframe --- with no sucsess.
samething i am doing wrong.
any tips / ideas to that ?
if
(
create==1 // means Limit-Order is in the market
&&
valueClose +5 <= Highs[1] [0]
// ( valueClose +5 = the last Barclose+5 ticks of the main timeframe )
//( Highs[1] [0] should represent the High of the 1-Range-timeframe)
If you use any BarsSinceEntry() or BarsSinceExit() anywhere in your script at all, you must rewrite them to make them MTF compatible. Change to BarsSinceEntry(0, "long", 0) to indicate barsarray 0, signal name "long", last entry.
If you aren't using that and still having trouble... Highs[1][0] would represent barsarray 1 bar 0 (last bar). You are right.
Also on your order submission, you can submit it to a smaller time frame:
EnterLong(1, 3, "long");
This will submit to bars array 1, order quantity 3, for long. Submitting to smaller time frame is useful for limit order because ninja will cancel the limit order at the end of the bar if not filled so keep in mind this and size of time frame.
As for cancelling an order manually, sorry I can not help. I do not use limit orders because of all the extra bugs in ninja to deal with them in backtesting.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
Also remember your other indicator based signals to need changing such as
double ma = EMA(BarsArray[1], 21)[0];
You can do the if (BarsInProgress == 1) method as well, but remember that if you check a dataseries value for a BarsArray other than current it will be zero/null. For instance if you .Set a dataseries in array 1 and check it in array 0, sometimes it will be zero/null.
I prefer to set the dataseries in all time frames and call it using the BarsArray[x] method so the dataseries is never 0/null.
so I am pointing all of this out because I do not know if your script in general is not MTF compatbile until you make all these changes or if everything is fine except you cant cancel the order.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
Max, in case you haven't already solved this, here's something simple to try to do a sanity check. I plan to do some testing with this period type soon as well, so good luck.
thank you,
i just tried it again on market replay to make shure my logic is right -
>> the ATM - order-cancelation works OK with a call from the main timeframe
It does not work with my trys from the second timeframe ...... there is a conflict somewhere i have to find.
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks: 16 given,
10
received
Hi Max,
Any chance you could post the code of the section you have that cancels the order? I have a good ATM strat but the cancel component is not working.
When I take out CurrentBar > barNumberOfOrder + 1 && I can get the orders to cancel(straight away but good for testing).
I have set TraceOrders = true; and from the output window can't see any errors. Even with print statements it looks good, the AtmCancelEntryOrder is called but doesn't actually cancel with CurrentBar > barNumberOfOrder + 1 . However, I can get it to cancel if I just call the cancel if any order is pending/working or accepted.
The NT site doesn't have any actual samples of working strats with AtmStrategyCancelEntryOrder(orderId); on it, just the command variable page.
Did you ever get it to work? If you have some working sample code you could post would really appreciate it!
Thanks for sharing the portion of your code. It appears mrticks and I are going through a similar learning experience.
A couple quick questions:
How are your Buy and Sell variables initially set? true or false? I'm assuming false with other conditions of your code creating the true condition.
When the condition sets Buy or Sell to true, do you also restate the other one to false (keeping them paired up throughout your code)?
Is this strat COBC = false;? I'm assuming false.
I've started my code off the SampleAtmStrategy which is a long only sample. How often would you use variables that are specifically long or short to keep them separated? I've tried orderIdL and orderIdS and atmStrategyIdL and atmStrategyIdS. Those seem to allow for going long AND short at the same time which could solve a bracketing type scenario but can create a mess also. Or if you have barNumber assignments do you use entryBarL = CurrentBar or just entryBar = CurrentBar?
Buy and Sell variables are initially set to false. Only Buy or Sell can be true at one time. If you look at the code carefully, there are instances where the variables are set back to false. ie if there there is an atmcancelorder or if the trade has just finished( filled )
No im running this as COBC = true. The point of running 1 tick timeframe is to pretty much run as COBC = false. However if you have an indicator that requires COBC = false and another to true, then it gets complicated. Is that what you are doing?
Yeah im assuming that error msg is because of that. Its hard to tell without seeing the code.
PM me if you need something more.
James
The following user says Thank You to jthom for this post:
Buy and Sell variables are initially set to false. Only Buy or Sell can be true at one time. If you look at the code carefully, there are instances where the variables are set back to false. ie if there there is an atmcancelorder or if the trade has just finished( filled )
No im running this as COBC = true. The point of running 1 tick timeframe is to pretty much run as COBC = false. However if you have an indicator that requires COBC = false and another to true, then it gets complicated. Is that what you are doing?
Yeah im assuming that error msg is because of that. Its hard to tell without seeing the code.
PM me if you need something more.
James
Thanks James,
Two questions - when I'm calling the indicators, can they be COBC = false or do you comment out that line in the indicator. (see post #3 from the NT support thread that mentions that) I have set this strategy to COBC true and would like up-to-the-tick info from the indicator.
Gavin, orderlimitprice is just a variable for the Close[0]
Just remember if you are referencing the 500 tick range in the BarsinProgress == 1(1 tick) its Closes[0][0]
The following user says Thank You to jthom for this post:
Zella,
I prefer running strategies on COBC = true. Just add a smaller timeframe and run the indicator on that. ie a 1 min chart with a 5 min. You cannot have an indicator on COBC = false and a strategy with the indicator set to COBC = true. It will calculate as it set to true
The following user says Thank You to jthom for this post:
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks: 16 given,
10
received
jthom
Gavin, orderlimitprice is just a variable for the Close[0]
Just remember if you are referencing the 500 tick range in the BarsinProgress == 1(1 tick) its Closes[0][0]
James - I couldn't get your code to work so I kept at my own and came up with something that kind of works. The strat will close orders once the current price dips x ticks below the high of the last bar. This is for a strat with a long ATM created.
I just have to figure out how to express "close pending orders if n bars have passed with no fill" and it's there. I have posted on the NT forums asking for pointers in the right direction also so if they come up with something I'll post it here also. It's on the same thread you posted in about canceling orders after n ticks +/- movement.
Here is the full status section code,
// 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
// Print some information about the strategy to the output window Print("126 At the end of TFL3BR"); 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)); Print("The current ATM Strategy Realized PnL is: " + GetAtmStrategyRealizedProfitLoss(atmStrategyId)); } }
Just by looking at your code there, it seems fine. Does it work properly? You will also need to put a buy cancel order in it. Ie Close [0] + 5 * TickSize < High[1]
Does it run on COBC = false? Because if it doesnt you will need to use a smaller timeframe for the cancel option which is 1 tick.
Looks good.
Also if you want to talk about it, I have a voice ventrillo server. You can download that for free. PM me for details.
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks: 16 given,
10
received
Hey James - I think it works OK. I need to test it on a sim feed today though. Haven't tried it with bar close set to false. As I'm running tick charts I haven't tried anything with COBC = false.
So if it doesn't run on COBC = false do you reckon I should test with a 1 tick chart?
I may take you up on that offer to talk about it. You seem to know your stuff!! Will PM you about it.