How to place orders to MT4

Hi!

I did’t find any solutions to send orders to MT4 platform (MetaQuotes).
There a lot of users of MT4, but there is no way to trade with AmiBroker + MT4.
And AFL language is much simpler and nicer to deal with than MQL4.
Why?

Thanks in advance!

This is not MT4 forum. MT4 is not supported.

I didn’t ask about MT4, I’m curious WHY you are NOT intererested in a lot of potentional customers of MT4 users?
As I know there is a solution AmiBroker + IB to trade throuhgh, but a quantity of MT4 users is much greater than IB users …
AmiBroker created a nice solution, but doesn’t care about to be integrated with other popular platforms for real trading.
The goal of a platform is real trading - sending orders, placing stops, moving trailing stops and cetera …
It’s not just backtesting and simulating.

I am interested in hundreds of things but I have only one life and quite frankly retail Forex (MT4 is a forex only as far as I know) as unregulated and manipulated and leveraged as it is, is just for amateurs who wish to lose their money. I have better things to do in life than to participate in driving hordes of naive people to forex brokers.

1 Like

Tomasz, I agree with you - Forex is manipulated as much as possible. Moreover it’s dangerous.
Trading is dangerous regardless of type of market.
And AmiBroker could simplify the life of thousands of MT4 users by backtesting, simulating and executing orders through MT4. AmiBroker has a lot of useful features except one - executing orders through diffrerent Forex platforms like MT4/5, OANDA API, LMAX API …
There are thousands and thousands traders with small acoounts and they can’t afford to trade futures or stocks …
By the way, driving a car is dangerous too, by with the right tools (rules of driving and cetera) we can travel, do our jobs, …
By the end, the goal of any tool is to help us.
Thanks.

Hello sinedanat,

i had a some problem like you, i searched long time to find code to send orders to MT4 platform because i could not write with MQL4. Fortunantely i found on mq4 code at http://paulsfxrandomwalk.blogspot.com.tr/2009/12/crude-api-for-metatrader-4.html . mq4 file already gone on this site but i added it here TradeformCSVfileV1little modifiied verison by me.

After download mq4 code, you have to run it, it is working as a script then drag&drop your chart on MT4.
In MT4 autotrade option should be open or selected.
last thing you have to create folder as a name “TradeFromCsvFile” on C:\Users\XusernameX\AppData\Roaming\MetaQuotes\Terminal\blablablanumber\MQL4\Files that’s all you should do at mt4 side.

Now you have to write your order to “…\MQL4\Files\TradeFromCsvFile\commandfile.txt” from amibroker.
like that //OrderSend(symbol,cmd,Volum,price,slippage,stoploss,takeprofit,comment,magic,expiration,arrow_color) or close your open order like that //" OrderClose",ticket,Volum,price,slippage,arrow_color)

Also you will can find “openorders.txt” at “…\MQL4\Files\TradeFromCsvFile\commandfile.txt”, you can read, your open order and closed them or modifiy them just with writing to “commondfile.txt” from amibroker.

Of course you can see there is limitation of this method because simply mq4 code read commandfile.txt every second and if there is something there, it will carry out this order. So if you send order it will carry out 1 second later and you cannot multi order at sametime. (Maybe it possible but i’m really beginner for coding, i’m just good to adapting exisiting code according to me)

I hope it will help you and others who are using MT4 with amibroker.

1 Like

@batu1453

How you manage the scale out?
For example you BUY 3 lots. Later on you need to close one by one your position. Ok?
After you close the first Lot the OrderID has change to different ID.
And my Question is.
How you can find / retrive the Number of the New ID that automatic Mt4 generate?

Then of course if you know the NewID, it is easy to send a new Order from Ami to .txt

when you run the script, it directly read your open order on MT4 and write to “openorders.txt” at “…\MQL4\Files\TradeFromCsvFile" so you can read all info your open order. But this script working with order comment.
there is comment number for every order so you have to use comment number when you want to close or modify your open order.

If you want open 3 lots on EURUSD pair,
Amibroker write to “commandfile.txt” like //OrderSend(symbol,cmd,Volum,price,slippage,stoploss,takeprofit,comment,magic,expiration,arrow_color)
for example: OrderSend,EURUSD,OP_BUY,3,,5,,,,,0,MediumOrchid
i just use slippage 5 , expiration is 0 other is depend on you.

1 second later script is read your ordersend command from “commandfile.txt” and execute it.

if you want to close 1 lot of your 3 lots EURUSD order,
Amibroker read your open order from “openorders.txt” it seems like that
2017.06.27 17:00,O:4425436988,0,EURUSD,OP_BUY,3,1.12835,0,0
and amibroker write again to “commandfile.txt”
//" OrderClose",ticket,Volum,price,slippage,arrow_color)
for example: OrderClose,O:4425436988,1,,5,MediumOrchid

of course you have a new comment number for 2 lots EURUSD but every new ordersend or orderclose, openorders.txt
refreshing by script so that amibroker can read new comment number for your 2 lot EURUSD.

if you need uniqe number for your order, you have to assign magic number when you use ordersend command, i guess it is not change when you partilly close or modifiy your order but i did not test it.

Of course you have to create some button to select your open orders if it is more than ones.

2 Likes

I someone is looking more about this subject
http://forum.amibroker.com/t/how-dont-display-creation-a-file-by-fopen-fputs-function/4844