# Thread: Open opposite / reverse trade: The "holy grai'l of forex trading

1. ## Open opposite / reverse trade: The "holy grai'l of forex trading

I have spent a number of years forex trading, with some success. My trading strategies yield more successful trades than losses. But unless, you can open an opposite trade (not just a stop loss), then performance of any strategy is seriously limited.

funyoo, please please assist.

I have pasted detailed tread of the type of assistance that you can provide.

Max trade per bar

If you can provide this type of detailed instruction, I will be a happy-camper.

My strategy is

- If losses on an open trade exceed 75 pips, then open an opposite trade of the same pair.
- New opposite trade must have an higher lot
- Close this pair if losses on both trades exceed XXXX amount (I am prepared for losses, but at least they must be manageable)
- Close this pair if profit exceeds XXXXX amount

Funyoo, this is the holy grail of trading, whatever trading strategy anyone can think of.

Thank oyu in advance

2. Maybe this may help;

//+----------------------------------------------------------------------------------------------------------------------------------+
//|The intention of this strategy is: If losses on an open trade exceed 75 pips, then open an opposite trade of the same pair. |
//|- New opposite trade must have a higher lot |
//|- Close this pair if losses on both trades exceed \$20 amount (I am prepared for losses, but at least they must be manageable) |
//|- Close this pair if profit exceeds \$30 amount |
//| |
//| |
//+------------------- DO NOT REMOVE THIS HEADER ------------------------------------------------------------------------------------+

#define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

extern int MagicNumber = 4513194;
extern bool EachTickMode = True;
extern double Lots = 0.61;
extern double LotsRO = 1.26;
extern int Slippage = 5;
extern bool UseStopLoss = True;
extern int StopLoss = 150;
extern bool UseReverseStopLoss = True;
extern int ReverseStopLoss = 75;
extern bool UseTakeProfit = True;
extern int TakeProfit = 20;
extern bool UseReverseTakeProfit = True;
extern int ReverseTakeProfit = 80;
extern bool UseTrailingStop = True;
extern int WhenToTrail = 70;
extern int TrailingStop = 20;
extern bool UseReverseTrailingStopLoss = True;
extern int ReverseWhenToTrailLoss = 90;
extern int ReverseTrailingStopLoss = 30;

extern int MaxTradePerBar = 2;
int ThisBarTrade = 0;
datetime Time0;
int TradePerBar=0;
int BarCount=-1;
int Current;
bool TickCheck = False;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
Time0 = Time[0];
BarCount = Bars;
if (EachTickMode) Current = 0; else Current = 1;
Comment (Symbol(), TakeProfit , StopLoss );
return(0);
}

//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start() {
int Order = SIGNAL_NONE;
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;

double BuyLots, SellLots, BuyProfit, SellProfit;
double
ReverseStopLossLevel,
ReverseTakeProfitLevel,
ReverseWhenToTrail;

if (EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
Order = SIGNAL_NONE;

//+------------------------------------------------------------------+
//| Variable Begin |
//+------------------------------------------------------------------+

double Buy5_2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL, Current + 0);
double Buy7_2 = iCCI(Symbol(),0,12,PRICE_OPEN,0);

double Sell5_2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL, Current + 0);
double Sell7_2 = iCCI(Symbol(),0,12,PRICE_OPEN,0);

double CloseBuy3_1 = iMA(NULL, 0, 25, 0, MODE_SMMA, PRICE_OPEN, Current + 1);
double CloseBuy3_2 = iMA(NULL, 0, 100, 0, MODE_SMA, PRICE_OPEN, Current + 1);
double CloseBuy4_1 = iMA(NULL, 0, 25, 0, MODE_SMMA, PRICE_OPEN, Current + 0);
double CloseBuy4_2 = iMA(NULL, 0, 100, 0, MODE_SMA, PRICE_OPEN, Current + 0);
double CloseBuy5_1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL, Current + 1);
double CloseBuy5_2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL, Current + 0);
double CloseBuy6_1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN, Current + 0);
double CloseBuy6_2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL, Current + 0);

double CloseSell3_1 = iMA(NULL, 0, 25, 0, MODE_SMMA, PRICE_OPEN, Current + 1);
double CloseSell3_2 = iMA(NULL, 0, 100, 0, MODE_SMA, PRICE_OPEN, Current + 1);
double CloseSell4_1 = iMA(NULL, 0, 25, 0, MODE_SMMA, PRICE_OPEN, Current + 0);
double CloseSell4_2 = iMA(NULL, 0, 100, 0, MODE_SMA, PRICE_OPEN, Current + 0);
double CloseSell5_1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL, Current + 1);
double CloseSell5_2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL, Current + 0);
double CloseSell6_1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN, Current + 0);
double CloseSell6_2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL, Current + 0);

//+------------------------------------------------------------------+
//| Variable End |
//+------------------------------------------------------------------+

//Check position
bool IsTrade = False;

for (int i = 0; i < Total; i ++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
{

}

if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {

//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+

if (
CloseBuy3_1 < CloseBuy3_2
&& CloseBuy4_1 > CloseBuy4_2
&& CloseBuy5_1 > 0.001
&& CloseBuy5_2 < 0.001
&& CloseBuy6_1 > CloseBuy6_2
) Order = SIGNAL_CLOSEBUY;

//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if(Bid - OrderOpenPrice() > (Point*1) * TrailingStop) {
if(OrderStopLoss() < Bid - (Point*1) * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - (Point*1) * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
continue;

}
}
}
} else {

//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell) |
//+------------------------------------------------------------------+
if (
CloseSell3_1 > CloseSell3_2
&& CloseSell4_1 < CloseSell4_2
&& CloseSell5_1 < -0.001
&& CloseSell5_2 > -0.001
&& CloseSell6_1 < CloseSell6_2
) Order = SIGNAL_CLOSESELL;
//+------------------------------------------------------------------+
//| Signal End(Exit Sell) |
//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > ((Point*1) * TrailingStop)) {
if((OrderStopLoss() > (Ask + (Point*1) * TrailingStop)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + (Point*1) * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
continue;

}
}
}
}
}
}

//+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+

if (
Buy5_2 < -0.00150
&& Buy7_2 < -180
) Order = SIGNAL_BUY;

if (
Sell5_2 > 0.00150
&& Sell7_2 > 180
) Order = SIGNAL_SELL;

//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+

//Buy
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount) && (TradePerBar<=MaxTradePerBar)))) {

if(BarCount!=Bars){TradePerBar=0;BarCount=Bars;}

if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss) StopLossLevel = Ask - StopLoss * (Point*1); else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * (Point*1); else TakeProfitLevel = 0.0;
if(OrderMagicNumber () == MagicNumber)
if(OrderSymbol () == Symbol())
if(Bid-OrderOpenPrice () > WhenToTrail*(Point*1))
if(OrderStopLoss () < Bid-(Point*1)*TrailingStop)
OrderModify(
OrderTicket(),
OrderOpenPrice(),
Bid - ((Point*1)*TrailingStop),
OrderTakeProfit (),
0,
Yellow);

if(Time0!=Time[0]){

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel,"", MagicNumber, 0, DodgerBlue);

if (OP_SELLLIMIT > Ask + ReverseWhenToTrailLoss);
if (Order == OP_SELLLIMIT && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount) && (TradePerBar<=MaxTradePerBar)))) {
if (UseReverseStopLoss) ReverseStopLossLevel = Bid + ReverseStopLoss * (Point*1); else ReverseStopLossLevel = 0.0;
if (UseReverseTakeProfit) ReverseTakeProfitLevel = Bid - ReverseTakeProfit * (Point*1); else ReverseTakeProfitLevel = 0.0;
if(OrderMagicNumber () == MagicNumber)
if(OrderSymbol () == Symbol())
if(OrderLots () == LotsRO )
if(OrderOpenPrice () - Ask > ReverseWhenToTrail*(Point*1))
if(OrderStopLoss () > Ask + ReverseTrailingStopLoss * (Point*1) || OrderStopLoss () == 0)
OrderModify(
OrderTicket(),
OrderOpenPrice(),
Ask + (ReverseTrailingStopLoss * (Point*1)),
OrderTakeProfit (),
0,
Yellow);
Ticket = OrderSend(Symbol(), OP_SELLLIMIT, LotsRO, Ask, Slippage, ReverseStopLossLevel, ReverseTakeProfitLevel,"", MagicNumber, 0, Green);

Time0=Time[0];

if(Ticket>0)TradePerBar++;
}
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}

//Sell
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount) && (TradePerBar<=MaxTradePerBar)))) {

if(BarCount!=Bars){TradePerBar=0;BarCount=Bars;}

if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss) StopLossLevel = Bid + StopLoss * (Point*1); else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * (Point*1); else TakeProfitLevel = 0.0;
if(OrderMagicNumber () == MagicNumber)
if(OrderSymbol () == Symbol())
if(OrderOpenPrice () - Ask > WhenToTrail*(Point*1))
if(OrderStopLoss () > Ask + TrailingStop * (Point*1) || OrderStopLoss () == 0)
OrderModify(
OrderTicket(),
OrderOpenPrice(),
Ask + (TrailingStop * (Point*1)),
OrderTakeProfit (),
0,
Yellow);

if(Time0!=Time[0]){

Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel,"", MagicNumber, 0, DeepPink);
}

if (OP_BUYLIMIT > Ask + ReverseWhenToTrailLoss);
if (Order == OP_BUYLIMIT && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount) && (TradePerBar<=MaxTradePerBar)))) {
if (UseReverseStopLoss) ReverseStopLossLevel = Ask - ReverseStopLoss * (Point*1); else ReverseStopLoss = 0.0;
if (UseReverseTakeProfit) ReverseTakeProfitLevel = Ask + ReverseTakeProfit * (Point*1); else ReverseTakeProfitLevel = 0.0;
if(OrderMagicNumber () == MagicNumber)
if(OrderSymbol () == Symbol())
if(OrderLots () == LotsRO )
if(Bid-OrderOpenPrice () > ReverseWhenToTrail*(Point*1))
if(OrderStopLoss () < Bid-(Point*1)*ReverseTrailingStopLoss)
OrderModify(
OrderTicket(),
OrderOpenPrice(),
Bid - ((Point*1)*ReverseTrailingStopLoss),
OrderTakeProfit (),
0,
White);

Ticket = OrderSend(Symbol(), OP_BUYLIMIT, LotsRO, Bid, Slippage, ReverseStopLossLevel, ReverseTakeProfitLevel,"", MagicNumber, 0, Green);

Time0=Time[0];

if(Ticket>0)TradePerBar++;

if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("", OrderOpenPrice());
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}

if (!EachTickMode) BarCount = Bars;

return(0);
}
}
}

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

#### Tags for this Thread

forex, forex trading, mql, pips, profit, programming, stop, strategies, strategy, trading

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•