Buy on Takeprofit and reverse on Stop Loss

 

Hi,
I had an idea for a trading strategy and wanted to code it or maybe it exist already?

Idea:

  1. Start buy order with 50 take profit points and 25 stop loss points
  2. If trade runs into take profit => reopen the same order again (50TP/25SL)
  3. If trade runs into stop loss => reopen order but in reverse.
    It becomes a sell order with 50TP and 25 SL in this example.

Anyone knows if it exist already? Or giving starting hints?

I'm trying to start with this code for now but it's not complete yet:


#include<Trade\Trade.mqh>

CTrade trade;
string direction = "buy";
input int TakeProfitPoints = 50;
input int StopLossPoints = 25;
input double BuySize = 0.10;
input double SellSize = 0.10;

void OnTick()
  {
  double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
  double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
  
  
      if ((PositionsTotal() == 0) && (direction == "buy")) {
       trade.Buy(BuySize,_Symbol,Ask,(Ask-StopLossPoints * _Point),(Ask+TakeProfitPoints * _Point),NULL);
       direction = "sell";
      }
     
      if ((PositionsTotal() == 0) && (direction == "sell")) {
       trade.Sell(SellSize,_Symbol,Bid,(Bid+StopLossPoints * _Point),(Bid-TakeProfitPoints * _Point), NULL);
       direction = "buy";
      }
     
     Comment ("Current direction is: ", direction);
  }


Thanks a lot.

 
ImmerLong:

Hi,
I had an idea for a trading strategy and wanted to code it or maybe it exist already?

It is such a common strategy I am sure that it exists somewhere.

If trade runs into take profit => reopen the same order again (50TP/25SL)

Why not leave the trade open with a 25 pip trailing SL?

 
Keith Watford #:

It is such a common strategy I am sure that it exists somewhere.

If trade runs into take profit => reopen the same order again (50TP/25SL)

Why not leave the trade open with a 25 pip trailing SL?

Thanks for your reply!

Why not leave the trade open with a 25 pip trailing SL?

Technically it works too, even though I would then want to work additionally with a break even on top. 

I just thought for the beginning TP and SL is easier than TSL.

 
ImmerLong #Why not leave the trade open with a 25 pip trailing SL?

Technically it works too, even though I would then want to work additionally with a break even on top. I just thought for the beginning TP and SL is easier than TSL.

If you close the position, only to reopen it again, you end up paying double the commission and the spread.

Just keep track of the new "virtual" Open-price for break-even calculations, and set a new Stop-loss set relative to the new "virtual" open-price.

 
As for reversing on a stop-loss, consider using "Close-By" functionality, that in many cases will save you on transaction costs. Some brokers support it and others not.
Reason: