I am trying to calculate a stop loss in Metatrader 4. I came across this example on their site. The example creates an order at the ASK price, but sets the stoploss and takeprofit based on the BID price. Why is everything not based on the ASK price?
I think you're flummoxed by the purpose of the bid and ask quotes. In general terms when you buy a security using a market order, you buy from the lowest ask price, and when you sell a security using a market order, you sell to the highest bidder.
For what you're working on you're setting up a buy with a stop out sell order. You will create your buy order using the current ask quote and set a stop loss sell order based on some function of the current bid price.
For these sorts of formulaic trades you need to be cognizant of the bid/ask spread so it makes sense to generate the orders based on the corresponding quote.