NexusFi: Find Your Edge


Home Menu

 





TriggerCustomEvent in another running object


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one vantojo with 2 posts (0 thanks)
    2. looks_two monpere with 1 posts (6 thanks)
    3. looks_3 Adfra with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 2,730 views
    2. thumb_up 6 thanks given
    3. group 5 followers
    1. forum 5 posts
    2. attach_file 1 attachments




 
Search this Thread

TriggerCustomEvent in another running object

  #1 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

This is outside the range of Ninja Support, but perhaps someone here knows and will post....


TriggerCustomEvent(CustomEvent customEvent, int barsIndex, object state)

Is normally used to trigger a user defined method (custom event) inside the same Strategy or Indicator.

However would it be possible for an Indicator running on a Chart to trigger a custom event in a strategy running in Strategy Analyzer?

(I used to code object oriented client server applications, and this was a standard way of executing code in another object., so there must be something in C# that would allow this?)

Thank you

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
45 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #3 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,395



vantojo View Post
This is outside the range of Ninja Support, but perhaps someone here knows and will post....


TriggerCustomEvent(CustomEvent customEvent, int barsIndex, object state)

Is normally used to trigger a user defined method (custom event) inside the same Strategy or Indicator.

However would it be possible for an Indicator running on a Chart to trigger a custom event in a strategy running in Strategy Analyzer?

(I used to code object oriented client server applications, and this was a standard way of executing code in another object., so there must be something in C# that would allow this?)

Thank you

Hi @vantojo,

I have looked for a simple way to do this in the past and thought more about what I was trying to do. I was thinking the Strategy is the controller not the indicator. So I poll or call public functions back to the Indicators to accomplish actions such as that which avoids the "child" driving the parent if you will seemed to make things more complex for me, but I think a new set of standard functions.

If you really wanted to do this, you could use public functions in the Indicator to pass values need for the Callback functions. You can see more about that structure from @anachronist here:

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

Hi NJAMC,

Thank you...lots to study, it looks like. Will dig into LOM examples it this week.

From a conceptual level:

In my mind I don't see the need to have a parent-child tightly coupled relationship between the Signal Generator and the Trade Manager.

In a way the Signal Generator should be driving the Trade Manager. The Trade Manager should be in a sleep state until it has something to do...that is, a signal wakes it up or it has an active trade to manage.

Otherwise it is wasting CPU cycles doing nothing.

In the case where the Trade Manager is submitting an ATM it has only to submit an order, and perhaps cancel an unfilled order (if a new signal comes in). The ATM would be doing the actual trade management, leaving the Trade Manager to do nothing.

This is not the way Ninja works, of course.

Just some thoughts.

Started this thread Reply With Quote
  #5 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371


vantojo View Post
Hi NJAMC,

Thank you...lots to study, it looks like. Will dig into LOM examples it this week.

From a conceptual level:

In my mind I don't see the need to have a parent-child tightly coupled relationship between the Signal Generator and the Trade Manager.

In a way the Signal Generator should be driving the Trade Manager. The Trade Manager should be in a sleep state until it has something to do...that is, a signal wakes it up or it has an active trade to manage.

Otherwise it is wasting CPU cycles doing nothing.

In the case where the Trade Manager is submitting an ATM it has only to submit an order, and perhaps cancel an unfilled order (if a new signal comes in). The ATM would be doing the actual trade management, leaving the Trade Manager to do nothing.

This is not the way Ninja works, of course.

Just some thoughts.

This is the way I trade exclusively for the past 4 years. All the buttons on the chart are from an indicator. Every button I click sends a text command to the strategy, and the strategy performs that command. Fore example, Pressing the 'Next Bar' button on the chart sends the following command to the strategy '<ATMmgrCmd> CL 09-12, BuyNextBar 1 @ 93.57 +12-93.51~0=9 @6:-3 @12:+6 NoFillCancel_2</ATMmgr>'. This means, put a buy stoplimit for 1 contract at the next bar open (93.57) and manage in the following way stop at 93.51 target +12 ticks At 6 ticks in profit move stop to -3 ticks (@6:-3), at 9 ticks profit move stop to break even (=9) at 12 ticks profit move stop to +6 ticks (@12:+6), if order is not filled after 2 bars cancel the stoplimit entry order (NoFillCancel_2), etc. I can add unlimited number of ATM style trade management just by adding a series of '@x:x' clauses to the command, or changing an open trade management the same way, etc. The communication just using a global style string variable that both the indicator and the strategy can poll and read.

In your Strategy put this code:

public class TradeManagerGlobal {
public static string command = "";
}
...
if ( TradeManagerGlobal.command.Contains("BuyLimit")) ) {
... Parse the string
... Execute commands
TradeManagerGlobal.command=""; // Clear the command, or send back results
}

In your Strategy put this code:

public class TradeManagerGlobal {
public static string command = "";
}
...
if ( TradeManagerGlobal.command.Contains("BuyLimit")) ) {
... Parse the string
... Execute commands
TradeManagerGlobal.command=""; // Clear the command, or send back results
}

In your Indicator put this code:

TradeManagerGlobal.command = "BuyLimit CL 09-12 @ 92.40 Stop=-10 Target=+20 BE=+10.... etc., etc ";

I also add a 1 second wake up timer to my strategy to insure that the strategy execute any command within 1 second of a button press on the chart.

And of course the strategy can communicate any results back to the strategy using the same TradeManagerGlobal.command string, or different similarly defined string variable. Anything can communicate with that strategy, even a chart for a different instrument, if desired.

Attached Thumbnails
Click image for larger version

Name:	cl.jpg
Views:	273
Size:	85.7 KB
ID:	84805  
Reply With Quote
  #6 (permalink)
 Adfra 
Melbourne
 
Experience: Intermediate
Platform: NinjaTrader
Broker: MB Trading, Kinetick
Trading: Forex, AUD/USD
Posts: 19 since Aug 2011
Thanks Given: 11
Thanks Received: 9

Hi Monpere,

Thanks so much for sharing your approach on this.
It works well.


monpere View Post
I also add a 1 second wake up timer to my strategy to insure that the strategy execute any command within 1 second of a button press on the chart.

It would be great if you could provide some more detail on that 1 sec. wake up timer. I don't even know where to start on that one. If you could share the code that would be awesome!

Cheers
Frank

Reply With Quote




Last Updated on November 7, 2013


© 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