Trades closing with $0 earnings on loaded Break Even - page 2

 
Oh yeah and prior to doing this test, I did another print to get FreezeLevel *PipPoints and FreezeLevel *Point just to see what I would get as a result and both come out as 0.
 
LEHayes:
Oh yeah and prior to doing this test, I did another print to get FreezeLevel *PipPoints and FreezeLevel *Point just to see what I would get as a result and both come out as 0.

On IBFX Digits=5 freeze is normally 0 and stop is normally 30

You must set the buy stop to bid-MathMax(freeze,stop)*Point or lower.

 

Actrually the answer was tied to the distance issue. The issue was actually on the distance from teh current price. Basically, you can set any pip distance you want, but you have to wait until the current price is a specific distance from the point where you want to set the break even. I took out the FreezeLevel code and then made a modification to the if conditions that evaluate distances. Notice the two highlighted sections in the code below. Can't say I haven't contributed to this site, this was a pretty diamond in the rough.

CASE CLOSED

void TrailOrder()
{
   bool result;
   int error;
   double BreakEven = 0.0;

   RefreshRates();

   if (OrderType() == OP_BUY) {
      if (OrderStopLoss() == 0 || OrderStopLoss() < OrderOpenPrice()) {
         // Now the BreakEven
         if (BreakEvenSpread > 0)
         {
            BreakEven = OrderOpenPrice() + BreakEvenSpread*PipPoints;
            if (Bid > OrderOpenPrice() &&(Bid - 5*PipPoints) > BreakEven && BreakEven > OrderOpenPrice()) {
               if (BreakEven == OrderOpenPrice())
               {
                  BreakEven += 2*PipPoints;
               }
               if (EnableLog)
               {
                  Print("Placing a Buy mod for BE, OrderPrice is: ", DoubleToStr(OrderOpenPrice(),Digits), " BreakEven: ", DoubleToStr(BreakEven, Digits), " Current Price: ", DoubleToStr(Bid,Digits));
               }
               result = OrderModify(OrderTicket(), OrderOpenPrice(), BreakEven, OrderTakeProfit(), 0, Green);
               if (result!=True) {
                  error=GetLastError();
                  if (EnableLog)
                  {
                     Print("Failed to set BE on buy, BreakEven: ", DoubleToStr(BreakEven, Digits), " error: ", error);
                  }
               }
               else
               {
                 if (EnableLog)
                 {
                     Print("SUCCESS a Buy mod for BE, OrderPrice is: ", DoubleToStr(OrderOpenPrice(),Digits), " BreakEven: ", DoubleToStr(BreakEven, Digits), " Current Price: ", DoubleToStr(Bid,Digits));
                 }
               }
            }
         }
      } else {
         // Now the the trailing:
         if ((OrderStopLoss() == 0 || 
              Bid - OrderStopLoss() > PipPoints*TrailingStopPips) &&
             Bid - OrderOpenPrice() > PipPoints*StartTrailingAfterPips) {
            result = OrderModify(OrderTicket(), OrderOpenPrice(), Bid - PipPoints*TrailingStopPips, OrderTakeProfit(), 0, Green);
            if (result!=True) {
               error=GetLastError();
               if (EnableLog)
               {
                  Print("Failed to trail order on buy, error: ", error);
               }
            }
         }
      }
   }
   BreakEven = 0.0;
   if (OrderType() == OP_SELL) {
      if (OrderStopLoss() == 0 || OrderStopLoss() > OrderOpenPrice()) {
         if (BreakEvenSpread > 0)
         {
            BreakEven = OrderOpenPrice() - BreakEvenSpread*PipPoints;      
            if (Ask < OrderOpenPrice() &&(Ask + 5*PipPoints) < BreakEven && BreakEven < OrderOpenPrice()) {
               if (BreakEven == OrderOpenPrice())
               {
                  BreakEven -= 2*PipPoints;
               }       
               if (EnableLog)
               {
                  Print("Placing a sell mod for BE, OrderPrice is: ", DoubleToStr(OrderOpenPrice(),Digits), " BreakEven: ", DoubleToStr(BreakEven,Digits), " Current Price: ", DoubleToStr(Ask,Digits));
               }
               result = OrderModify(OrderTicket(), OrderOpenPrice(), BreakEven, OrderTakeProfit(), 0, Green);
               if (result!=True) {
                  error=GetLastError();
                  if (EnableLog)
                  {
                     Print("Failed to set Sell BE, BreakEven: ", DoubleToStr(BreakEven, Digits), " error: ", error);
                  }
               }
               else
               {
                  if (EnableLog)
                  {
                     Print("SUCCESS a Sell mod for BE, OrderPrice is: ", DoubleToStr(OrderOpenPrice(),Digits), " BreakEven: ", DoubleToStr(BreakEven, Digits), " Current Price: ", DoubleToStr(Ask,Digits));
                  }
               }
            }
         }
      }
      else
      {
         if ((OrderStopLoss() == 0 || 
              OrderStopLoss() - Ask > PipPoints*TrailingStopPips) &&
             OrderOpenPrice() - Ask > PipPoints*StartTrailingAfterPips) {
            result = OrderModify(OrderTicket(), OrderOpenPrice(), Ask + PipPoints * TrailingStopPips, OrderTakeProfit(), 0, Red);
            if (result!=True) {
               error=GetLastError();
               if (EnableLog)
               {
                  Print("Failed to trail order on Sell, error: ", error);
               }
            }
         }
      }
   }
}
Reason: