Download MetaTrader 5

Please guide me regarding spread

To add comments, please log in or register
Use MQL5 Cloud Network. It is secure!
tatyawinchu
101
tatyawinchu 2014.04.05 09:14 

Hello,

I found this script off web, all thanks and copyrights to that guy..

I dont understand coding, but could someone please let me know if this considers "SPREAD" while closing out orders?

Here is the copy paste of code

Because i dont know anything about coding or rules, I am not deleting any of info of copyright or his email or such .. I hope I am not breaking any forum rule :)

Here is a code, I am not even sure if its EA or if its a SCRIPT ..

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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

//| CloseTrades_After_Account_Profit_Reached.mq4 |

//| Copyright © 2007, Tradinator |

//| tradinator.fx@gmail.com |

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


#property copyright "Copyright © 2007, Tradinator"

#property link "tradinator.fx@gmail.com"



extern double My_Money_Profit_Target=100; //The amount of money profit at which you want to close ALL open trades.

extern string Profit_Target= "Enter above To Close all OPEN trades when amount of profit is Reached in Account and not per OPEN trade! ";

int Slippage=5;

int i;


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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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



int start()

{

if (AccountProfit()>= My_Money_Profit_Target)

{

for(i=OrdersTotal()-1;i>=0;i--)

{

OrderSelect(i, SELECT_BY_POS);

int type = OrderType();

bool result = false;

switch(type)

{

//Close opened long positions

case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);

break;

//Close opened short positions

case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);

}

if(result == false)

{

Sleep(0);

}

}

Print ("Account Profit Reached. All Open Trades Have Been Closed");

return(0);

}

Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),

"\nMy Account Profit Target: ",My_Money_Profit_Target);

return(0);

}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

If this doesnt work, I am looking for something that closes out ALL orders at X pips profit AFTER considering spread and stuff

Thanks so much.

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.05 09:29  
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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

//| CloseTrades_After_Account_Profit_Reached.mq4 |

//| Copyright © 2007, Tradinator |

//| tradinator.fx@gmail.com |

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


#property copyright "Copyright © 2007, Tradinator"

#property link "tradinator.fx@gmail.com"



extern double My_Money_Profit_Target=100; //The amount of money profit at which you want to close ALL open trades.

extern string Profit_Target= "Enter above To Close all OPEN trades when amount of profit is Reached in Account and not per OPEN trade! ";

int Slippage=5;

int i;


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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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



int start()

{

if (AccountProfit()>= My_Money_Profit_Target)

{

for(i=OrdersTotal()-1;i>=0;i--)

{

OrderSelect(i, SELECT_BY_POS);

int type = OrderType();

bool result = false;

switch(type)

{

//Close opened long positions

case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);

break;

//Close opened short positions

case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);

}

if(result == false)

{

Sleep(0);

}

}

Print ("Account Profit Reached. All Open Trades Have Been Closed");

return(0);

}

Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),

"\nMy Account Profit Target: ",My_Money_Profit_Target);

return(0);

}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Daniel Petrovai
440
Daniel Petrovai 2014.04.05 10:18  
tatyawinchu:

Hello,

I found this script off web, all thanks and copyrights to that guy..

I dont understand coding, but could someone please let me know if this considers "SPREAD" while closing out orders?

Here is the copy paste of code

Because i dont know anything about coding or rules, I am not deleting any of info of copyright or his email or such .. I hope I am not breaking any forum rule :)

Here is a code, I am not even sure if its EA or if its a SCRIPT ..

Hi tatyawinchu,

The EA submitted doesn't look right for your purpose. It is a sort of an incomplete EA (expert).

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

//| expert initialization function |

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

The EA starts by checking your account profit and if in profit by minimum 100 closes all orders.

Let's say you have a good trade, just made 200 $. Your account profit is 200. You open a new trade and then run this EA.

From the start it will check if the account is in profit (it is from previous trade) and if so, it will close the trade. Not good.

You need a script that monitors order profit and closes the order when the target is reached.Or, if you intend to place more than one order, it should monitor the sum of the profits for all orders.

You need something that at least counts your profit from the moment you start it, but best would be an EA that would check the Account equity when the order is placed and count the profit from that point on.

You can search the forum for money management EA's or scripts and if you don't find what you need you can post back here more details .

Hope it helps

tatyawinchu
101
tatyawinchu 2014.04.05 10:54  
thrdel:

Hi tatyawinchu,

The EA submitted doesn't look right for your purpose. It is a sort of an incomplete EA (expert).

The EA starts by checking your account profit and if in profit by minimum 100 closes all orders.

Let's say you have a good trade, just made 200 $. Your account profit is 200. You open a new trade and then run this EA.

From the start it will check if the account is in profit (it is from previous trade) and if so, it will close the trade. Not good.

You need a script that monitors order profit and closes the order when the target is reached.Or, if you intend to place more than one order, it should monitor the sum of the profits for all orders.

You need something that at least counts your profit from the moment you start it, but best would be an EA that would check the Account equity when the order is placed and count the profit from that point on.

You can search the forum for money management EA's or scripts and if you don't find what you need you can post back here more details .

Hope it helps


Thanks a loads for your quick reply ..

A few more quick questions regarding this matter:-

Trading Style: .. Min trades open at any time is ONE, Max trades open at any time is only TWO..[ different pairs] ..I will turn EA/Script to 'ON' when I execute the first trade .. Now, if X pips of profits are achieved I am trying to look for EA which will close the order by 'considering the bid ask spread when it is calculating X' ..

Now, if we have another order on other pair, so in total TWO orders, still when the total profit goes to X profits, EA should close both orders and its MUST consider spread cost of both and close X as PURE profit ..

For example .. say spread for pair A is 5 pips and spread for pair b is 10 pips .. If I do a setting in EA as exit at 10 pips profit, EA should exit after it considers that 15 pips is the spread to be paid plus 10 pips of profit for me .. to be clearer, it should not close out the order at 10 pips with sum total ending up to be -5 because of 15 spread..

Are these things available and possible in MT4 ?

thanks man.

tatyawinchu
101
tatyawinchu 2014.04.05 10:55  
deysmacro:


thanks man :)
Daniel Petrovai
440
Daniel Petrovai 2014.04.05 11:17  
tatyawinchu:


Thanks a loads for your quick reply ..

A few more quick questions regarding this matter:-

Trading Style: .. Min trades open at any time is ONE, Max trades open at any time is only TWO..[ different pairs] ..I will turn EA/Script to 'ON' when I execute the first trade .. Now, if X pips of profits are achieved I am trying to look for EA which will close the order by 'considering the bid ask spread when it is calculating X' ..

Now, if we have another order on other pair, so in total TWO orders, still when the total profit goes to X profits, EA should close both orders and its MUST consider spread cost of both and close X as PURE profit ..

For example .. say spread for pair A is 5 pips and spread for pair b is 10 pips .. If I do a setting in EA as exit at 10 pips profit, EA should exit after it considers that 15 pips is the spread to be paid plus 10 pips of profit for me .. to be clearer, it should not close out the order at 10 pips with sum total ending up to be -5 because of 15 spread..

Are these things available and possible in MT4 ?

thanks man.


Yes, it is possible since the spread for each pair is variable and the spread on one pair varies usually with the volume. So you're looking for a script/EA to manage the order profit, possible on different pairs and exit each order on a specified profit accounting for the spread available at the time.

I don't have anything ready to do just that, but I'm sure we can help you out. Unless you want a custom EA and are willing to post a job .

I'll keep in touch.

Keith Watford
Moderator
9625
Keith Watford 2014.04.05 11:33  

I think that you will find that AccountProfit()

is already net of spread.

tatyawinchu
101
tatyawinchu 2014.04.05 11:39  
GumRai:

I think that you will find that AccountProfit()

is already net of spread.


" already net of spread" = ? sorry bad at english ..

I found this on documentation site

AccountProfit

Returns profit value of the current account.

double AccountProfit();

Returned value

Profit value of the current account.

Example:

Print("Account profit ", AccountProfit());

It doesnt say if it considers spread or if it doenst .. plz help ?

Keith Watford
Moderator
9625
Keith Watford 2014.04.05 12:43  
tatyawinchu:


" already net of spread" = ? sorry bad at english ..

I found this on documentation site

AccountProfit

Returns profit value of the current account.

double AccountProfit();

Returned value

Profit value of the current account.

Example:

Print("Account profit ", AccountProfit());

It doesnt say if it considers spread or if it doenst .. plz help ?

Yes, it already considers spread.

If you have a short position open, look in the trade window of the terminal, under the 2nd price column, you will see the Ask, this is the price used for OrderProfit and spread is already allowed for.

tatyawinchu
101
tatyawinchu 2014.04.05 13:17  
thrdel:


Yes, it is possible since the spread for each pair is variable and the spread on one pair varies usually with the volume. So you're looking for a script/EA to manage the order profit, possible on different pairs and exit each order on a specified profit accounting for the spread available at the time.

I don't have anything ready to do just that, but I'm sure we can help you out. Unless you want a custom EA and are willing to post a job .

I'll keep in touch.


Thanks a loads.. very clear and very useful .. I wonder how much it would cost to post such a job? How difficult would u rate such code may be? The code I got off web which I have posted above looks HUGE .. I mean I really cant shell out thousands of dollars...
Keith Watford
Moderator
9625
Keith Watford 2014.04.05 13:47  
tatyawinchu:

Thanks a loads.. very clear and very useful .. I wonder how much it would cost to post such a job? How difficult would u rate such code may be? The code I got off web which I have posted above looks HUGE .. I mean I really cant shell out thousands of dollars...

I would think that you could get this coded for 20 or 30 $
1234
To add comments, please log in or register