Can anybody help pretty please?

wingate
Trader
Posts: 32
Joined: Mon Jan 09, 2012 6:04 pm

Can anybody help pretty please?

Post by wingate »

Hi,

I have been tearing my hair out trying to find some simple scripts to do the following tasks. I have searched high and low on the net to find something that works but to no avail. I have tried to modify a couple myself (below) but they still do not work :evil:

If some kind soul could help me out I would be eternally grateful :mrgreen:

The Four scripts I am after are as follows:-

1. Close all 'OPEN SELL' trades (must not close pending sells at the same time though)
2. Close all 'OPEN BUY' trades (again must not close pending buys at the same time though)
3. This one may be harder to code, I have no idea but It would be useful to have a script that could
place a series of pending orders of either buy/sell limit/stop orders at predefined distances apart (user selectable). P.s I do not need any options for TP, stops or trailing stops as I do not use them.
4. Close all pending orders (if there was a user definable option to 'close all' or close just the buys or sells then that would be brill but not essential)

I have attached below scripts that I did manage to find but for some reason they do not appear to work as they should or work slightly differently to required.

Thank you so much for anybody who thinks they could possibly help.

Regards,
Baz.
close-all-buy-orders.mq4
RLF_Multi-Pending_Script.5Digit.ex4
close-all-sell-orders.mq4
You do not have the required permissions to view the files attached to this post.
User avatar
bourgenot
Trader
Posts: 159
Joined: Mon Aug 27, 2012 4:37 pm

Re: Can anybody help pretty please?

Post by bourgenot »

I, check this. Maybe help you; take look here :
http://www.forexfactory.com/showthread. ... ht=scripts
You do not have the required permissions to view the files attached to this post.
wingate
Trader
Posts: 32
Joined: Mon Jan 09, 2012 6:04 pm

Re: Can anybody help pretty please?

Post by wingate »

Hi bourgenot,

Thank you for trying to help out :) Unfortunately neither of those files do what I need them to do.

Thanks though.
Baz

Edit: Sorry I didn't notice the link you posted, I will have to investigate that one further thank you. :shock:
MrLong

Re: Can anybody help pretty please?

Post by MrLong »

wingate wrote:Hi,

I have been tearing my hair out trying to find some simple scripts to do the following tasks. I have searched high and low on the net to find something that works but to no avail. I have tried to modify a couple myself (below) but they still do not work :evil:

If some kind soul could help me out I would be eternally grateful :mrgreen:

The Four scripts I am after are as follows:-

1. Close all 'OPEN SELL' trades (must not close pending sells at the same time though)
2. Close all 'OPEN BUY' trades (again must not close pending buys at the same time though)
3. This one may be harder to code, I have no idea but It would be useful to have a script that could
place a series of pending orders of either buy/sell limit/stop orders at predefined distances apart (user selectable). P.s I do not need any options for TP, stops or trailing stops as I do not use them.
4. Close all pending orders (if there was a user definable option to 'close all' or close just the buys or sells then that would be brill but not essential)

I have attached below scripts that I did manage to find but for some reason they do not appear to work as they should or work slightly differently to required.

Thank you so much for anybody who thinks they could possibly help.

Regards,
Baz.
close-all-buy-orders.mq4
RLF_Multi-Pending_Script.5Digit.ex4
close-all-sell-orders.mq4

Close all Buy trades.

Code: Select all



//+------------------------------------------------------------------+
//| Close All Buys Button Function                                        |
//+------------------------------------------------------------------+
void CloseAllBuys(int Slippage, int MagicNumber)
{
    bool closed = false;
    for (int i = OrdersTotal(); i >= 0; i--)
    {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        while (IsTradeContextBusy())
            Sleep(100);
        RefreshRates();
        if (OrderType() == OP_BUY && (MagicNumber == OrderMagicNumber()))
        {
            closed = OrderClose(OrderTicket(), OrderLots(),
                                NormalizeDouble(MarketInfo(OrderSymbol(), MODE_BID), MarketInfo(OrderSymbol(), MODE_DIGITS)), Slippage, CLR_NONE);
           
        }
      
    }
}
Call like :
CloseAliBuys(7, MagicNumber);


Close All Sells.

Code: Select all

//+------------------------------------------------------------------+
//| Close All Sells Button Function                                        |
//+------------------------------------------------------------------+
void CloseAllSells(int Slippage, int MagicNumber)
{
    bool closed = false;
    for (int i = OrdersTotal(); i >= 0; i--)
    {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        while (IsTradeContextBusy())
            Sleep(100);
        RefreshRates();
        if (OrderType() == OP_SELL && (MagicNumber == OrderMagicNumber()))
        {
            closed = OrderClose(OrderTicket(), OrderLots(),
                                NormalizeDouble(MarketInfo(OrderSymbol(), MODE_BID), MarketInfo(OrderSymbol(), MODE_DIGITS)), Slippage, CLR_NONE);
           
        }
      
    }
}
Call like :
CloseAllSells(7, MagicNumber);

Delete Pendings.

Code: Select all

//+------------------------------------------------------------------+
// Expert Function : Delete All Pending Trades
//+------------------------------------------------------------------+
void DeletePendingTrades()
{
    for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
    {
        if (!OrderSelect(cc, SELECT_BY_POS))
            continue;
        if (OrderMagicNumber() != MagicNumber)
            continue;
        if (OrderType() == OP_BUY || OrderType() == OP_SELL)
            continue;

        bool result = OrderDelete(OrderTicket());
        if (result)
            cc++;
   
    }
}
Call Like:
DeletePendingTrades();
wingate
Trader
Posts: 32
Joined: Mon Jan 09, 2012 6:04 pm

Re: Can anybody help pretty please?

Post by wingate »

Hi again bourgenot,

Just to let you know I have just had a quick breeze through the link you provided. This looks like more than I need but may well do the trick! I will experiment with the scripts tomorrow to see if they work as described.

Thanks again for your help.

Kind regards,
Baz. :P
wingate
Trader
Posts: 32
Joined: Mon Jan 09, 2012 6:04 pm

Re: Can anybody help pretty please?

Post by wingate »

Hi Mr Long,

Again thank you for chiming in with help. Being just a cut and paister am I right in assuming I should cut and past your code into the files I uploaded? Sorry if this is a dumb question. :lol:

Regards,
baz
MrLong

Re: Can anybody help pretty please?

Post by MrLong »

wingate wrote:Hi Mr Long,

Again thank you for chiming in with help. Being just a cut and paister am I right in assuming I should cut and past your code into the files I uploaded? Sorry if this is a dumb question. :lol:

Regards,
baz
Yes then call the function from start, as described.
wingate
Trader
Posts: 32
Joined: Mon Jan 09, 2012 6:04 pm

Re: Can anybody help pretty please?

Post by wingate »

Hi Mr Long,

Sorry but I do not understand what you mean by "call the function from start, as described" :oops:

Thanks and sorry if I am being a dumb ass :lol:
wingate
Trader
Posts: 32
Joined: Mon Jan 09, 2012 6:04 pm

Re: Can anybody help pretty please?

Post by wingate »

Hi again,

When you say 'call' do you mean 'rename' the file? Also you mention magic number (7) should I be pasting a number into the code between the brackets? Sorry I really am starting to feel and sound like a dumb ass now :oops: :lol:
MrLong

Re: Can anybody help pretty please?

Post by MrLong »

These are finished scripts, save them to your Experts\scripts folder, restart Empty4, then just drop one on a chart and any sell/buy trades will be closed
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Scripts”