Bizarre uneven takeprofit and stoploss
7 cents commission?
Keith Watford:
7 cents commission?
7 cents commission?
You know what - I think you're right. That makes sense on what the broker charges. I hadn't figured on that. Dammit!
Thanks for your help though :) Much appreciated
-

Play videoPlease edit your post.
For large amounts of code, attach it - int LotDigits = (int) - MathLog10(SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP));
double LotSize=NormalizeDouble(Lots,LotDigits);
double TakeProfit = NormalizeDouble(Bid-trade_size,Digits);
double StopLoss = NormalizeDouble(Bid+trade_size,Digits);;Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrongLotDigits also fails when not a power of 1/10. (int) MathCeil(-MathLog10(...)) will work.- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
You also aren't getting a 1:1 RRR. For a buy your SL includes the spread (buy at the Ask, close at Bid,) your TP does not (buy at the Ask, close at the Ask-spread i.e. Bid.) For a sell your SL doesn't include the spread (sell at the Bid, close at the Bid-spread i.e. Ask,) same for TP. Your code Simplified if(Ticket>=0)
{
return(true);
}
return(false);return Ticket>=0;
Hi All,
I've been trying to ensure that my takeprofit and stoploss are equal (in other words, profits and losses should be of the same magnitude). I've done a bit of investigating and tried a few solutions but I still get uneven profits and losses - even though looking at the prices in the results tab it they should be equal. Here's the code I used to execute the trades:
double trade_size = 0.0003;
bool OpenBuy()
{
//Get new market prices
RefreshRates();
//Define lot size
double Lots = 0.01;
int LotDigits = (int) - MathLog10(SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP));
double LotSize=NormalizeDouble(Lots,LotDigits);
//Calculate and check spread
double MaxSpreadInPoints = 50;
double Spread = Ask - Bid;
if(Spread>MaxSpreadInPoints)
return(false);
//Define allowed slippage
int SlippageInPoints = 0;
//Define TakeProfit and StopLoss levels
double TakeProfit = NormalizeDouble(Bid+Spread+trade_size,Digits);
double StopLoss = NormalizeDouble(Bid+Spread-trade_size,Digits);;
int Ticket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,SlippageInPoints,StopLoss,TakeProfit,"Spread Test",13,0,Green);
if(Ticket==-1)
{
Alert("Buy Error: " ,GetLastError());
return(false);
}
if(Ticket>=0)
{
return(true);
}
return(false);
}
bool OpenSell()
{
//Get new market prices
RefreshRates();
//Define lot size
double Lots = 0.01;
int LotDigits = (int) - MathLog10(SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP));
double LotSize=NormalizeDouble(Lots,LotDigits);
//Calculate and check spread
double MaxSpreadInPoints = 50;
double Spread = Ask - Bid;
if(Spread>MaxSpreadInPoints)
return(false);
//Define allowed slippage
int SlippageInPoints = 0;
//Define TakeProfit and StopLoss levels
double TakeProfit = NormalizeDouble(Bid-trade_size,Digits);
double StopLoss = NormalizeDouble(Bid+trade_size,Digits);;
int Ticket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,SlippageInPoints,StopLoss,TakeProfit,"Spread Test",13,0,Red);
if(Ticket==-1)
{
Alert("Sell Error: " ,GetLastError());
return(false);
}
if(Ticket>=0)
{
return(true);
}
return(false);
}
and here are some of the resulting trades:
As you can see the profit is always 23 cents and the loss is always 37 cents. I've been wracking my brain to figure out what is going on but I can't figure it out. Am I missing something obvious to do with the bid/ask spread?
Any help would be greatly appreciated.