NexusFi: Find Your Edge


Home Menu

 





Custom Time Event for a ATM


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one jthom with 2 posts (0 thanks)
    2. looks_two Big Mike with 1 posts (4 thanks)
    3. looks_3 MXASJ with 1 posts (2 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 3,780 views
    2. thumb_up 6 thanks given
    3. group 1 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Custom Time Event for a ATM

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

Im looking for the correct method to initiate a custom timer event as soon as a
AtmStrategyCreate order is initiated. If the order is not filled say within 30 secs, a AtmStrategyCancelEntryOrder cancels the current order.
Also CalculateOnBarClose = true;
 
Code
                            
#region Variables
private string atmStrategyId string.Empty;
private 
string orderId string.Empty;
private 
System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
 
protected 
overridevoid Initialize()
{
CalculateOnBarClose true;
}

///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protected overridevoid OnBarUpdate()
{
if (
Historical)
return;

myTimer.Interval 1000;
myTimer.Start();

if(
orderId.Length == 
&& atmStrategyId.Length == && BLAH BLAH)
{
atmStrategyId GetAtmStrategyUniqueId();
orderId GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.Action.BuyOrderType.LimitClose[0] -TickSize0TimeInForce.DayorderId"BLAH"atmStrategyId);
myTimer.ToString();

}

else if (
myTimer.ToString 30000)

{
AtmStrategyCancelEntryOrder(orderId);



Any ideas in the right direction would be greatly appreciated.

Thanks

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
MC PL editor upgrade
MultiCharts
Better Renko Gaps
The Elite Circle
Quant vue
Trading Reviews and Vendors
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
What is Markets Chat (markets.chat) real-time trading ro …
77 thanks
Spoo-nalysis ES e-mini futures S&P 500
55 thanks
Just another trading journal: PA, Wyckoff & Trends
37 thanks
Bigger Wins or Fewer Losses?
24 thanks
The Program
17 thanks
  #3 (permalink)
 
aslan's Avatar
 aslan 
Madison, WI
 
Experience: Advanced
Platform: ALT
Trading: ES
Posts: 625 since Jan 2010
Thanks Given: 356
Thanks Received: 1,127


If you search the Ninja forums for "timer" you will find several examples. It should be the same for NT 6.5/7.

The basics are to use a timer event callback routine, start the timer when you initiate an order, check the order status when the timer routine is called, turn the timer off when the order fills. You will need to deal with timing windows though, as a timer could go off while you are processing an order, so you could get a timer event even though you thought you turned it off already. Also consider the case of initiating a timer when it is already running (if you had long timers).

Reply With Quote
  #4 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,461 since Jun 2009
Thanks Given: 33,235
Thanks Received: 101,657

Something like this:

 
Code
                            
#init
private System.Windows.Forms.Timer myTimerClock             = new System.Windows.Forms.Timer();
private 
bool init false;
        
// ---

private void OnTimerTick(object senderEventArgs e)
{
            
TriggerCustomEvent(UpdateTimemyTimerClock.Interval);
}

private 
void DoTime(Object myObjectEventArgs myEventArgs)
{
            
TriggerCustomEvent(UpdateTimemyTimerClock.Interval);
}

private 
void UpdateTime(object state)
{
// your timer related stuff here
}

#onbarupdate
protected override void OnBarUpdate()
{

if (!
init && !Historical)
{
myTimerClock.Tick += new EventHandler(DoTime);
                
myTimerClock.Interval 1000;
                
myTimerClock.Start();
                
                
init    true;
}

}

public 
override void Dispose()
{
            
// timer dispose
            
myTimerClock.Dispose();

Rest of your ATM-specific stuff is up to you.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #5 (permalink)
 jthom 
Sydney / Australia
 
Experience: Intermediate
Platform: NT
Broker: AMP
Trading: Oil
Posts: 118 since Jun 2009
Thanks Given: 128
Thanks Received: 105

Cheers Mike. That helped out. Many thanks

Started this thread Reply With Quote
  #6 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

If you are on NT7 you will need a barsIndex overload in TriggerCustomEvent. This appears to be different than 6.5 where barsIndex was optional:

 
Code
                            
private void OnTimerTick(object senderEventArgs e)
{
TriggerCustomEvent(UpdateTime0myTimer.Interval);

Note the Zero between UpdateTime and myTimer.Interval

Reply With Quote
Thanked by:




Last Updated on May 18, 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