Get HWND of the Properties popup of an offline chart

Post Reply
DigitalCrypto
Trader
Posts: 237
Joined: Tue Feb 24, 2015 4:38 am

Get HWND of the Properties popup of an offline chart

Post by DigitalCrypto »

Goal:
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;
}
DigitalCrypto
Trader
Posts: 237
Joined: Tue Feb 24, 2015 4:38 am

Get HWND of the Properties popup of an offline chart

Post by DigitalCrypto »

I've figured it out using direct keyboard events. I wasn't taking into account the fact that a button pressed needed a release afterward.

Updated code follows:

Hope this helps someone else.

-David

Code: Select all

#import "user32.dll"
    int RegisterWindowMessageA(string lpString); 
    
    //For Window operations on offline chart
    void keybd_event(int bVk, int bScan,int dwFlags,int dwExtraInfo);
#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)

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);
      
      //Finally get the ChartID of opened chart and apply a template to auto load an EA
      ChartApplyTemplate(chartid,"Offline.tpl");
      Sleep(3000); //Give it time to load
      
      //Manually run a keyboard macro to enable EAs to trade offline charts
      keybd_event(VK_F8,0,0,0); //Hit the F8 key to open chart properties
      Sleep(10);
      keybd_event (VK_SPACE, 0, 0, 0 );   //space bar pressed
      Sleep(10);
      keybd_event (VK_SPACE, 0, KEYEVENTF_KEYUP, 0); //space bar released
      Sleep(10);
      keybd_event (VK_RETURN, 0, 0, 0 );              //Return key pressed
      Sleep(10);
      keybd_event (VK_RETURN, 0, KEYEVENTF_KEYUP, 0); //Return key released.
      Sleep(100);
 
      //Next Minimize this generator window
      int hWnd = WindowHandle(Symbol(), Period());
      int parent = GetParent(hWnd);
      ShowWindow(parent, SW_SHOWMINIMIZED);
   
      //Force chart window update
      UpdateChartWindow();
   }
   
   return;
}
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Get HWND of the Properties popup of an offline chart

Post by SteveHopwood »

Well done for figuring it out David - I would not even have started to bother to do so had you asked me.

Renko is recognised at SHF for the waste of time it is. Are you sure you are not simply throwing good time after bad?

Only curious. Not being critical. Just asking.

:xm: :rocket:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
DigitalCrypto
Trader
Posts: 237
Joined: Tue Feb 24, 2015 4:38 am

Get HWND of the Properties popup of an offline chart

Post by DigitalCrypto »

Hey Steve,

The reason for the code here was not specific to renko as it would apply to any offline chart type and you coder guys probably know this stuff cold but I wanted to be honest about what I was aiming to do in case anyone had asked specifics.

Yes I know exactly what you mean about renko but there's a small back story to this. Many years ago I met a guy name of "Jack". He would only come around every few months over the years to chat. When I asked him why the long vacations he told me that he could only trade a couple months out of the year because his broker would shut him down as he had made too much money (a few million dollars). Naturally, suspecting bullshit, I inquired further. Jack said that he only traded renko continuations of a larger but not specific size and would not divulge the whole method. Of course it's been plaguing my mind since. I figured I would take a stab at it and see if there was anything to it.

- David
Post Reply

Return to “Coders Hangout”