Trades closing with $0 earnings on loaded Break Even

 

So I created a loaded break even:

For a long:

BreakEven = OrderOpenPrice() + (MarketInfo(Symbol(),MODE_FREEZELEVEL)*PipPoints + BreakEvenSpread*PipPoints)*PipPoints;

For a Short:

BreakEven = OrderOpenPrice() - (BreakEvenSpread*PipPoints + MarketInfo(Symbol(),MODE_FREEZELEVEL)*PipPoints)*PipPoints;

I call it loaded because of the BreakEvenSpread. This forces my breakevens to actually close a few pips to the positive on the trade. Now an interesting thing is happening. Regardless of whether I set this value to 2pips, 5pips, or 7pips, I still get trades that are closing with a $0.00 earning. According to the above values that would not be possible. Unless the brokers where up to something. Any ideas?

I have attached a detailed statement so you can see the trades. Providing a pic of it as well.


$0.00 earnings

 
BreakEven = OrderOpenPrice() + (MarketInfo(Symbol(),MODE_FREEZELEVEL)*PipPoints + BreakEvenSpread*PipPoints)*PipPoints;


dont you think you have too many *PipPoints ?

 
LEHayes wrote >>

So I created a loaded break even:

For a long:

For a Short:

I call it loaded because of the BreakEvenSpread. This forces my breakevens to actually close a few pips to the positive on the trade. Now an interesting thing is happening. Regardless of whether I set this value to 2pips, 5pips, or 7pips, I still get trades that are closing with a $0.00 earning. According to the above values that would not be possible. Unless the brokers where up to something. Any ideas?

I have attached a detailed statement so you can see the trades. Providing a pic of it as well.


$0.00 earnings

Hi

try this, it works perfect for Breakeven

where you see red 0 in BOLD, write your number of pips

------------------------

void MoveBreakEven()
{
int cnt,total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(BreakEven>0)
{
if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*Point)
{
if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),Digits)<0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+0*Point,Digits),OrderTakeProfit(),0,Blue);
return(0);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*Point)
{
if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),Digits)<0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-0*Point,Digits),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
}

 
MarketInfo(Symbol(),MODE_FREEZELEVEL)*PipPoints

The unit for freezelevel and MODE_STOPLEVEL are points not pips.

On IBFX Digits=5 freeze=0 stoplevel=30

 
samirgham wrote >>

Hi

try this, it works perfect for Breakeven

where you see red 0 in BOLD, write your number of pips

------------------------

void MoveBreakEven()
{
int cnt,total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(BreakEven>0)
{
if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*Point)
{
if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),Digits)<0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+0*Point,Digits),OrderTakeProfit(),0,Blue);
return(0);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*Point)
{
if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),Digits)<0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-0*Point,Digits),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
}

I sent you a private message. Thank you for your time.

 
LEHayes wrote >>

I sent you a private message. Thank you for your time.

Hi

i answered

 
samirgham wrote >>

Hi

try this, it works perfect for Breakeven

where you see red 0 in BOLD, write your number of pips

------------------------

void MoveBreakEven()
{
int cnt,total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(BreakEven>0)
{
if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*Point)
{
if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),Digits)<0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+0*Point,Digits),OrderTakeProfit(),0,Blue);
return(0);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*Point)
{
if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),Digits)<0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-0*Point,Digits),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
}

Thank you on this, but your code already contains the conditionals that I have incorporated into mine.

It would seem that we are talking apples and oranges. The break even doesn't move, you just set it. It is a safety barrier to prevent taking losses, instead closing at a positive. I do have a trailing stop loss but mine is far more complicated than what you are showing me. Mine has 2 targets the first target is the point that the currency pair must run to before setting the trailing stop loss x pips behind it. Then I have a break even that I want to place just inside the positive range. as I said a safety barrier. meanwhile we wait for the currency pair to run to money in the trailing stop loss, once the trailing stop loss commitments have hit, then the break even is no longer needed.

Still this is not my problem, my problem is that even though I set the BreakEven = OpenPrice()+FreezeLevel+BreakEvenSpread. the user provides the BreakEvenSpread, which means it could go from freezeLevel to upwards of 10, 20, 100 pips away, whatever the user sets. The problem is that no matter what the user set, I have used 2, 4, 5, 7, 10, we still get closing values of $0.00. Logically, this should not be happening. Now my question is WHY IS IT HAPPENING?

If I take open price of 1.4545 and I add 0 (freezeLevel) and BreakEvenSpread of say 5 pips, that should at least be 1.4550, which is 5 pips above entry, assuming a long. Now let's assumge we have a freezeLevel, 1.4545 + freezelevel of 5, + spread of 5. we now have 1.4555, still not explanation of why we are getting these kind of results of 0.00.

sorry if I sound curt with you, it is just I am tired of getting run arounds on this and no one seems to know the real answer as to why there is such funny math in automation trading, such that no matter the spread added it still seems to equal the open price. Brokers blame MT4, MT4 blames the developers and yet we know that it's BS as developers. I have more than 20 tests running right now that can prove this situation. With that being the case, how can it be magic numbers that are creating this illussive 0.00?

I am going to add this to the forum link, I think this needs to come to the surface.

 

Here is some of my code snippet to explain what I am doing. Note that I have a stop loss, a trailing stop loss, and a break even. The trailing stop loss has a higher number that the currency pair must reach before it can trigger the lower number trailing stop loss. An example of the trailing stop loss is 20,10 where it waits for price to reach 20 pips before setting a 10 pip stop loss. Meanwhile, as the currency price reaches the trailing stop loss, it has to cross the boundary of the break even, at which point it is buffered to not only take into consideration the freezelevel, but also the breakevenspread which should place the break even mark clearly above or below the open price, depending on whether it is a buy or a sell. So here is the snippet...

First at the beginning of the program outside of the candle open processes we call the trailing procedures which store stop loss, trailing stop loss, and break even actions, result is that it is called on every tick.

int start()
{

//....
   DoTrailingStops();

}

void DoTrailingStops() {
   if(StartTrailingAfterPips*Point == 0) // optional trailing stop check
      return;

   int total = OrdersTotal();   // loop through the open trades
   for(int i = 0; i <= total; i++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()) {
         TrailOrder();  // call the method that actually performs the work.
      }
   }
}

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

   RefreshRates();  //force a refresh rate before we begin

   if (OrderType() == OP_BUY) { // we are on a buy trade
      if (OrderStopLoss() == 0 || OrderStopLoss() < OrderOpenPrice()) {  // the stop loss is either 0 because not
         // Now the BreakEven                                               set or less than price because stop
                                                                         // loss is set to stop the bleeding

         // Here we get the break even point buffering it by the freezelevel and the user provided Spread, 
         // to ensure we are safely away from the open price.
         BreakEven = OrderOpenPrice() + (MarketInfo(Symbol(),MODE_FREEZELEVEL)*PipPoints + BreakEvenSpread*PipPoints)*PipPoints;
         // confirm that the current price is greater than the open price and the break even price
         if (Bid > OrderOpenPrice() && Bid > BreakEven && BreakEven > OrderOpenPrice() + (MarketInfo(Symbol(),MODE_FREEZELEVEL)*PipPoints)) {
            // we are getting a lot of closures where the earnings is $0.00, so let's confirm that breakeven is
            // equal to the open price, if so, then we will add a couple of pips to force it above the breakeven
            if (BreakEven == OrderOpenPrice())
            {
               BreakEven += 2*PipPoints;
            }
            //place the order.
            result = OrderModify(OrderTicket(), OrderOpenPrice(), BreakEven, OrderTakeProfit(), 0, Green);
            // check for errors, we get frequent 130 errors on break evens.  But it does eventually place the order
            if (result!=True) {
               error=GetLastError();
               Print("Failed to set BE on buy, BreakEven: ", DoubleToStr(BreakEven, Digits), " error: ", error);
            }
         }
      } else {
         // Now the the trailing stop loss, this will overwrite the breakeven if the values meet trailing 
         // stop criteria:
         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();
               Print("Failed to trail order on buy, error: ", error);
            }
         }
      }
   }
   // resetting the BreakEven values for the sell play instead of the buy play.
   // performing the same tasks in sell just changing the addition/subtraction for reverse of direction
   BreakEven = 0.0;
   if (OrderType() == OP_SELL) {  // confirm this is a sell 
      if (OrderStopLoss() == 0 || OrderStopLoss() > OrderOpenPrice()) {
         BreakEven = OrderOpenPrice() - (BreakEvenSpread*PipPoints + MarketInfo(Symbol(),MODE_FREEZELEVEL)*PipPoints)*PipPoints;      
         if (Ask < OrderOpenPrice() && Ask < BreakEven && BreakEven < OrderOpenPrice() - (MarketInfo(Symbol(),MODE_FREEZELEVEL)*PipPoints)) {
            if (BreakEven == OrderOpenPrice())
            {
               BreakEven -= 2*PipPoints;
            }         
            result = OrderModify(OrderTicket(), OrderOpenPrice(), BreakEven, OrderTakeProfit(), 0, Green);
            if (result!=True) {
               error=GetLastError();
               Print("Failed to set Sell BE, BreakEven: ", DoubleToStr(BreakEven, Digits), " error: ", error);
            }
         }
      }
      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();
               Print("Failed to trail order on Sell, error: ", error);
            }
         }
      }
   }
}

earit was mentioned that freezeLevel was a point not a pip, by,ultiplying it against pippoints, it becomes a pip value as does the breakevenspread. Regardless, this does not explain the fact that a person can change the spread value and still get the same result of $0.00.

So, unless someone can explain where my code is causing the 0.00, I would like an explanation of how MT4 or the brokers can come up with $0.00 when breakeven is obviously boosted to be greater than or less than open price based on the direction of the trade.

 
LEHayes wrote >>

Here is some of my code snippet to explain what I am doing. Note that I have a stop loss, a trailing stop loss, and a break even. The trailing stop loss has a higher number that the currency pair must reach before it can trigger the lower number trailing stop loss. An example of the trailing stop loss is 20,10 where it waits for price to reach 20 pips before setting a 10 pip stop loss. Meanwhile, as the currency price reaches the trailing stop loss, it has to cross the boundary of the break even, at which point it is buffered to not only take into consideration the freezelevel, but also the breakevenspread which should place the break even mark clearly above or below the open price, depending on whether it is a buy or a sell. So here is the snippet...

First at the beginning of the program outside of the candle open processes we call the trailing procedures which store stop loss, trailing stop loss, and break even actions, result is that it is called on every tick.

earit was mentioned that freezeLevel was a point not a pip, by,ultiplying it against pippoints, it becomes a pip value as does the breakevenspread. Regardless, this does not explain the fact that a person can change the spread value and still get the same result of $0.00.

So, unless someone can explain where my code is causing the 0.00, I would like an explanation of how MT4 or the brokers can come up with $0.00 when breakeven is obviously boosted to be greater than or less than open price based on the direction of the trade.

Yes, it is totally different as what i understood from the begining.

Sorry for losing your time in trying.

Hope you will arrive to a point and fix it.

Regards,

Samir

 
samirgham wrote >>

Yes, it is totally different as what i understood from the begining.

Sorry for losing your time in trying.

Hope you will arrive to a point and fix it.

Regards,

Samir

No problem, thank you for the help. I have been at this night and day trying to resolve it. I am sorry if I appear short or ru de about it.

 
There is nothing that bugs me more than an unsolved mystery, so I tried some more testing.
I took out the FreezeLevel entry, I then entered a print statement before each attempt to modify and in the if error, I added an else with a print for success. The end result is that in a scenario where BESpread was 3, the BE would actually generate a 130 error until the following:
Buy: Current Price was 9 pips above Open Price or Open Price was 6 pips above the BE
Sell: Current Price was 10 pips below Open Price or Current Price was 7 pips below BE.
Now this could mean that there is a min range around the current price Where the current price has to be X away from modified Stop Loss value in order to be accepted, or that Current Price must be X amount of pips away from Open Price, not sure which.
does this shed any light on the subject?
Here are the prints I got:
Buy:
2009.10.28 05:23:36 BBW_Scalp_v3_8_1_cli CADJPY,H1: SUCCESS a Buy mod for BE, OrderPrice is: 84.89 BreakEven: 84.92 Current Price: 84.98
2009.10.28 05:23:36 BBW_Scalp_v3_8_1_cli CADJPY,H1: modify #1239228 buy 0.46 CADJPY at 84.89 sl: 84.92 tp: 86.89 ok
Sell: (Ignore the "Buy" text, I was tired, it was late)
2009.10.28 05:30:42 BBW_Scalp_v3_8_1_cli EURJPY,M1: SUCCESS a Buy mod for BE, OrderPrice is: 134.76 BreakEven: 134.73 Current Price: 134.66
2009.10.28 05:30:42 BBW_Scalp_v3_8_1_cli EURJPY,M1: modify #1239226 sell 0.46 EURJPY at 134.76 sl: 134.73 tp: 132.76 ok
2009.10.28 05:30:41 BBW_Scalp_v3_8_1_cli EURJPY,M1: Placing a sell mod for BE, OrderPrice is: 134.76 BreakEven: 134.73 Current Price: 134.66
Reason: