NexusFi: Find Your Edge


Home Menu

 





Multi-Timeframe in a strategy


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one mrticks with 8 posts (1 thanks)
    2. looks_two jthom with 7 posts (7 thanks)
    3. looks_3 max-td with 7 posts (0 thanks)
    4. looks_4 caprica with 5 posts (0 thanks)
    1. trending_up 16,407 views
    2. thumb_up 8 thanks given
    3. group 3 followers
    1. forum 30 posts
    2. attach_file 0 attachments




 
Search this Thread

Multi-Timeframe in a strategy

  #21 (permalink)
 jthom 
Sydney / Australia
 
Experience: Intermediate
Platform: NT
Broker: AMP
Trading: Oil
Posts: 118 since Jun 2009
Thanks Given: 128
Thanks Received: 105


zeller4 View Post
jthom,

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.

When I see error messages in the log (ie "GetAtmStrategyMarketPosition() method error: Missing atmStrategyId parameter"), is that because I have a situation where there's no "check" such as
if (atmStrategyId.Length > 0)?

Thanks,
Kirk

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

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Futures True Range Report
The Elite Circle
Exit Strategy
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #22 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10


jthom View Post
Ok you would add the strategy to a 500 tick chart.
Then add a 1 tick chart by:
Add( PeriodType.Tick, 1);

Add a Buy and Sell variable when you would set to false. Set Buy or Sell to true once entry conditions are met.
Then add this:


 
Code
                            
if (BarsInProgress == && 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
    
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")
      
orderId string.Empty;
      
Buy false;
      
Sell false;
      
    
    
    if (
Buy == true && status[2] == "Working" && Close[0] == orderLimitPrice TickSize)
     {
        
AtmStrategyCancelEntryOrder(orderId);
     } 
    if (
Sell == true && status[2] == "Working" && Close[0] == orderLimitPrice TickSize)
     {
        
AtmStrategyCancelEntryOrder(orderId);
     } 
    }
    } 
// If the strategy has terminated reset the strategy id
    
else if (atmStrategyId.Length && GetAtmStrategyMarketPosition(atmStrategyId) ==  Cbi.MarketPosition.Flat)
    
atmStrategyId string.Empty;
    
Buy false;
    
Sell false

Enjoy

James - Thank you so much for that code, appreciate you going to the trouble of putting that up.

I have just edited the strat with your code and it won't compile due to an error with the reference to orderLimitPrice from the line:

if (Buy == true && status[2] == "Working" && Close[0] == orderLimitPrice + 3 * TickSize)

The error I get is "The name 'orderLimitPrice' does not exist in the current context".

So I'm going to try and use a different trigger instead of orderLimitPrice. Will let you know how I get on.


Thanks,

Gavin.



Reply With Quote
  #23 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404



jthom View 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.

https://forum.ninjatrader.com/showthread.php?p=66428

What code do you use to ensure a fill (ie High[0] > limitPrice && Low[0] < limitPrice) ? Where should this be placed in the code in relation to the

 
Code

if (entryPriceL > 0) AtmStrategyCreate(Cbi.Action.Buy, OrderType.Limit, entryPriceL, 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
 
Or do I need to change the "0" to the limit price also?
Thanks,
Kirk

Reply With Quote
  #24 (permalink)
 jthom 
Sydney / Australia
 
Experience: Intermediate
Platform: NT
Broker: AMP
Trading: Oil
Posts: 118 since Jun 2009
Thanks Given: 128
Thanks Received: 105

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]

Reply With Quote
Thanked by:
  #25 (permalink)
 jthom 
Sydney / Australia
 
Experience: Intermediate
Platform: NT
Broker: AMP
Trading: Oil
Posts: 118 since Jun 2009
Thanks Given: 128
Thanks Received: 105

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

Reply With Quote
Thanked by:
  #26 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404

Thanks James,

Any thoughts for the "fill" question?
kz

Reply With Quote
  #27 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10


jthom View Post
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.

 
Code
                            
}
                
                if (
Close [0] - TickSize High[1] &&(status[2] == "Accepted" || status[2] == "Working" || status[2] == "Pending"))
                
                {
                Print(
"108 ATM cancel TFL3BR order");    
                
AtmStrategyCancelEntryOrder(orderId);
                } 
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,
 
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

                
if (status.GetLength(0) > 0)
                    
                
                if (
status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                
                {
                    Print(
"100 Reset the strategy id if filled/cancelled or rejected");    
                      
orderId string.Empty;
                                        
                }
                
                if (
Close [0] - TickSize High[1] &&(status[2] == "Accepted" || status[2] == "Working" || status[2] == "Pending"))
                
                {
                Print(
"108 ATM cancel TFL3BR order");    
                
AtmStrategyCancelEntryOrder(orderId);
                }
            } 
            
                        
            if (
atmStrategyId.Length && GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
                {
                Print(
"117   reset the strategy id");
                
atmStrategyId string.Empty;
                
orderId string.Empty;
                }


            if (
atmStrategyId.Length 0)
            {
                
                
// 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));
            }
        } 

Reply With Quote
  #28 (permalink)
 jthom 
Sydney / Australia
 
Experience: Intermediate
Platform: NT
Broker: AMP
Trading: Oil
Posts: 118 since Jun 2009
Thanks Given: 128
Thanks Received: 105

Gavin,

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.

Reply With Quote
  #29 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10

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.


Thanks,

Gavin.

Reply With Quote
  #30 (permalink)
 jthom 
Sydney / Australia
 
Experience: Intermediate
Platform: NT
Broker: AMP
Trading: Oil
Posts: 118 since Jun 2009
Thanks Given: 128
Thanks Received: 105


Well Im willing to help you get it running efficiently.
Ok well I have a Ventrilo Chat Server setup for you guys to chat in.

You will need a microphone.

You can download Ventrilo Client Free here:
Ventrilo - Download

The Server Ip is 180.92.192.226
Port is 4584

Or the easy way to connect is just to click this Link:
ventrilo://180.92.192.226:4584/servername=BigMikeTrading

The Channel you want to goto is BigMikeTrading.

The password for the channel is 'trading'

Look for Jimmy in there. Thats me. All are welcome to join
Its very easy to setup

Reply With Quote
Thanked by:




Last Updated on July 22, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts