Needed help coding a trailing takeprofit - page 2

 
Alain Verleyen:

If you want precision (exact breakeven) and broker side exit, it's almost impossible if you mix buys and sells orders. As it will depends of the spread and the spread can change on each tick, in theory it' s possible to change SL/TP for several orders on each tick, but in practice it will not work. You will need some compromise.

A remark about you TP at breakeven, that doesn't make much sense, the stoploss should be used in your case, unless I misunderstood something in your requirements.

Brian Lillard:

Say for example, if there were a mix of buy and sell orders, worst case scenario, some orders were activated limit orders and others market orders: suppose you just add up commission/swap/any other fees and current profits & losses and incremented them by points in a loop to ultimately place the exit/target price to close when the price was at a breakeven point. For as far as a formula I haven't a clue what would have the kind of accuracy counting point by point -- and I think it may be that the breakeven will be overshot to a profit versus a loss, anyways.

I wrote a code that logs the breakeven price when it occurred, and it closes all orders when the target was within the target plus a slippage point value of the exit/target price, but this is not good enough for me - as possibly having many orders to fill takes time and costs money which is why I am opting for a broker side exit.

The end result should be either a breakeven or a profit because I think the slippage point value variable should be added to the breakeven price.

Is there really any difference between stoploss and takeprofit? Both may be jumped and nothing happen and both may be selected from either side.

A stop marks your risk, take profit marks your reward. Stop loss is trailed into profit and take profit is trailed into loss and that's just how I see it.

 
Brian Lillard:

The end result would be either a breakeven or a profit because I think the slippage point value variable should be added to the breakeven price.

Is there really any difference between stoploss and takeprofit? Both may be jumped and nothing happen and both may be selected from either side.

A stop marks your risk, take profit marks your reward. Stop loss is trailed into profit and take profit is trailed into loss and that's just how I see it.

Slippage has nothing to do here, you can't know slippage by advance.

Yes you can use takeprofit() to breakeven if you want. I just don't see the goal to do that. It can only be used if you are in loss, and you want to stop when you finally come to profit area ? Weird to me.

 

 
Alain Verleyen:

Slippage has nothing to do here, you can't know slippage by advance.

Yes you can use takeprofit() to breakeven if you want. I just don't see the goal to do that. It can only be used if you are in loss, and you want to stop when you finally come to profit area ? Weird to me.

Slippage, would be compensated at breakeven so profits occur. Does spread have any anything to do with it? Activated limit orders confuse me regarding slippage but just because they close opposite price as regular market orders -- doesn't mean they are much different as once they are in motion they can be calculated to a specific exit.

Reason: