To have my renko generator launch an offline chart, press F8 on that chart and uncheck the "Offline Chart" function. Then load a template which contains an EA as part of the template.
Results:
I've managed to get it to launch an offline chart and also select the offline chart and press F8 to open the chart properties. I still need to uncheck "Offline Chart" in the properties so that the chart is tradeable with a Renko EA. But I can't seem to figure out how to get this new window.
Since the Renko generator code is irrelevant I will post my mess of code that I've cobbled together so far.
Any help is greatly appreciated.
Thank you
- David
Code: Select all
#include <WinUser32.mqh>
#include <stdlib.mqh>
//+------------------------------------------------------------------+
#import "user32.dll"
int RegisterWindowMessageA(string lpString);
//For Window operations on offline chart
int PostMessageA(int hWnd,int Msg,int wParam,int lParam);
int GetAncestor (int hwnd, int gaFlags);
int GetLastActivePopup( int hWnd );
#import
//+------------------------------------------------------------------+
//For minimizing Renko EA window
#define SW_SHOWMINIMIZED 11
#define VK_F8 0x77 //- F8 Key (119)
#define VK_DOWN 0x28 // Down Arrow
#define VK_UP 0x26 // Up Arrow
#define VK_SPACE 0x20 //- Space Bar (32)
#define VK_RETURN 0x0D //- Return Key (13)
#define GA_ROOT 2
void OpenRenkoChart() {
//Check if offline chart(2 period) is open
int win_handle=0;
win_handle=WindowHandle(Symbol(),2);
if(win_handle !=0) return; //If so get out of this
if(win_handle == 0) //If not
{
Print("Opening Chart");
long chartid = ChartOpen(Symbol(),PERIOD_M2);
// On the opened offline chart Press F8, Uncheck Offline Chart,
// Press Enter (Makes Chart Tradable
int OffChart= GetAncestor(WindowHandle(Symbol(),Period()),GA_ROOT);
PostMessageA(OffChart, WM_KEYDOWN, VK_F8, 0);
//F8 Window pops up how do I select this window to run keys?
int GetPopUp = GetLastActivePopup(HTerminal);
PostMessageA(GetPopUp, WM_KEYDOWN, VK_DOWN, 0); //Maybe if I send arrow down and
PostMessageA(GetPopUp, WM_KEYDOWN, VK_UP, 0); //arrow up first before hitting space?
PostMessageA(GetPopUp, WM_KEYDOWN, VK_SPACE, 0); //Press space to uncheck "Offline Chart"
PostMessageA(GetPopUp, WM_KEYDOWN, VK_RETURN, 0); //Press return to close this window
//Next Minimize this generator window (Works)
int hWnd = WindowHandle(Symbol(), Period());
int parent = GetParent(hWnd);
ShowWindow(parent, SW_SHOWMINIMIZED);
//Finally get the ChartID of opened chart and apply a template to auto load an EA (Works)
ChartApplyTemplate(chartid,"Offline.tpl");
//Force an update on the active chart redraw on this window (Renko Generator) (works)
UpdateChartWindow();
}
return;
}