'Close all'/'Open' tools - page 43

 

Jimmynz:

You can add the following snippet of code to check for day and time so your EA can close all trades.

extern bool FridayClose = true; // enable Friday close of all trades

extern int closeDay = 5; // Friday = market close day of week

extern int closeTime = 19; // 7 PM = market close time

int timeFlag = 0; // allow trades to occur

if (FridayClose && TimeHour(TimeCurrent())>=closeTime && TimeDayOfWeek(TimeCurrent())>=closeDay)

{

timeFlag=1; // set flag to stop trading

closeAll(); // function closes all trades opened by this EA

}

I hope this helps you.

Best wishes!

coderMike

~quality EA programming services~

 

not a script, but code for EA

newdigital:
'Close all' scripts for MT4.

Hi newdigital,

Thanks a lot for your post.

what I was actually looking for is not a script, but a code that I can install in my EA. For example, the orders open at the beginning of the day, and finish at the end of each day, but all orders (pending or market orders) don't close at all.

For example, I was given some suggestions like using new bar function or using time function so all orders close at the end of each day. The problem is that I don't know how to make such function work since I'm intermediate programmer. I really would appreciate it if you helped me out here. I want to be very professional programmer and coder.

Please let me know as soon as possible.

Thanks again for the scripts.

Best wishes,

 
coderMike:
Jimmynz:

You can add the following snippet of code to check for day and time so your EA can close all trades.

extern bool FridayClose = true; // enable Friday close of all trades

extern int closeDay = 5; // Friday = market close day of week

extern int closeTime = 19; // 7 PM = market close time

int timeFlag = 0; // allow trades to occur

if (FridayClose && TimeHour(TimeCurrent())>=closeTime && TimeDayOfWeek(TimeCurrent())>=closeDay)

{

timeFlag=1; // set flag to stop trading

closeAll(); // function closes all trades opened by this EA

}

I hope this helps you.

Best wishes!

coderMike

~quality EA programming services~

Hi Jimmynz,

Thanks a lot for your great help.

I have just one quick question please. Would this code help as well in closing at the daily bar. I'm using pending orders to trade in my code, but want the EA to close All pending and open orders at the end of daily candle.

I thought I have to use this:

if (Close[1] == Open[0])

return (1);

where 1 is using in the signal code function. Like if (signal ==1) blah blah blah

I'm still not pro programmer yet, but I want to be so that's why I will do my best to make this dream true.

Thanks again and I hope I can hear from you soon.

Best wishes,

 

I used this code, but didn't work

Hi,

I just want to mention that I used this code to close all orders, but didn't work at all.

if (AccountProfit() > 0)

{

DeleteOrders();

CloseOrders();

}

void CloseOrders()

{

int cnt = OrdersTotal();

for (int i=cnt-1; i >= 0; i--)

{

if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

int type = OrderType();

if (type == OP_BUY)

{

RefreshRates();

OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 3);

}

if (type == OP_SELL)

{

RefreshRates();

OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 3);

}

}

}

void DeleteOrders()

{

int cnt = OrdersTotal();

for (int i=cnt-1; i >= 0; i--)

{

if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

int type = OrderType();

if (type == OP_BUYSTOP || type == OP_SELLSTOP || type == OP_BUYLIMIT || type == OP_SELLLIMIT)

{

OrderDelete(OrderTicket());

}

}

}

It is strange that some codes are correct, but don't work.

Please let me know if you have opinion about that.

Best wishes,

 

Buy/Sell ALL CHF script pls!!!!

Hello,

I need help if anyone can guide me where to find a script that can BUY @ SELL all CHF pairs or make me one if not too burden

thx in advance

ps: sry if post this at the wrong section

 

Does anyone have a close specific currency EA when the average price of only that specific pair reaches a user input profit target?

 

script pending order on MA

Hi all

could you please help me out

i need a script that will execute on the chart

pending order = MA

i found something but cant get it working

please help

 

IcebergOrders [Script]...

Here's a open order/iceberg order tool that might be useful for some folks...;)

 

Script: Close All positions and do reversal.

Hello

Is it posible to do a script that closes all positions and takes reversal with the same size?

Example:

Im Long GBPUSD 1.0 lots

Also Long GBPJPY 1.0 lots

SCRIPT activated

Now Im short GBPUSD 1.0 lots

Also short GBPJPY 1.0 lots.

Thanks!

Thanks in advance.

 
monotomiatsd:
Hello

Is it posible to do a script that closes all positions and takes reversal with the same size?

Example:

Im Long GBPUSD 1.0 lots

Also Long GBPJPY 1.0 lots

SCRIPT activated

Now Im short GBPUSD 1.0 lots

Also short GBPJPY 1.0 lots.

Thanks!

Thanks in advance.

The rough pseudocode in start() would be

for (int i=0;i<OrdersTotal();i++) {

if (OrderSymbol() == Symbol() && (OrderType() == OP_BUY || OrderType() == OP_SELL)) {

if (OrderType() == OP_BUY) {

OrderSend(OP_SELL,OrderLots(),...)

} else if (OrderType() == OP_SELL) {

OrderSend(OP_BUY,OrderLots(),...)

}

OrderClose(OrderTicket(),...);

}

}
Reason: