• Join us

How to trade with the smallest stop-loss

To add comments, please log in or register

Hi, in the particular trade I'm creating I want to open a position with the smallest stop-loss that my broker will allow.

I've modified some code I found on these forums but it's still not working right and I'm not sure what I'm doing wrong.

Here's a snippet of my code:

if (type == POSITION_TYPE_BUY)
   currentPrice = State.Symbol.Ask();
   slPriceLimit = currentPrice-MathMax(SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL),SymbolInfoInteger(Symbol(),SYMBOL_TRADE_FREEZE_LEVEL))*Point();
   currentPrice = State.Symbol.Bid();
   slPriceLimit = currentPrice+MathMax(SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL),SymbolInfoInteger(Symbol(),SYMBOL_TRADE_FREEZE_LEVEL))*Point();

Now, my broker publishes the SYMBOL_TRADE_STOPS_LEVEL with a value of 40 and as a result, when opening a BUY position on EURUSD, the stop-loss is 0.0004 below the ASK price.

My problem is that sometimes this stop-loss still results in a failed trade.  Here's a sample from my journal:

Lot = 3.18000000
Symbol = EURUSD
Ask = 1.14844000
Bid = 1.14827000
StopLoss = 1.14804000
TakeProfit = 0.00000000
failed market buy 3.18 EURUSD sl: 1.14804 [Invalid stops]
CTrade::OrderSend: market buy 3.18 EURUSD sl: 1.14804 [invalid stops]
ERROR: method Buy returned the code: 10016, message: invalid stops

My question is, should I change my code or my broker?

Enrique Dangeroux
Enrique Dangeroux  
Change broker. Stop level >0 is not from this time of age for quite some time.
To add comments, please log in or register