AutoHotkey for MetaTrader 4 signal to IQ Option
This bot is just a simple tool to get signal from your MetaTrader 4 then click Put or Call on your IQ Option software accordingly.
As for my limited knowledge, the most simple solution to access both and can simply be coded was using the clipboard. The idea was to simply designate a letter to the clipboard from MetaTrader 4 script when a signal happen then AutoHotkey script will detect the clipboard and execute according to the signal.
The problem with this is you cannot use the clipboard or copy something while the AutoHotkey script is running. As long as you do not use the clipboard, you can still use your computer.
What do we need?
AutoHotkey and MetaTrader 4 will be our software for this or you can use your own MetaTrader 4 broker as long as the tick data was almost identical to IQ Option. Personally I use FXCM as my broker.
How to set it up?
First, AutoHotkey and MetaTrader 4 must be installed then download or right click and save my AutoHotkey script (myBot.ahk) and Metatrader 4 EA. (myStrategy.mq4)
Save the AutoHotkey script anywhere you like and Metatrader 4 EA to MQL4\Experts of your MT4 installation folder.
We will now set the coordinates of the X and Y of Call and Put button in the AutoHotkey script.
- Open Active Window Info (Window Spy) and the IQ Option program. The IQ Option program must be the active window then hover your mouse cursor to the CALL button.
- Make sure that IQ Option is in Window Title then write down the Relative value of Mouse Position. Example below was "Relative: 1307, 440" which means X is 1307 and Y is 440.
- Just like the procedure in CALL, do this also in PUT button. Hover your mouse to the PUT then write down again the X and Y.
Edit the value of variable "callx", "cally", "putx" and "puty" in your AutoHotkey script (myBot.ahk). The default character of what the script will detect in the clipboard was "a" for call and "b" for put. You can change it whatever you want but make sure that it what equivalent to the settings of the MT4 EA or else the script won't work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. | |
; #Warn ; Enable warnings to assist with detecting common errors. | |
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. | |
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. | |
; enter below the value of your Call and Put x and y using AutoHotkey Active Window Info (Window Spy) | |
; the value below was my settings using 1366x768 resolution of my laptop and a maximized IQ Option | |
callx = 1307 | |
cally = 440 | |
putx = 1307 | |
puty = 562 | |
call = a | |
put = b | |
SetTimer, main | |
main: | |
clipboard = ; Empty the clipboard | |
ClipWait | |
Sleep, 100 | |
cb = %clipboard% | |
winactivate, IQ Option | |
Sleep, 300 | |
if (cb == call) ; if character 'a' was detected in clipboard | |
{ | |
Click %callx%, %cally% ; Click Call | |
Sleep, 60000 ; wait for 1 minute before waiting again for another signal | |
} | |
if (cb == put) ; if character 'b' was detected in clipboard | |
{ | |
Click %putx%, %puty% ; Click Put | |
Sleep, 60000 ; wait for 1 minute before waiting again for another signal | |
} | |
return |
Next is open your MetaTrader 4 program then attach the EA (myStrategy.mq4) to the chart of your choice. Of course it must be the same with the chart on your IQ Option. In your MetaTrader 4, make sure that the "Allow DLL Input" was checked as it will be needed for the clipboard to work.
Once attached you can now run the AutoHotkey script (myBot.ahk) and wait for the signal.
The example strategy on this guide was a simple Parabolic SAR signal so don't use it on your real account or you will lose. It's just for demonstration purpose.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+------------------------------------------------------------------+ | |
//| myStrategy.mq4 | | |
//| Copyright 2017, MetaQuotes Software Corp. | | |
//| https://www.mql5.com | | |
//+------------------------------------------------------------------+ | |
#property copyright "Copyright 2017, MetaQuotes Software Corp." | |
#property link "https://www.mql5.com" | |
#property version "1.00" | |
#property strict | |
//---- copy to clipboard | |
#import "kernel32.dll" | |
int GlobalAlloc(int Flags, int Size); | |
int GlobalLock(int hMem); | |
int GlobalUnlock(int hMem); | |
int GlobalFree(int hMem); | |
int lstrcpyA(int ptrhMem, string Text); | |
#import | |
#import "user32.dll" | |
int OpenClipboard(int hOwnerWindow); | |
int EmptyClipboard(); | |
int CloseClipboard(); | |
int SetClipboardData(int Format, int hMem); | |
#import | |
#define GMEM_MOVEABLE 2 | |
#define CF_TEXT 1 | |
input double psar_step = 0.02; | |
input double psar_max = 0.2; | |
input string clipboardCall = "a"; | |
input string clipboardPut = "b"; | |
//+------------------------------------------------------------------+ | |
//| Expert tick/timer function | | |
//+------------------------------------------------------------------+ | |
void OnTick() | |
{ | |
double psar1 = iSAR(NULL,0,psar_step,psar_max,1); | |
double psar2 = iSAR(NULL,0,psar_step,psar_max,2); | |
if (psar1<Close[1] && psar2>Close[2]) { | |
CopyTextToClipboard(clipboardCall); | |
} | |
if (psar1>Close[1] && psar2<Close[2]) { | |
CopyTextToClipboard(clipboardPut); | |
} | |
} | |
//+------------------------------------------------------------------+ | |
bool CopyTextToClipboard(string Text) | |
{ | |
bool bReturnvalue = false; | |
// Try grabbing ownership of the clipboard | |
if (OpenClipboard(0) != 0) { | |
// Try emptying the clipboard | |
if (EmptyClipboard() != 0) { | |
// Try allocating a block of global memory to hold the text | |
int lnString = StringLen(Text); | |
int hMem = GlobalAlloc(GMEM_MOVEABLE, lnString + 1); | |
if (hMem != 0) { | |
// Try locking the memory, so that we can copy into it | |
int ptrMem = GlobalLock(hMem); | |
if (ptrMem != 0) { | |
// Copy the string into the global memory | |
lstrcpyA(ptrMem, Text); | |
// Release ownership of the global memory (but don't discard it) | |
GlobalUnlock(hMem); | |
// Try setting the clipboard contents using the global memory | |
if (SetClipboardData(CF_TEXT, hMem) != 0) { | |
// Okay | |
bReturnvalue = true; | |
} else { | |
// Failed to set the clipboard using the global memory | |
GlobalFree(hMem); | |
} | |
} else { | |
// Meemory allocated but not locked | |
GlobalFree(hMem); | |
} | |
} else { | |
// Failed to allocate memory to hold string | |
} | |
} else { | |
// Failed to empty clipboard | |
} | |
// Always release the clipboard, even if the copy failed | |
CloseClipboard(); | |
} else { | |
// Failed to open clipboard | |
} | |
return (bReturnvalue); | |
} |