NexusFi: Find Your Edge


Home Menu

 





ChartTrader: Programmatically changing selected Account


Discussion in NinjaTrader

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




 
Search this Thread

ChartTrader: Programmatically changing selected Account

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

One of you more advanced guys might know how to do this...??

I'm making a global button on ChartTrader that will reset all my charts from Live back to SIM...so before I walk away from the charts, everything is on SIM when I get back.

Almost there, but when I use code to change the selected account from Live to SIM, the selected Account is changed on ChartTrader, but the mother code (Ninja) does not see it.... for example, when Ninja does not change the ChartTrader background to dark gray and it will still submit trades to the Live account even though the code changed the selected Account to Sim101.

Probably just a matter of triggering the right event, but actually I'm not sure how to get there....

Here is the code:

System.Windows.Forms.ComboBox CBAccount = null;

CBAccount = ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["cboAccount"] as System.Windows.Forms.ComboBox;

CBAccount.SelectedIndex = 1; // live account is 0, Sim101 is 1

// CBAccount.SelectedIndex = CBAccount.Items.IndexOf("Sim101"); // this does not work, it returns -1

Started this thread Reply With Quote

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
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
NexusFi Journal Challenge - April 2024
Feedback and Announcements
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #3 (permalink)
 steve2222 
Auckland, New Zealand
 
Experience: Beginner
Platform: Sierra Chart
Broker: AMP/CQG
Trading: Whatever moves in my timezone
Posts: 1,896 since Sep 2009
Thanks Given: 3,379
Thanks Received: 1,540


Have a look at the code in @vvhg indi in this thread:



This indi allows you to select to change the account and it changes it in Chart Trader and elsewhere at the sametime.

I actually use this indi for the purpose you describe - to move seemlessly from Live to SIM.

Reply With Quote
Thanked by:
  #4 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

What a tremendous resource we have here at futures.io (formerly BMT)!

Will dig into the code as you suggested. I'm not a native C# guy...but can do quite a bit with examples from others.

Started this thread Reply With Quote
  #5 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

OK, taken from the indicator you mentioned, the code that will do this is:

using System.Runtime.InteropServices;

------------------------------------------------------------------------------------------------------------

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);

--------------------------------------------------------------------------------------------------------------

CBAccount = ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["cboAccount"] as System.Windows.Forms.ComboBox;

// to select the prior account in the list
SendMessage(CBAccount.Handle, 0x0100, (IntPtr)0x26, (IntPtr)0X1500001); //uparrow keydown

// to select the next account in the list
SendMessage(CBAccount.Handle, 0x0100, (IntPtr)0X28, (IntPtr)0X1500001); //downarrow keydown

--------------------------------------------------------------------------------------------------------------

works OK for me because I only have SIM and my production account in the ChartTrader account list when Live...if there are more than two accounts it would create need for more code

------------------------------------------------------------------------------------------------------------------------

THANK YOU vvhg and steve2222 !!

Started this thread Reply With Quote
  #6 (permalink)
Anastasia
Russia
 
Posts: 2 since Nov 2013
Thanks Given: 0
Thanks Received: 0


vantojo View Post

Here is the code:

System.Windows.Forms.ComboBox CBAccount = null;

CBAccount = ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["cboAccount"] as System.Windows.Forms.ComboBox;

CBAccount.SelectedIndex = 1; // live account is 0, Sim101 is 1

// CBAccount.SelectedIndex = CBAccount.Items.IndexOf("Sim101"); // this does not work, it returns -1

private Account selectedacct;
private ComboBox ctrdrAcct;

ctrdrAcct = (ComboBox)ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["cboAccount"];
selectedacct = (Account) ctrdrAcct.SelectedItem; // this you Account

Reply With Quote




Last Updated on February 6, 2017


© 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