• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 7:20pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 7:20pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Printable Version

Similar Threads

Open: Button, Close: MA Cross 14 replies

Need an on-chart button to close position w/o confirmation 9 replies

Space to the right (Mt4) more than chart shift button 1 reply

Help - how to modify an EA to leave existing trades open 2 replies

Confessions of a compulsive close-button clicker 10 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe

Open Existing chart from a button

  • Post #1
  • Quote
  • First Post: Feb 13, 2020 1:13pm Feb 13, 2020 1:13pm
  •  Spikehunter
  • Joined Mar 2006 | Status: Member | 651 Posts
Hi,
I have searched high and low looking for a method to open an existing chart from a button. Scenario is that I have a master screen with all my pairs indicated and any possible and actual trades highlighted. I want to be able to create buttons with the pair name that when pushed it goes straight to that existing chart. This would save me scrolling through the list at the foot of the screen. I don't want a new chart as the existing chart is already running with an EA attached. I cant find anything except one item which I cant get to work. I have thought about running all the pairs of one EA and then opening a new chart and attaching a template but that would mean a rewrite of my EA.
Please any ideas.
  • Post #2
  • Quote
  • Feb 13, 2020 5:05pm Feb 13, 2020 5:05pm
  •  Erebus
  • Joined Jul 2011 | Status: Member | 5,607 Posts | Online Now
So, it's not as per the title, open a chart, only go to that chart?

How many charts are we talking about, 10, 20, 30?

If you Arrange the charts, expand the 1st chart, then you can use Ctrl + Tab to progress from chart to chart fairly quickly.

The two most powerful warriors are patience and time. Leo Tolstoy
  • Post #3
  • Quote
  • Feb 13, 2020 5:35pm Feb 13, 2020 5:35pm
  •  Jagg
  • Joined Oct 2006 | Status: Member | 439 Posts
Quoting Erebus
Disliked
So, it's not as per the title, open a chart, only go to that chart? How many charts are we talking about, 10, 20, 30? If you Arrange the charts, expand the 1st chart, then you can use Ctrl + Tab to progress from chart to chart fairly quickly.
Ignored
You meant CTRL+F6
  • Post #4
  • Quote
  • Feb 13, 2020 5:47pm Feb 13, 2020 5:47pm
  •  Jagg
  • Joined Oct 2006 | Status: Member | 439 Posts
Quoting Spikehunter
Disliked
Hi, I have searched high and low looking for a method to open an existing chart from a button. Scenario is that I have a master screen with all my pairs indicated and any possible and actual trades highlighted. I want to be able to create buttons with the pair name that when pushed it goes straight to that existing chart.
Ignored
create that pair name button objects and when clicked you search in all open charts for this symbol and bring it to top, isn't a chart open with that symbol you open a new one and apply your template on it.

Something like...
Inserted Code
void OpenChart(int ind) {
   long nextchart = ChartFirst();
      do {
         string sym = ChartSymbol(nextchart);
         if (StringFind(sym,TradePairs[ind]) >= 0) {
               ChartSetInteger(nextchart,CHART_BRING_TO_TOP,true);
               //ChartSetSymbolPeriod(nextchart,TradePairs[ind],TradePairs_TradingTimeFrame[ind]);
               //ChartApplyTemplate(nextchart,usertemplate);
               return;
            }
      } while ((nextchart = ChartNext(nextchart)) != -1);
      long newchartid = ChartOpen(TradePairs[ind],TradePairs_TradingTimeFrame[ind]);
      ChartApplyTemplate(newchartid,usertemplate);
}
  • Post #5
  • Quote
  • Feb 13, 2020 5:54pm Feb 13, 2020 5:54pm
  •  Erebus
  • Joined Jul 2011 | Status: Member | 5,607 Posts | Online Now
Quoting Jagg
Disliked
{quote} You meant CTRL+F6
Ignored
Please try Ctrl + Tab

What happens?

The two most powerful warriors are patience and time. Leo Tolstoy
  • Post #6
  • Quote
  • Feb 13, 2020 5:59pm Feb 13, 2020 5:59pm
  •  Jagg
  • Joined Oct 2006 | Status: Member | 439 Posts
Quoting Erebus
Disliked
{quote} Please try Ctrl + Tab What happens?
Ignored
Sorry - you're right... CTRL+Tab do the same as CTRL+F6 (tab is possible easier for the fingers to catch than F6 )
1
  • Post #7
  • Quote
  • Feb 13, 2020 6:03pm Feb 13, 2020 6:03pm
  •  Spikehunter
  • Joined Mar 2006 | Status: Member | 651 Posts
Thank you for your replies. Ctrl Tab etc is too long winded as it scrolls through each chart, I want to go straight to it from a button. The code looks promising so I will try that. Not sure how to show a screen shot, I'll try tomorrow..
  • Post #8
  • Quote
  • Feb 13, 2020 6:06pm Feb 13, 2020 6:06pm
  •  Erebus
  • Joined Jul 2011 | Status: Member | 5,607 Posts | Online Now
Quoting Spikehunter
Disliked
Thank you for your replies. Ctrl Tab etc is to long winded as it scrolls through each chart, I want to go straight to it from a button. The code looks promising so I will try that. Not sure how to show a screen shot.
Ignored
Must be some real fancy trading you are doing if that's too long winded

Good luck with your 1st world problem

The two most powerful warriors are patience and time. Leo Tolstoy
  • Post #9
  • Quote
  • Feb 14, 2020 6:27am Feb 14, 2020 6:27am
  •  Spikehunter
  • Joined Mar 2006 | Status: Member | 651 Posts
Quoting Erebus
Disliked
So, it's not as per the title, open a chart, only go to that chart? How many charts are we talking about, 10, 20, 30? If you Arrange the charts, expand the 1st chart, then you can use Ctrl + Tab to progress from chart to chart fairly quickly.
Ignored
Yes you are right. Let me rephrase. Give focus to an existing chart when a button is pressed. I have 26 charts open running an EA. Some may be viable trades so I have a control panel with all the pair names and indication if they are worth looking at. Just want to convert the names to buttons to go directly to that chart.
Thanks
  • Post #10
  • Quote
  • Feb 14, 2020 12:47pm Feb 14, 2020 12:47pm
  •  Spikehunter
  • Joined Mar 2006 | Status: Member | 651 Posts
Quoting Jagg
Disliked
{quote} create that pair name button objects and when clicked you search in all open charts for this symbol and bring it to top, isn't a chart open with that symbol you open a new one and apply your template on it. Something like... void OpenChart(int ind) { long nextchart = ChartFirst(); do { string sym = ChartSymbol(nextchart); if (StringFind(sym,TradePairs[ind]) >= 0) { ChartSetInteger(nextchart,CHART_BRING_TO_TOP,true); //ChartSetSymbolPeriod(nextchart,TradePairs[ind],TradePairs_TradingTimeFrame[ind]); //ChartApplyTemplate(nextchart,usertemplate);...
Ignored
Hi
Thank you for the code. This looks like it is opening a new chart from scratch. I already have the chart open together with 25 others all running the same EA. I need the EA to be running consistently to give the signals. This is a nice to have but looks from searching google and the forums that it may not be possible. I may re-architect the EA to run all pairs from one screen and use something like this just to check. Just seems like a lot of work for a nice to have.

Ctrl F6 just scrolls through.
  • Post #11
  • Quote
  • Feb 14, 2020 2:24pm Feb 14, 2020 2:24pm
  •  Spikehunter
  • Joined Mar 2006 | Status: Member | 651 Posts
Hi,
Just wanted to post a work in progress, some bits aren't correct but don't affect the working principle. This will change the screen to the pair as defined, next step is to parameterise it so the button provides the pair name. I have that bit already done just not linked. Thanks for your posts. I will post final version as someone else may need the help.
Regards
Steve

#import "user32.dll"
#define WM_MDIACTIVATE 0x222
#define WM_MDIMAXIMIZE 0x0225
#define WM_COMMAND 0x111
#define MT4_WMCMD_PERIOD_D1 33134
#define MT4_WMCMD_PERIOD_H1 33135
#define MT4_WMCMD_PERIOD_H4 33136
#define MT4_WMCMD_PERIOD_M1 33137
#define MT4_WMCMD_PERIOD_M5 33138
#define MT4_WMCMD_PERIOD_M15 33139
#define MT4_WMCMD_PERIOD_M30 33140
#define MT4_WMCMD_PERIOD_W1 33141

int GetParent(int hWnd);
int SendMessageA(int hWnd, int Msg, int wParam, int lParam);
int GetAncestor (int hwnd, int gaFlags);
#import


int ChangePair_Window()
{
int win_handle=WindowHandle("GBPUSD",PERIOD_D1);
// if(win_handle!=0) { Alert("Window with GBPUSD,H1 detected. ",win_handle);}

int p = GetParent(win_handle);
SendMessageA(GetParent(p), WM_MDIMAXIMIZE, p, 0);
SendMessageA(GetAncestor(win_handle,3), WM_COMMAND, MT4_WMCMD_PERIOD_D1,"GBPUSD");
return(0);
}
  • Post #12
  • Quote
  • Feb 14, 2020 4:29pm Feb 14, 2020 4:29pm
  •  Jagg
  • Joined Oct 2006 | Status: Member | 439 Posts
Quoting Spikehunter
Disliked
{quote} Hi Thank you for the code. This looks like it is opening a new chart from scratch. I already have the chart open together with 25 others all running the same EA. I need the EA to be running consistently to give the signals. This is a nice to have but looks from searching google and the forums that it may not be possible. I may re-architect the EA to run all pairs from one screen and use something like this just to check. Just seems like a lot of work for a nice to have. Ctrl F6 just scrolls through.
Ignored
My posted work - I've tested it here....

Important:
- on your chart where you have your "control panel / buttons for every symbol" in you have to use a symbol name where you do NOT use in all your 25 other charts (where your trading EAs are in)
- the 25 other charts should be 25 different symbols (so no symbol should be opened two times or more...)
- if this is the case a click on a button on your control panel/chart brings your open trading chart of that symbol to front
This works and don't use system dll calls

But you posted another mehtod which uses dll calls - your choice. But afaik using SendMessageA is deprecated - it should be SendMessageW.
  • Post #13
  • Quote
  • Feb 15, 2020 5:16am Feb 15, 2020 5:16am
  •  Spikehunter
  • Joined Mar 2006 | Status: Member | 651 Posts
Quoting Jagg
Disliked
{quote} My posted work - I've tested it here.... Important: - on your chart where you have your "control panel / buttons for every symbol" in you have to use a symbol name where you do NOT use in all your 25 other charts (where your trading EAs are in) - the 25 other charts should be 25 different symbols (so no symbol should be opened two times or more...) - if this is the case a click on a button on your control panel/chart brings your open trading chart of that symbol to front This works and don't use system dll calls But you posted another mehtod...
Ignored
Hi Jagg
Thanks for the post. I am a bit out of my comfort zone with this one. Although I have programmed Mt4 a lot I have never gone quite this deep.
I was a mainframe systems programmer in the 70's.
I hope I didn't suggest that your code didn't work just that it appeared to open new charts from scratch.
I will definitely try it over the weekend and see how it works. I will also look at the difference in the send message as I don't understand the difference.
My version works but as you suggest there may be a better way.
Thanks again
Steve
1
  • Post #14
  • Quote
  • Last Post: Feb 16, 2020 11:35am Feb 16, 2020 11:35am
  •  Spikehunter
  • Joined Mar 2006 | Status: Member | 651 Posts
Thanks to everyone. I now have a working solution. I see that it can be achieved in a number of ways but this works so I am happy with that. Must make some actual money trading.

This is the solution I have used and its part of a bigger EA that does the entries and exits as well.
//#####################################################################################################
int Create_MyButton(int CM_cnt, int CM_x, int CM_y)
{
long chart_ID=0; // chart's ID
// ENUM_BASE_CORNER corner=CORNER_RIGHT_LOWER; // chart corner for anchoring
//--- reset the error value
// ResetLastError();
//--- create the button
string name;
if(CM_cnt==1) {name="AUDCAD";}
if(CM_cnt==2) {name="AUDCHF";}
if(CM_cnt==3) {name="AUDJPY";}
if(CM_cnt==4) {name="AUDNZD";}
if(CM_cnt==5) {name="AUDUSD";}
if(CM_cnt==6) {name="CADCHF";}
if(CM_cnt==7) {name="CADJPY";}
if(CM_cnt==8) {name="CHFJPY";}
if(CM_cnt==9) {name="EURAUD";}
if(CM_cnt==10) {name="EURCAD";}
if(CM_cnt==11) {name="EURCHF";}
if(CM_cnt==12) {name="EURGBP";}
if(CM_cnt==13) {name="EURJPY";}
if(CM_cnt==14) {name="EURNZD";}
if(CM_cnt==15) {name="EURUSD";}
if(CM_cnt==16) {name="GBPAUD";}
if(CM_cnt==17) {name="GBPCAD";}
if(CM_cnt==18) {name="GBPCHF";}
if(CM_cnt==19) {name="GBPJPY";}
if(CM_cnt==20) {name="GBPNZD";}
if(CM_cnt==21) {name="GBPUSD";}
if(CM_cnt==22) {name="NZDJPY";}
if(CM_cnt==23) {name="NZDUSD";}
if(CM_cnt==24) {name="USDCAD";}
if(CM_cnt==25) {name="USDCHF";}
if(CM_cnt==26) {name="USDJPY";}
ObjectCreate(chart_ID,name,OBJ_BUTTON,1,0,0);
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,CM_x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,CM_y);
ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,60);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,20);
ObjectSetString(chart_ID,name,OBJPROP_TEXT,name);
ObjectSetString(chart_ID,name,OBJPROP_FONT,"Courier New");
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,10);
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clrBlack);
ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,clrSilver);
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,false);
//--- successful execution
return(true);
}

//#######################################################################################################

//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{



if(id==CHARTEVENT_OBJECT_CLICK)
{
int win_handle=WindowHandle(sparam,PERIOD_D1);

int p = GetParent(win_handle);
SendMessageA(GetParent(p), WM_MDIMAXIMIZE, p, 0);
SendMessageA(GetAncestor(win_handle,3), WM_COMMAND, MT4_WMCMD_PERIOD_D1,sparam);
ObjectSetInteger(0,sparam,OBJPROP_STATE,false);
}
}

//###############################################################
  • Platform Tech
  • /
  • Open Existing chart from a button
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2021