|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
Hi There ...
Because you are working with any symbol you can not use things such as bid , ask, point but rather MarketInfo( OrderSymbol(), MODE_BID ), MarketInfo( OrderSymbol(), MODE_ASK ) etc ... Try updating to this: PHP Code:
PHP Code:
Patrick |
|
|||
|
Quote:
Code:
void closeProfitable(int tpPips, int magic) {
for(i=0; i<OrdersTotal(); i++) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
break;
if(OrderMagicNumber() != magic)
continue;
double oAsk = MarketInfo(OrderSymbol(), MODE_ASK);
double oBid = MarketInfo(OrderSymbol(), MODE_BID);
if(OrderType() == OP_BUY &&
oBid > OrderOpenPrice() + tpPips * Point) {
OrderClose(OrderTicket(),OrderLots(),oBid,0);
i--;
}
if(OrderType() == OP_SELL &&
oAsk < OrderOpenPrice() - tpPips * Point) {
OrderClose(OrderTicket(),OrderLots(),oAsk,0);
i--;
}
}
}
Last edited by mikkom : 03-29-2008 at 01:58 PM. |
|
||||
|
Yes but that would close trades on profit , I am looking at the combined trades menaing that EURUSD could be in 30pips+ and USDCHF could be in -15 pips so I look at the overall profit of trades with magic number 111 if the total profit from all those trades reach 15 pips I close all orders of magic number 111 only at combined profit of 15 pips
Quote:
|
|
|||
|
Quote:
Code:
#define MAX_MAGIC_NUMBER 100 // or whatever
void closeProfitable(int tpPips, int magic) {
double profit[MAX_MAGIC_NUMBER];
for(i=0; i<OrdersTotal(); i++) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
break;
if(OrderMagicNumber() != magic)
continue;
double oAsk = MarketInfo(OrderSymbol(), MODE_ASK);
double oBid = MarketInfo(OrderSymbol(), MODE_BID);
if(OrderType() == OP_BUY)
profit[OrderMagicNumber()] += oBid - OrderOpenPrice();
if(OrderType() == OP_SELL)
profit[OrderMagicNumber()] += OrderOpenPrice() - oAsk;
}
for(i=0; i<OrdersTotal(); i++) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
break;
if(OrderMagicNumber() != magic)
continue;
double oAsk = MarketInfo(OrderSymbol(), MODE_ASK);
double oBid = MarketInfo(OrderSymbol(), MODE_BID);
if(profit[OrderMagicNumber()] >= tpPips*Point) {
if(OrderType() == OP_BUY) {
OrderClose(OrderTicket(),OrderLots(),oBid,0);
i--;
}
if(OrderType() == OP_SELL) {
OrderClose(OrderTicket(),OrderLots(),oAsk,0);
i--;
}
}
}
|
|
||||
|
yes I think I can use part of the code it seems to do what I want, now I had made 3 experts , each one based on a reply I got
, lucky me. I will test them this week , I thank you Mistigri , mikkom and waltini your help is really appricated Last edited by MiniMe : 03-30-2008 at 05:49 PM. |
|
||||
|
Minime,
I created the following piece of code to get the total profit of all orders with the same magic number: PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
![]() |
![]() |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| magic number | forextrend | Metatrader 4 | 31 | 04-11-2008 04:27 PM |
| Magic Number question | Yoda_Glenn | Expert Advisors - Metatrader 4 | 1 | 02-22-2007 08:26 AM |
| MT4 Magic Number | DeadEye96 | Expert Advisors - Metatrader 4 | 2 | 09-19-2006 10:05 PM |
| magic number | caldolegare | Metatrader 4 | 4 | 03-19-2006 05:28 AM |