Dukascopy
 
 
Wiki JStore Search Login

Specific Trailing Stop
 Post subject: Specific Trailing Stop Post rating: 0   New post Posted: Sat 13 Apr, 2013, 02:18 

User rating: 0
Joined: Fri 12 Apr, 2013, 00:05
Posts: 13
Location: United KingdomUnited Kingdom
Hello there!


I am looking for a specific Trailing Stop Robot, which I haven't seen on this forum.

First of all, it is an Instant trailing stop. Instant trailing stop is the one, which after being triggered, instantly follow the price by a particular number of pips.

Also, it has to be managed in 3 stages.


Example:

Start trailing at: 20 pips

Distance of instant trailing stop: 4 pips

When +28 pips will be reached - increase ts distance to 8 pips

And finally, when let say +36 pips reached - incease ts distance to 16 pips and keep running till it will be closed by TP or TS.


>>>>

Different strategies require different settings, but are traded on the same pair at the same time.

On my MT4 Position Manager I had an option to "Manage trades by the comment or magic number".

I haven't seen a possibility to add comments or magic numbers here on JForex. Maybe there is but I didn't find?

If there is no - could you suggest an alternative way please to have 2 or more instances of EA, which will manage predefined positions with the different settings on the same pair.


Thank a lot,

Arthur


 
 Post subject: Re: Specific Trailing Stop Post rating: 0   New post Posted: Mon 15 Apr, 2013, 10:49 
User avatar

User rating: 8
Joined: Tue 31 Jan, 2012, 11:24
Posts: 72
Location: India, Gurgaon
Check:

viewtopic.php?f=7&t=47762&p=65836&hilit=trailing+stop#p65836

Thanks.


 
 Post subject: Re: Specific Trailing Stop Post rating: 0   New post Posted: Mon 15 Apr, 2013, 20:50 

User rating: 0
Joined: Fri 12 Apr, 2013, 00:05
Posts: 13
Location: United KingdomUnited Kingdom
Thanks Drishti,


But as I mentioned in the first sentence - there in no TS Strategy like this on the forum yet.

What is Instant Trailing Stop? It is a stop which follow the price by every little tick (even 0.001 of a pip). It also should be added an Increment Pips parameter, to allow EA to move only if there is a change in 5th decimal for instance (Increment Pips = 0.1).

In addition, we should specify the constant distance in pips to follow the price by. Something like InstantTrailPips parameter.

All the parameters I need:

Stage 1.

1). Start Trail At Pips:
2). Instant Trail Pips (SL distance behind):
3). Instant Trail Pips Increment:
4). Stop Trail At Pips:

All the same for Stage 2 and 3.

>>>>>>

You can get a feel of what the Instant Trailing Stop is in the MPTM mq4 EA if you wish to (attached below).


Thank you,

Arthur


Attachments:
Multi purpose trade manager instructions.pdf [108.64 KiB]
Downloaded 483 times
Multi purpose trade manager.mq4 [113.21 KiB]
Downloaded 364 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Specific Trailing Stop Post rating: 1   New post Posted: Mon 15 Apr, 2013, 21:59 
User avatar

User rating: 3
Joined: Mon 30 May, 2011, 18:51
Posts: 51
Location: Portugal, Aveiro
Hello,

I use something like this:

public void updateTrailingStop(ITick tick, double pTriggerPips) throws JFException {

            if (order != null && inState(IOrder.State.FILLED)) {

                Instrument inst = order.getInstrument();

                double newStop;
                double openPrice = order.getOpenPrice();
                double currentStopLoss = order.getStopLossPrice();

                // (START) trailing stop loss is activated when price is higher than order price + trailingTrigger pips
               
                if (order.isLong()) { // long side order
                    if (tick.getBid() > openPrice + toPrice(pTriggerPips, inst)) {
                        // trailing stop loss
                        newStop = tick.getAsk() - toPrice(pTriggerPips, inst);
                        newStop = round(newStop, inst);

                        if (currentStopLoss < newStop) {
                            order.setStopLossPrice(newStop);
                            return;
                        }
                    }

                } else { // short side order
                    if (tick.getAsk() < openPrice - toPrice(pTriggerPips, inst)) {

                        // trailing stop loss
                        newStop = tick.getBid() + toPrice(pTriggerPips, inst);
                        newStop = round(newStop, inst);

                        if (currentStopLoss > newStop) {
                            order.setStopLossPrice(newStop);
                            return;
                        }
                    }
                }
            }
        }


Hope it helps!!!

LinnuxFX


 
 Post subject: Re: Specific Trailing Stop Post rating: 0   New post Posted: Tue 16 Apr, 2013, 18:15 

User rating: 0
Joined: Fri 12 Apr, 2013, 00:05
Posts: 13
Location: United KingdomUnited Kingdom
Hello LinnuxFX,


Thanks for your reply. Could you post a file please if you don't mind.

Unfortunately, I am not a coder, but as far as I can read it - it is an instant trailing stop with the trigger price level in pips, which will trail my position by the same constant TriggerPips amount further on.

Well, thank you, it is a fundamental part of my request. This code should be taken as a base I believe.

I'll show exactly what I need comparing to this.


This strategy:

TriggerPips: 20 pips

So, when I will be +20, it will move my SL to BE. When I will be +20.5, it will move my SL to BE +0.5 and so on (If I read the code correctly).


What I need:

TriggerPips: 20 pips

When I will be +20, I want to move my SL to BE +18 straight away. (I need this extra parameter of step behind and to make it configurable) >> Something like "SL Step Behind", which is equal to 2 pips in this case.

Next, when I will be +20.5, it will move my SL to +18.5 similarly to the above example.

Finally, I want to stop trailing at 26 pips and let it run. (An extra parameter of "StopTrailAt" required). My SL will remain at +24 in this case.

This would be a complete 1st Stage.

I need a total of 3 exactly the same stages like this.


I hope I keep my explanation as clear as possible.


Thank you,

Arthur


 
 Post subject: Re: Specific Trailing Stop Post rating: 0   New post Posted: Sun 21 Apr, 2013, 01:35 
User avatar

User rating: 0
Joined: Mon 01 Aug, 2011, 11:51
Posts: 3
Location: Russian Federation, Saint-Petersburg
Maybe this feature.
private void trail(IOrder order, double trailPips, double step) throws JFException {
        Instrument instr = order.getInstrument();
        boolean isLong = order.isLong();
        double sl = order.getStopLossPrice();
        double pv = instr.getPipValue();
        if (isLong) {
            double bidPrice = history.getLastTick(instr).getBid();
            if (sl < bidPrice - (trailPips + step) * pv) {
                order.setStopLossPrice(bidPrice - trailPips * pv);
            }
        }
        if (!isLong) {
            double askPrice = history.getLastTick(instr).getAsk();
            if (sl > askPrice + (trailPips + step) * pv) {
                order.setStopLossPrice(askPrice + trailPips * pv);
            }
        }
    }

Use can so:
trail(marketOrder,20,0.5)


 
 Post subject: Re: Specific Trailing Stop Post rating: 0   New post Posted: Sun 21 Apr, 2013, 18:04 

User rating: 0
Joined: Fri 12 Apr, 2013, 00:05
Posts: 13
Location: United KingdomUnited Kingdom
ilmac wrote:
Maybe this feature.
private void trail(IOrder order, double trailPips, double step) throws JFException {
        Instrument instr = order.getInstrument();
        boolean isLong = order.isLong();
        double sl = order.getStopLossPrice();
        double pv = instr.getPipValue();
        if (isLong) {
            double bidPrice = history.getLastTick(instr).getBid();
            if (sl < bidPrice - (trailPips + step) * pv) {
                order.setStopLossPrice(bidPrice - trailPips * pv);
            }
        }
        if (!isLong) {
            double askPrice = history.getLastTick(instr).getAsk();
            if (sl > askPrice + (trailPips + step) * pv) {
                order.setStopLossPrice(askPrice + trailPips * pv);
            }
        }
    }

Use can so:
trail(marketOrder,20,0.5)


Hello Ilmac,


Thank you for this.

But as far as I understand the principal of this code - it will start to trail SL immediately after the price will be higher than trailPips + step and it will keep moving my SL at trailPips interval. Alright.

But, I need to have a trigger level as it is explained above, so I don't want to trail my position straight away.

Generally, the feature of "STEP" is what I need.

Overall:

Here were mentioned 3 out of 4 features to build the strategy I need. The 4th and last one is "StopTrailAt" which I believe is simple.

I need someone to combine this all together.


Thank you
Arthur


 
 Post subject: Re: Specific Trailing Stop Post rating: 0   New post Posted: Tue 23 Apr, 2013, 18:18 
User avatar

User rating: 0
Joined: Fri 02 Mar, 2012, 05:13
Posts: 2
Location: Russian Federation, Rostov-on-Don
private void trail(IOrder order, ITick tick, int[] triggers, int[] stops) throws JFException {
        double pr=order.getProfitLossInPips();
        for(int i=triggers.length-1;i>=0;i--) {
            if(pr<triggers[i]) continue;
            double pv=order.getInstrument().getPipValue();
            double nsl,sl=order.getStopLossPrice();
            if(order.isLong()) {
                nsl=tick.getBid()-stops[i]*pv;
                if(nsl>sl) order.setStopLossPrice(nsl);
            } else {
                nsl=tick.getAsk()+stops[i]*pv;
                if(nsl<sl || sl==0) order.setStopLossPrice(nsl);
            }
            return;
        }
    }
trail(order,tick,new int[]{20,28,36},new int[]{4,8,16});


 

Jump to:  

  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com