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

  #11 (permalink)
 
jackyd's Avatar
 jackyd 
Calgary Canada
 
Experience: Intermediate
Platform: Ninja
Broker: IB/Kinetic
Trading: 6E, CL
Posts: 47 since Jun 2009
Thanks Given: 44
Thanks Received: 20

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.

 
Code
if (BarsInProgress == 0)
{
	if (Position.MarketPosition != MarketPosition.Flat)
	{
		Print(Time[0] + " Process Range Bar 0 - High: " + High[0] + ", Low: "  + Low[0] + ", Close: "  + Close[0]);
	}
}

if (BarsInProgress == 1)
{
	if (Position.MarketPosition != MarketPosition.Flat)
	{
		Print(Time[0] + " ======> Process Range Bar 1 - High: " + High[0] + ", Low: "  + Low[0] + ", Close: "  + Close[0]);
	}
}

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Futures True Range Report
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
My NT8 Volume Profile Split by Asian/Euro/Open
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
38 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #12 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927

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.

max-td
Started this thread Reply With Quote
  #13 (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



max-td View Post
well ... there is nothing special inside the strategy ---- just some simple conditions and a call for an Entry via ATM-creation :


if (blabla )


{
AtmStrategyCreate(Action.Buy, OrderType.Limit, valueClose - 1 , 0,
TimeInForce.Day, entryorderid, atmname,
atmorderid);
create = 1;
}

dont know could cause MTF- troubles here -- but never used MTF before i must say.

max-td, for the above to work do you need the following ints?

private string entryorderid = string.Empty;
private string atmorderid = string.Empty;

Reply With Quote
  #14 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927

hi mrtick,
yes thats right.

i have the following in my #region variables:

private string entryorderid = "";
private string atmorderid = "";
private string atmname = "";

to run this shown example.

max-td
Started this thread Reply With Quote
  #15 (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


max-td View Post
hi mrtick,
yes thats right.

i have the following in my #region variables:

private string entryorderid = "";
private string atmorderid = "";
private string atmname = "";

to run this shown example.


Thanks for the reply. Have a good weekend!

Reply With Quote
Thanked by:
  #16 (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


max-td View Post
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.

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.

 
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(
                        CurrentBar > barNumberOfOrder + 1 &&
                        (status[1] == "Accepted" || status[1] == "Working" || status[1] == "Pending"))
                    AtmStrategyCancelEntryOrder(orderId);
                    Print("TFL3BRATM Cancelled Order");
                    atmStrategyId = string.Empty;
                    orderId = string.Empty;
                                        
                }
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,

Gavin.

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

Gavin,
What time frame are you running the chart in and what market is it for? Futures?
I can post some code once I know that.

James

Reply With Quote
  #18 (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

Hi James - I use tick charts. Have been testing it on the mini Russel 500 tick chart. That would be great if you could post that!

Thanks,

Gavin.

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

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

Reply With Quote
Thanked by:
  #20 (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,

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?


Thanks,
Kirk

Reply With Quote




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