Set Take Profit Relative To Stop Loss (Risk:Reward Ratio)

To add comments, please log in or register
95jlenk
54
95jlenk  
I've been struggling to solve this. Based on what I saw I should use OrderSelect() but have been unsuccessful. See "SL" and "TP" below. SL works everytime because it is set to the low of the previous candle, however I'm trying to base the TP off of the SL to have the Risk:Reward ratio of my liking (1:2 currently).

Can someone more experienced point me in the right direction?

I used an EAbuilder but it doesn't have everything I want/need (like ObjectGetDouble) so I've been trying to learn a little coding. This is my first real challenge that I've been struggling to get through.

//Open Buy Order
   if(iLow(NULL, PERIOD_CURRENT, 1) < ObjectGetDouble(0,"SLCbp",1,0)
   && iClose(NULL, PERIOD_CURRENT, 1) > ObjectGetDouble(0,"SLCbp",1,0)
   && iLow(NULL, PERIOD_CURRENT, 1) < iLow(NULL, PERIOD_CURRENT, 2)
   && iLow(NULL, PERIOD_CURRENT, 1) < iLow(NULL, PERIOD_CURRENT, 3)
   && (((MathAbs(iOpen(NULL, PERIOD_CURRENT, 1) - iClose(NULL, PERIOD_CURRENT, 1)))/(iHigh(NULL, PERIOD_CURRENT,1) - iLow(NULL, PERIOD_CURRENT, 1))) < (maxBMIpercent/100))
   && (ObjectDescription("S.L.Clus#grbpv") >= 2.0)
   && (ObjectDescription("S.L.Clus#grbpv") < 9.0)
   )
     {
      RefreshRates();
      price = Ask;
      SL = iLow(NULL, PERIOD_CURRENT, 1); //Stop Loss = Candlestick Low
      if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES) == True)
      {
      TP = OrderOpenPrice() + ((OrderOpenPrice() - iLow(NULL, PERIOD_CURRENT, 1)) + (OrderOpenPrice() - iLow(NULL, PERIOD_CURRENT, 1)));
      }
      if(price - SL < MinSL) SL = price - MinSL;
      TradeSize = MM_Size(price - SL);
      if(TimeCurrent() - LastTradeTime < NextOpenTradeAfterMinutes * 60) return; //next open trade after time   
      if(IsTradeAllowed())
        {
         ticket = myOrderSend(OP_BUY, price, TradeSize, "");
         if(ticket <= 0) return;
        }
      else //not autotrading => only send alert
         myAlert("order", "");
      LastTradeTime = TimeCurrent();
      myOrderModify(ticket, SL, 0);
      myOrderModify(ticket, 0, TP);
     }
To add comments, please log in or register