Is it possible to call a Script from an Indicator ?

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
1438
file45 2012.01.20 07:42 #
 
OK - that appears to clear up a few things - I think I need to step back and go through accumulated material - answers have been most helpful.
 
avatar
1438
file45 2012.02.15 18:59 #
 

This has been working successfully to call script to delete SL And TP Lines.

Warning: Can only be used to call scripts NOT EA

property copyright "Copyright © 2012 file45"
#property indicator_chart_window

extern int  Hot_Key1 = 162; // 162 L-Ctrl
extern int  Hot_Key2 = 90;  // 90 Z, 65 A
extern bool Show_Alert=true;

#include <WinUser32.mqh>

void keybd_event(int bVk, int bScan,int dwFlags,int dwExtrainfo); 

#define KEYEVENTF_EXTENDEDKEY          0x0001
#define KEYEVENTF_KEYUP                0x0002

#define VK_0   48
#define VK_1   49
#define VK_2   50
#define VK_3   51
#define VK_4   52
#define VK_5   53
#define VK_6   54
#define VK_7   55
#define VK_8   56
#define VK_9   57
#define VK_A   65
#define VK_B   66
#define VK_C   67
#define VK_D   68
#define VK_E   69
#define VK_F   70
#define VK_G   71
#define VK_H   72
#define VK_I   73
#define VK_J   74
#define VK_K   75
#define VK_L   76
#define VK_M   77
#define VK_N   78
#define VK_O   79
#define VK_P   80
#define VK_Q   81
#define VK_R   82
#define VK_S   83
#define VK_T   84
#define VK_U   85
#define VK_V   86
#define VK_W   87
#define VK_X   88
#define VK_Y   89
#define VK_Z   90

#define VK_LBUTTON         1     //Left mouse button
#define VK_RBUTTON         2     //Right mouse button
#define VK_CANCEL          3     //Control-break processing
#define VK_MBUTTON         4     //Middle mouse button (three-button mouse)
#define VK_BACK            8     //BACKSPACE key
#define VK_TAB             9     //TAB key
#define VK_CLEAR           12    //CLEAR key
#define VK_RETURN          13    //ENTER key
#define VK_SHIFT           16    //SHIFT key
#define VK_CONTROL         17    //CTRL key
#define VK_MENU            18    //ALT key
#define VK_PAUSE           19    //PAUSE key
#define VK_CAPITAL         20    //CAPS LOCK key
#define VK_ESCAPE          27    //ESC key
#define VK_SPACE           32    //SPACEBAR
#define VK_PRIOR           33    //PAGE UP key
#define VK_NEXT            34    //PAGE DOWN key
#define VK_END             35    //END key
#define VK_HOME            36    //HOME key
#define VK_LEFT            37    //LEFT ARROW key
#define VK_UP              38    //UP ARROW key
#define VK_RIGHT           39    //RIGHT ARROW key
#define VK_DOWN            40    //DOWN ARROW key
#define VK_PRINT           42    //PRINT key
#define VK_SNAPSHOT        44    //PRINT SCREEN key
#define VK_INSERT          45    //INS key
#define VK_DELETE          46    //DEL key
#define VK_HELP            47    //HELP key
#define VK_LWIN            91    //Left Windows key (Microsoft® Natural® keyboard)
#define VK_RWIN            92    //Right Windows key (Natural keyboard)
#define VK_APPS            93    //Applications key (Natural keyboard)
#define VK_SLEEP           95    //Computer Sleep key
#define VK_NUMPAD0         96    //Numeric keypad 0 key
#define VK_NUMPAD1         97    //Numeric keypad 1 key
#define VK_NUMPAD2         98    //Numeric keypad 2 key
#define VK_NUMPAD3         99    //Numeric keypad 3 key
#define VK_NUMPAD4         100   //Numeric keypad 4 key
#define VK_NUMPAD5         101   //Numeric keypad 5 key
#define VK_NUMPAD6         102   //Numeric keypad 6 key
#define VK_NUMPAD7         103   //Numeric keypad 7 key
#define VK_NUMPAD8         104   //Numeric keypad 8 key
#define VK_NUMPAD9         105   //Numeric keypad 9 key
#define VK_MULTIPLY        106   //Multiply key
#define VK_ADD             107   //Add key
#define VK_SEPARATOR       108   //Separator key
#define VK_SUBTRACT        109   //Subtract key
#define VK_DECIMAL         110   //Decimal key
#define VK_DIVIDE          111   //Divide key
#define VK_F1              112   //F1 key
#define VK_F2              113   //F2 key
#define VK_F3              114   //F3 key
#define VK_F4              115   //F4 key
#define VK_F5              116   //F5 key
#define VK_F6              117   //F6 key
#define VK_F7              118   //F7 key
#define VK_F8              119   //F8 key
#define VK_F9              120   //F9 key
#define VK_F10             121   //F10 key
#define VK_F11             122   //F11 key
#define VK_F12             123   //F12 key
#define VK_F13             124   //F13 key
#define VK_NUMLOCK         144   //NUM LOCK key
#define VK_SCROLL          145   //SCROLL LOCK key
#define VK_LSHIFT          160   //Left SHIFT key
#define VK_RSHIFT          161   //Right SHIFT key
#define VK_LCONTROL        162   //Left CONTROL key
#define VK_RCONTROL        163   //Right CONTROL key
#define VK_LMENU           164   //Left MENU key
#define VK_RMENU           165   //Right MENU key

int Orders;
//+------------------------------------------------------------------+
int start()
{
   if (Orders>OrdersTotal()) Closed_Order_Detect(); 
   Orders=OrdersTotal(); 
    
   return(0);
}  
//+------------------------------------------------------------------+
void Closed_Order_Detect()
{   
   double Order_Close;
   for(int i = OrdersHistoryTotal()-1;i >=0; i--)
   //for i,hstTotal=OrdersHistoryTotal();
   //for(i=0;i<hstTotal;i++)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
   if (OrderSymbol()==Symbol())      
      {
      Order_Close=OrderClosePrice(); 
      if (Order_Close==OrderStopLoss()||Order_Close==OrderTakeProfit()||(OrderCloseTime()!=0)) SendKey(0);                  
      }                  
   }       
}
//+------------------------------------------------------------------+
void SendKey(int key, bool release = false)
{         
    keybd_event(key,0,0,0);
    keybd_event(Hot_Key1, 0, 0, 0); // Left-Ctrl (162)
    keybd_event(Hot_Key2, 0, 0, 0); // Z (90)
    keybd_event(Hot_Key2, 0, KEYEVENTF_KEYUP, 0); 
    keybd_event(Hot_Key1, 0, KEYEVENTF_KEYUP, 0);  
        
    if(release) keybd_event(key, 0, KEYEVENTF_KEYUP, 0);             
}

 
avatar
55
strontiumDog 2016.05.12 21:27 #
 
file45:

This has been working successfully to call script to delete SL And TP Lines.

Warning: Can only be used to call scripts NOT EA

I know this was 4 years ago, but running the above code gives me

'keybd_event' - function must have a body       hotkey.mq4      150     5
'keybd_event' - function must have a body       hotkey.mq4      151     5
'keybd_event' - function must have a body       hotkey.mq4      152     5
'keybd_event' - function must have a body       hotkey.mq4      153     5
'keybd_event' - function must have a body       hotkey.mq4      154     5
'keybd_event' - function must have a body       hotkey.mq4      156     17
avatar
126
Demos 2016.05.13 10:51 #
 

hello,

i guess it is a typo in the original article, or maybe things have changed over the years

property copyright "Copyright © 2012 file45"
#property indicator_chart_window

extern int  Hot_Key1 = 162; // 162 L-Ctrl
extern int  Hot_Key2 = 90;  // 90 Z, 65 A
extern bool Show_Alert=true;

#include <WinUser32.mqh>

void keybd_event(int bVk, int bScan,int dwFlags,int dwExtrainfo); /* it has to be int dwExtraInfo, 

                                                                     that is, Info with a capital i */

 

you can find that inside the WinUser32.mqh file

 

best regards 

Back to topics list   | 1 2  

To add comments, please log in or register