Trailing Stop Orders

Created at 22 Nov 2018, 23:48
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
97

9718853

Joined 14.10.2014

Trailing Stop Orders
22 Nov 2018, 23:48


Hi,

I'm placing some orders upon a criteria set by Market.Series High or Low...

I wish to trail these StopOrders so that they trail the Bid/Ask by a fixed distance as calculated by the distance between the marketSeries High and Low...

However, the distance will be different for each set of orders as they respect the current High and Low...

Once the price action moves the MarketSeries High and Low will change so I have no reference to trail the orders with...

In your Sample Trailing Stop Loss you have the index of _highestGain = Positions[0].Pips; for Positions... But I can't see any way to apply this to PendingOrders...

Is it possible to index the distance of PendingOrders?

Many thanks,

Ian...


@9718853
Replies

PanagiotisCharalampous
23 Nov 2018, 10:51

Hi Ian,

I am not sure I understand your question. You can use an index with PendingOrders, if this is what you ask. If you want to find the distance from the current price to the order, then you need to use the Target Price. See below

PendingOrders[0].TargetPrice

Let me know if this is what you were looking for.

Best Regards,

Panagiotis


@PanagiotisCharalampous

9718853
23 Nov 2018, 13:01

Hi Panagiotis,

Thank you for you reply...

I'm trying to trail Stop orders behind the Bid/Ask price by a cosistant distance...

This is easy if I use a parameter eg var newTargetPrice = Symbol.Bid + X pips * Symbol.Pipsize

However, I'm using the MarketSeries High/Low to determine 'X' which is the current range of pips between the current High and Low...

Somehow I need my cBot to remember and refer to this range so that the orders can trail at a consitent distance while the MarketSeries High / Low fluctuates...

Is this possible with PendingOrders[0].TargetPrice?

Many Thanks, 

Ian


@9718853

PanagiotisCharalampous
23 Nov 2018, 14:07

Hi Ian,

Yes you can. Just use ModifyPendingOrder to set the new target price each time the price is recalculated.

Best Regards,

Panagiotis


@PanagiotisCharalampous

9718853
23 Nov 2018, 15:57

Sorry Panagiotis, could you please offer an example of how to correectly use PendingOrders[0].TargetPrice 

How do I compare the PendingOrders[0].TargetPrice price to the Bid/Ask price ? 

My appologies, usually I can work these things out by looking at sample code but this one has me stumped!

Many thanks,

Ian


@9718853

PanagiotisCharalampous
23 Nov 2018, 17:26

Hi Ian,

I am not sure what kind of example you need. PendingOrder.TargetPrice is the price at which the order is set to trigger. If you need to modify it so that the order trails the price fluctuation, you will use ModifyPendingOrder to change the target price. Let me know a simple scenario you wish to see programmed so that I can provide with a sample code.

Best Regards,

Panagiotis


@PanagiotisCharalampous