MT4 - two questions

Hi there,

I have a couple of questions about using MT4, if may?

1.) How easy would it be to code an automatic buy/sell order, where I dictate to the software WHEN I want to actually enter a trade, and it automatically enters my trailing stop, PCI stop loss, lot size etc…

2.) Is there any way of having a trailing stop smaller than the 15 pip stated minimum? Maybe something that needs to be programmed? If not, do other packages offer something smaller?

Many thanks for your time and help.

Cord

for your first question thats one of meta traders strength, You would have to know MQL, the programming language for meta trader, and if you find a well written how to or tutorial, I’ld be happy to read it :slight_smile:

With the power that meta trader offers I’m sure you could make a custom trailing stop, but I dont think that is the limit, however I dont typically use meta trader right now eigther…

Thanks Simy,

I’ve been trawling google for existing scripts and/or advice on how to get this to work how I’d like it, but as I have no background in programming it’s a lot of two steps forward twelve steps back, heh.

I do have a few friends online who programme for a living, so will ask them nicely if they think they would be able to get to grips with it.

It’s not essential for the moment, but if something I’m currently trying out proves to be successful, it will be nice to have some of the more mind numbing parts automated :rolleyes:

This should be simple. Start MT, open the Navigator, scroll down to Scripts, find the one that says “Trade” and right-click it - select Modify.

A little editor will open. Now you can tweak it. If you look at the code it’s setup to BUY. But you can make one for BUY and a second script for SELL. Then you can enter in the Stop loss and Take profit. When you’re done, save it (or “Save As” for the Sell one, so you have two) and then they will appear on the list. Right-click again and you can assign a hot key (like ALT+S or ALT+B or something not used by any other programs). Voila!

So to make an order with 1.0 lots, 3 pips slippage allowed, a 50 pip TP and a 25 pip SL, you would change this:

[I]ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25Point,Ask+50Point,“Buy order”,16384,0,Blue);[/I]

It’ll also make a nice little blue arrow on your chart where the order was placed. :cool:

If you make a second one for selling, it would look like this, and will make a little red arrow on the chart:

[I]ticket=OrderSend(Symbol(),OP_SELL,1,Ask,3,Ask-25Point,Ask+50Point,“Sell order”,12345,0,Red);[/I]

Be sure to compile it after each change. If there’s an error, double-click the error and it’ll take you right to the line where you need to fix something. :slight_smile:

I should add - you can’t do less than 15 pips stop in MT, but even if you did that would be crazy in my opinion. Just a tiny movement would hit that right away.

You can, however, program an EA (Expert Advisor - a more advanced script) to follow your trade and modify the order and the SL automatically.

That’s fantastic Poco, thanks!

I’ll take a look at those and see where they lead me. As I need to open more than one lot at a time this should really save me some time.

Thanks again.

Cord

I inserted that script into my MT4, and it worked a treat! Many thanks!

May I ask for just a little more of your time though?

1.) Would it be possible to include more than buy order in the script? I’d like to have 2 or more buys with each click of the script if possible?

2.) Is it possible to include a trailing stop in with this initial buy order, or does that need to be set seperatley?

3.) Is it possible to have this set a pending order, rather than an instant execution? (EDIT - I found the OP_BUYSTOP or OP_BUYLIMIT functions in the meta trader editor, but can’t test it until the market resumes later tonight - are these the right ones?)

I’m going to try and find the answers to these through google if I can, but if anyone reads this before I post back saying I’ve found them and can/would like to help, that would be great!

many thanks,

Cord

This might help you :slight_smile:
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25Point,Ask+50Point,“Buy order”,16384,0,Blue);

volume(lots)
price
slippage(pips)
stop loss(price)
take profit(price)
expiration, for pending orders

That’s truly excellent, thankyou Simy.

I have little to no coding experience, great to get help like this - but erm, where abouts in that line of code would I put my trailing stop? Or does that need a separate line?

I have found some code to add a trailing stop, but not how to add it whilst I am actually placing the order. :confused:

Well to be honest just because I can sometimes program simple programs in a few languages dosnt mean I know a thing about MQL :stuck_out_tongue_winking_eye: I can however give it a shot as I plan to eventually learn it so I can setup my computer(s) to automagically page me when I would prefer to look at a chart (eg setup, and signal alerts)

If you want my help your going to have to help me, show me where you went for what you have learned/code you have, and also how you execute it, this to me seams to be a script of some sort and not an EA but I could be wrong…

I can then look into a trailing stop but I have a feeling its a little more involved, but I sure can give it a shot for ya…

Sure thing,

I’ve been trying to expand my very limited knowledge with a website that I’ll have to PM you as I’m not allowed to post links yet :smiley:

Check your inbox!

Can you explain to me what you want? And do you know if you can have an EA do this for you as apparently a script cant do a trailing stop…

I’m learning though, so just remember I dont have the answers but I’m willing to search for them…

Well, for the moment if you just use that link for your own benefit and go along at your own pace, I have a friend who programs who is currently looking into it for me. I didn’t want to ask him first of all as he doesn’t trade, so knew alot of the terminology would be difficult for him.

Turns out though he’s quite keen to learn everything anyways, so he’s going to try and help.

Many, many thanks for your help so far Simy and everyone else - and if I do run into a wall and you’re advancing nicely, would be great to be able to call on you?

Thanks again

Cord

I’ld be happy to help if ever you need it, if only to expand my horizons :slight_smile:

If you view my profile and then find my website homepage in there, I have a series of links on my site that will help you immensely - it’s the entire set of links to the MQL4 programming language, including a book they wrote. :slight_smile:

You can have MT4 email you, too. I do that. It’s “SendMessage” - just google “mql4 sendmessage” and you should find the documentation.

Excellent thanks Poco, I’ll check that out!