input bool doBasketExit = true; // Check for Basket Exit conditions
input double BasketTP = 250.0; // Basket Take Profit (Account Currency) The chart Pair
input double BasketSL = -100.0; // Basket Stop Loss (Account Currency) The chart Pair
I’m running 9 pairs/Charts with BnG-v1w H1 and I want pair specific basket trading on each of the 9 charts.
Here's what just happened to me. 9 charts running, 3 charts are in trade with, of course, 3 separate pairs, each with 15 trades, yes 45 trades open, 2 are in profit & one is losing badly. I looking for a way to add up each group of the 15 separately and rub each group against a Basket SL & TP boundaries.
Why do I want this, I can't hedge so this my Stop_And_Limit_Order idea, crazy or not??
I was searching other EAs & TMs and found this at Rene's MADTrader 1.1, lines 372-418. I hoping someone can help me change this to a Basket specific pair “CloseAll”
See the following code for starters from Rene's MADTrader 1.1, lines 372-418:
Code: Select all
void closeTrades( CURRENCY* ¤cies[] ) {
// Check for Basket Exit
if ( doBasketExit ) {
double basketProfit = getBasketProfit();
if ( ( ( BasketTP > 0.0 ) && ( basketProfit > BasketTP ) ) ||
( ( BasketSL < 0.0 ) && ( basketProfit < BasketSL ) ) ) {
closeAll();
}
}
double getBasketProfit() {
double basketProfit = 0.0;
for (int iOrder=OrdersTotal()-1; iOrder >= 0; iOrder--) {
if (OrderSelect(iOrder,SELECT_BY_POS,MODE_TRADES)) {
if ( OrderMagicNumber() == MagicNumber ) {
if ( (OrderType() == OP_BUY) || (OrderType() == OP_SELL) ) {
basketProfit += OrderProfit() + OrderSwap() + OrderCommission();
}
}
}
}
return(basketProfit);
}
void closeAll() {
double closePrice;
string symbolName;
int result;
for (int iOrder=OrdersTotal()-1; iOrder >= 0; iOrder--) {
if (OrderSelect(iOrder,SELECT_BY_POS,MODE_TRADES)) {
if ( OrderMagicNumber() == MagicNumber ) {
if ( (OrderType() == OP_BUY) || (OrderType() == OP_SELL) ) {
symbolName = OrderSymbol();
closePrice = ( OrderType() == OP_BUY ) ? MarketInfo( symbolName, MODE_BID ) : MarketInfo( symbolName, MODE_ASK );
result = OrderCloseReliable(OrderTicket(), OrderLots(), closePrice, 50 );
}
}
}
}
}Ray