English

## How to set correct stoploss and takeproffit on BUYSTOP orders

 2 Algo-FX 2015.10.27 02:06   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: ```      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);```   for sellstop: ```      double priceSELL = NormalizeDouble(Bid -  BST       *xecn * Point, Digits);       double slSELL    = NormalizeDouble(Ask + (SL - BST) *xecn * Point, Digits);       double tpSELL    = NormalizeDouble(Ask - (TP + BST) *xecn * Point, Digits);           orderticket = OrderSend(Symbol(),OP_SELLSTOP ,lots, priceSELL, slippage, slSELL, tpSELL, "BuyStop", MagicNum, Time[0] + expr);```     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.09971-1.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
 126 Demos 2015.10.27 20:14 #   Algo-FX: 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.09971-1.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 Ask-Spread+(BST-SL), and vice versa for sell order  best regards