Download MetaTrader 5
To add comments, please log in or register
Publish your article and thousands of people all over the world will read it!
moonsboy
889
moonsboy 2015.01.04 05:09 
When using OrderModify() to set the values of "takeprofit" and "stoploss", should I suppose the "takeprofit" or the "stoploss" is an Ask price or a Bid price for an existing long and short orders respectively?
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2015.01.04 05:35  

Takeprofit for Long (Buy) = Ask + takeprofit

Stoploss = Ask - stoploss


Takeprofit for Sell (Short) = Bid - takeprofit

Stoploss = Bid + stoploss


Notice the + - and work from there. This is the example.

moonsboy
889
moonsboy 2015.01.04 05:59  

Thanks, Deysmacro.

Therefore, if order '1' is an existing short position, I should use below codes. Correct?

If(target<Ask) OrderModify(1, OrderOpenPrice(),0,target,0);
whroeder1
13627
whroeder1 2015.01.04 15:18  
jollydragon: values of "takeprofit" and "stoploss", should I suppose the "takeprofit" or the "stoploss" is an Ask price or a Bid price for an existing long and short orders respectively?
  1. You buy at the Ask and Sell at the Bid. So for a Buy order the TP/SL trigger when the Bid reaches the value. For Sells when the Ask reaches the value.
  2. deysmacro:

    Takeprofit for Long (Buy) = Ask + takeprofit

    Stoploss = Ask - stoploss


    Takeprofit for Sell (Short) = Bid - takeprofit

    Stoploss = Bid + stoploss

    deysmacro's post assumes that

    • There was no slippage.
    • The takeprofit does not include the spread (a takeprofit of zero results in the order being closed at the OrderOpenPrice for zero profit.
    • The stoploss does include the spread (if stoploss is less than the spread it fails.)

  3. My code converts the OrderOpenPrice to a Bid price (subtract spread only for buy orders) Add or subtracts distance+spread. Then convert the Bid price to a Stop price (add spread only for sell orders.)  Distance+spread must be at least MODE_STOPLEVEL.

    If you are using a chart price (lowest low/highest high) then for a sell order only, you must add the spread. Chart prices are Bid prices, sells close at the Ask.

whroeder1
13627
whroeder1 2015.01.04 20:20  
jollydragon: Therefore, if order '1' is an existing short position, I should use below codes. Correct?
If your network goes down you never close the order. Why aren't you setting the TP in the OrderSend?
moonsboy
889
moonsboy 2015.01.05 02:38  
WHRoeder:
If your network goes down you never close the order. Why aren't you setting the TP in the OrderSend?

Dear WHRoeder,  

What do you mean with "network goes down"?

 You know my code will modify the takeprofit based on lastest market price. Just set takeprofit based on 'Ask' as it's a short order. 

whroeder1
13627
whroeder1 2015.01.05 16:06  
jollydragon: What do you mean with "network goes down"? You know my code will modify the takeprofit based on lastest market price. Just set takeprofit based on 'Ask' as it's a short order. 
  1. PC shutsdown, Airplane mode activated, loose connection, modem dies, lightning strike takes out one of your ISPs repeaters, someone starts digging and cut's their wire: Network goes down!
  2. I know that your code will do NOTHING, if it doesn't get any ticks or can't send a message to your broker.
  3. The point of TP and SL is that they function on the broker's server. You will be taken out of the order. Don't set a SL and you risk your entire account (up to the margin call.)
/
To add comments, please log in or register