

AlgoFX: When i do the math for the buystop order, I get a stop loss of 319pips (1.099711.09652) and take profit of 281 pips (1.10252  1.09971),



AlgoFX: An example order from testing is as follows: 2015.10.26 15:20:09.493 2015.07.23 09:00 TriangleTS v3.1EURUSD,M30: open #25 buy stop 0.10 EURUSD at 1.09971 sl: 1.09652 tp:1.10252 ok 2015.10.26 15:20:09.493 2015.07.23 09:00 TriangleTS v3.1EURUSD,M30: open #26 sell stop 0.10 EURUSD at 1.09752 sl: 1.10071 tp:1.09471 ok When i do the math for the buystop order, I get a stop loss of 319pips (1.099711.09652) and take profit of 281 pips (1.10252  1.09971),when I am expecting them both to be 300.
Should I be using Ask to calculate my stop loss and take profit?? double priceBUY = NormalizeDouble(Ask + BST *xecn * Point, Digits); double slBUY = NormalizeDouble(Bid + (BST  SL) *xecn * Point, Digits); double tpBUY = NormalizeDouble(Bid + (TP + BST) *xecn * Point, Digits); orderticket = OrderSend(Symbol(),OP_BUYSTOP ,lots, priceBUY, slippage, slBUY, tpBUY, "BuyStop", MagicNum, Time[0] + expr);
Hello, As you imagine, the problem lies in the fact that you are using Bid price for calculating slBUY and tpBUY in your buy order. In OrderSend() you are simply passing a number, so in fact you are doing AskSpread+(BSTSL), and vice versa for sell order
best regards


AlgoFX: My question is why is it not 30 pips when I entered with a stop loss of 30 and a take profit of 30, what am I doing wrong in my code that I am always off by the spread? You buy at the Ask and sell at th Bid. On a buy order, you pay the spread on open. On a sell order you pay the spread on close. Your buy order is the open=Ask and SL is Bid  30 pips (close price  30 pips,) so the difference is 30 pips + spread. On sell orders open=Bid and SL is Ask + 30 pips (close price + 30 pips.) Both of these means the 30 pips does not include the spread. If you want the 30 pips to include the spread use the open price only in your calculation, not the close price. 
I am writing an EA to place buystop and sellstop orders, everything works great but I do not think I am calculating the sl and tp values correctly in my code.
in the code:
BST = 10
SL = 30
TP = 30
xecn = 10
the broker uses a 5 digit quote and spread is 19
here is the code for buystop:
for sellstop:
An example order from testing is as follows:
2015.10.26 15:20:09.493 2015.07.23 09:00 TriangleTS v3.1 EURUSD,M30: open #25 buy stop 0.10 EURUSD at 1.09971 sl: 1.09652 tp: 1.10252 ok
2015.10.26 15:20:09.493 2015.07.23 09:00 TriangleTS v3.1 EURUSD,M30: open #26 sell stop 0.10 EURUSD at 1.09752 sl: 1.10071 tp: 1.09471 ok
When i do the math for the buystop order, I get a stop loss of 319 pips (1.099711.09652) and take profit of 281 pips (1.10252  1.09971), when I am expecting them both to be 300.
Should I be using Ask to calculate my stop loss and take profit??
please help this very confused new guy