Make the take profit the range of the previous bar

 

I'm struggle to set my TP the range of the previous bar

I've manage to set my SL for a SEll trade above the previous bar range but i want to set my TP in the same way 

RISK TO REWARD WILL BE THEN A 1:1


Code for opening a sell position, but I'm not getting the Take profit section to work

Any advise ?

    {

      RefreshRates();

      price = Bid;

      SL = High[1] + 5 * myPoint; //Stop Loss = Candlestick High + fixed value

      TradeSize = MM_Size(SL - price);

      TP = (High[1] - Low[1]) ; //Take Profit = Candlestick Range 

      if(!TradeDayOfWeek()) return; //open trades only on specific days of the week   

      if(IsTradeAllowed())

        {

         ticket = myOrderSend(OP_SELL, price, TradeSize, "");

         if(ticket <= 0) return;

        }

      else //not autotrading => only send alert

         myAlert("order", "");

      myOrderModify(ticket, SL, 0);

      myOrderModify(ticket, 0, TP);

     }

  }

Extract profit down to the last pip
Extract profit down to the last pip
  • www.mql5.com
The article describes an attempt to combine theory with practice in the algorithmic trading field. Most of discussions concerning the creation of Trading Systems is connected with the use of historic bars and various indicators applied thereon. This is the most well covered field and thus we will not consider it. Bars represent a very artificial entity; therefore we will work with something closer to proto-data, namely the price ticks.
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  3. Your risk is SL-price. Your TP is therefor Ask - risk.