MetaTrader 4 Scripts

 

I noticed there isnt a thread for MetaTrader 4 scripts. I dont really have any, and the few I have collected dont work. Besides the buy scripts, which can be found almost everywere, maybe someone has a trailing stop script, or a close all script, etc. I had a "close all open and pending order", but it didnt work. Ill see if I can find it to post it anyway.

Thanks all,

- secXces

 

Scripts thread!

secxces:
I noticed there isnt a thread for MetaTrader 4 scripts. I dont really have any, and the few I have collected dont work. Besides the buy scripts, which can be found almost everywere, maybe someone has a trailing stop script, or a close all script, etc. I had a "close all open and pending order", but it didnt work. Ill see if I can find it to post it anyway.

Thanks all,

- secXces

secXces,

It's a very good idea to have a thread for the scrpits( mql2 & mql4).

Hope to see this thread soon.

 

Trendline Script

codersguru:

Originally Posted by codersguru

Hi folks,

I've got a lot of private messages asking me for helping with some pieces of code.

Here you can post your questions related to MQL4, and I'll do my best to answer them.

codersguru I would like a script that executes a buy or sell order with stop loss and take profit when price crosses a trendline that I draw on the chart. Also, I would like the script to have the ability to disable the buy/sell function and only generate an alert when the trendline is crossed by the price. I hope you can help with this. Thank you very much, Happy New Year!

 

Can you please help me with the referencing of the previous value on an indicator for example:

MovingAverage[2]

 

Script to close all positions

Here is a little script I wrote that closes all open positions. You need to check "Alow Live Trading" option under Options > Expert Advisor tab in order for this script to work.

To Setup:

- Open up MetaEditor.

- Click File > New

- Select "Script program"

- Select replace all text with code below

- Compile & Run

I hope you find it as useful as I do.

//+------------------------------------------------------------------+

//| CLOSE_ALL.mq4 |

//| pileo|

//| http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "pileo"

#property link "http://www.metaquotes.net"

#include

#include

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

int start()

{

//----

if(MessageBox("Do you really want to close all positions?", "Close All", MB_YESNO|MB_ICONQUESTION) !=IDYES) return(1);

double prc;

int prc_mode;

int total = OrdersTotal();

int orders[];

int size;

size = ArrayResize(orders, total);

//Get original positions

for(int i=0;i<total;i++)

{

OrderSelect(i, SELECT_BY_POS);

orders = OrderTicket();

}

if(size <= 0)

{

//No open orders

return(-1);

}

int ticketSent;

for(int x=0;x<size;x++)

{

OrderSelect(orders[x], SELECT_BY_TICKET);

if(OrderType()==OP_BUY)

prc_mode = MODE_BID;

else

prc_mode = MODE_ASK;

prc = MarketInfo(OrderSymbol(), prc_mode);

Print("Closing Order # ", orders[x], " symbol: ", OrderSymbol(), " price: ", prc);

if(OrderClose(orders[x],OrderLots(),prc,3))

{

Print("Order # ", orders[x], " closed");

}

else

{

Print("Failed to close Order # ", orders[x], " Error: ", GetLastError());

return(false);

}

}

//----

return(0);

}

//+------------------------------------------------------------------+

 
pileo:
Here is a little script I wrote that closes all open positions. You need to check "Alow Live Trading" option under Options > Expert Advisor tab in order for this script to work.

To Setup:

- Open up MetaEditor.

- Click File > New

- Select "Script program"

- Select replace all text with code below

- Compile & Run

I hope you find it as useful as I do.

//+------------------------------------------------------------------+

//| CLOSE_ALL.mq4 |

//| pileo|

//| http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "pileo"

#property link "http://www.metaquotes.net"

#include

#include

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

int start()

{

//----

if(MessageBox("Do you really want to close all positions?", "Close All", MB_YESNO|MB_ICONQUESTION) !=IDYES) return(1);

double prc;

int prc_mode;

int total = OrdersTotal();

int orders[];

int size;

size = ArrayResize(orders, total);

//Get original positions

for(int i=0;i<total;i++)

{

OrderSelect(i, SELECT_BY_POS);

orders = OrderTicket();

}

if(size <= 0)

{

//No open orders

return(-1);

}

int ticketSent;

for(int x=0;x<size;x++)

{

OrderSelect(orders[x], SELECT_BY_TICKET);

if(OrderType()==OP_BUY)

prc_mode = MODE_BID;

else

prc_mode = MODE_ASK;

prc = MarketInfo(OrderSymbol(), prc_mode);

Print("Closing Order # ", orders[x], " symbol: ", OrderSymbol(), " price: ", prc);

if(OrderClose(orders[x],OrderLots(),prc,3))

{

Print("Order # ", orders[x], " closed");

}

else

{

Print("Failed to close Order # ", orders[x], " Error: ", GetLastError());

return(false);

}

}

//----

return(0);

}

//+------------------------------------------------------------------+

can you make it close orders like every 30 minutes?

 

Hello people wanted to know if there is a script to close /exit/remove or kill all the ea's

from the charts.Thanks.

 
maalox:
Hello people wanted to know if there is a script to close /exit/remove or kill all the ea's from the charts.Thanks.

maalox

You can check this : https://www.forex-tsd.com/forum/debates-discussions/116-something-interesting-please-post-here/page391#comment_748167