executing scripts on chart

 

Hi All,

4 months ago i started to trade with forex using mt4 platform, one thing i don't get

how to executu script on chart.

I spent quite some time working as developer in C# and C++, so i am quite good with coding.

thing is when I drag even the simpliest script on chart, nothing happens, no new order is created nothing.

I found here on this site some script how to make 3 same orders, i will paste it bellow:

#property copyright "Copyright © 2008, PRMQuotes Software Corp."

#include <stdlib.mqh>
#include <WinUser32.mqh>

extern double Lots = 1.0;

int start()
{


OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask+16,Ask+36,"refa1",0,0,CLR_NONE);
//OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"refa2",0,0,CLR_NONE);
//OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"refa3",0,0,CLR_NONE);

}

I pasted it in ME compiled it and then it showed up in the mt4 in sidebar.


As i understand this script, when i drag her on the chart, should figure it out which symbol i am dealing with (should it?), and then place the trade as active.

when i drag it to the chart nothing happens. I don't know why.

Should i specify what symbols i am trading inside the script or how does it go.

As i mentioned, i quite good with coding and have really good knowledge in math, aproximations, predictions and so on regarding the functions.

Please help me run and execute first script on mt4 so i can start creating some tools.


p.s.

I didn't manage to run even default scripts that come with mt4, i don't know how i couldn't find it anywhere described. that is why i am posting here.

 

I assume you are using a demo account, so there should be no issue over the broker allowing EA-initiated orders.


Have you checked that the "Allow Live Trading" box is ticked and that the expert is showing a smily face at the top right of your chart?


If so, then I reckon if you print out the value returned by GetLastError(), you will probably see either:

- an invalid stops error (130), due to the fact that you are trying to execute a buy order and setting the stoploss higher than your entry price

or

- a not enough margin error (134 off the top of my head), if you don't have a leveraged account (as you are attempting to open a full lot)


As you state that you're a programmer, please allow me to slap your wrist for your shameful lack of exception handling. Go stand in the corner! :-)


CB

 

Some dealers don't permit stops and limits to be set in tht initial order

OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask+16,Ask+36,"refa1",0,0,CLR_NONE);
You may need to send the Buy, then OrderModify() the stop and limit

What error do you get?

 

Allow Live Trading wasn't selected. Thank you guys.

now it works :D

yeeee

Reason: