Discussion of article "Cross-Platform Expert Advisor: Custom Stops, Breakeven and Trailing"

 

New article Cross-Platform Expert Advisor: Custom Stops, Breakeven and Trailing has been published:

This article discusses how custom stop levels can be set up in a cross-platform expert advisor. It also discusses a closely-related method by which the evolution of a stop level over time can be defined.

The following feature shows a diagram of calculation of the breakeven in the way described above. Based on the this flowchart, the three values activation, deactivation, and new stop level are calculated beforehand. If the current price level is greater than or equal to the minimum price level required for the initial stage (setting stoploss to breakeven), the calculated new stop level calculated earlier will be used as the tentative new stop level for the trade. If not, then the output would be zero. The next step would be to check if the new stop level is within the current stop level, which should always return true if the previous condition was satisfied, and thus would return the calculated stop level as the final output.


Breakeven

Author: Enrico Lambino

 

Hi Enrico. Your great work continues. Do not tire, keep up the great work.

 

Hello,

It appears it's not possible to set a specific volume (percent) for trailing stop?

 

How do I use 2 or more TS?

This is my code:

//--- trailing stop
   CTrails *trails=new CTrails();
   //--- setting breakeven
   CTrail *trail_be=new CTrail();
   trail_be.Set(BELevel,BEOpenPriceDist,0);   
   trails.Add(trail_be);
   //--- setting trailing stop
   CTrail *trail=new CTrail();
   trail.Set(trail_value,trail_start,trail_step);
   trails.Add(trail);
   //---     
   main.Add(trails);

Breakeven don't work in this case. If I remove the trailing stop (trail object) breakeven works fine.

 
mbjen:

Hello,

It appears it's not possible to set a specific volume (percent) for trailing stop?

Yes, it is not possible. CTrail and CTrails are for modification of stop level only. For volume, you need to set it on CStop.
mbjen:

How do I use 2 or more TS?

This is my code:

Breakeven don't work in this case. If I remove the trailing stop (trail object) breakeven works fine.

That would depend on the activation and distance you set for the two (breakeven and trail). But it is likely that trailing has triggered first before breakeven. Breakeven will no longer apply if the stop level is already above the breakeven price you have set.
 
Enrico Lambino:
Yes, it is not possible. CTrail and CTrails are for modification of stop level only. For volume, you need to set it on CStop.That would depend on the activation and distance you set for the two (breakeven and trail). But it is likely that trailing has triggered first before breakeven. Breakeven will no longer apply if the stop level is already above the breakeven price you have set.
Below the settings I use. Breakeven is not working. As I understand second trail must be activated at distance 500, right? So breakeven must be activated before. Why it don't work then?
   //--- trailing stop
   CTrails *trails=new CTrails();
   //--- setting breakeven
   CTrail *trail_be=new CTrail();
   //trail_be.Set(BELevel,BEOpenPriceDist,0);   
   trail_be.Set(230,250,0);   
   trails.Add(trail_be);
   //--- setting trailing stop
   CTrail *trail=new CTrail();
   //trail.Set(trail_value,trail_start,trail_step);
   trail.Set(200,500,10);
   trails.Add(trail);
   //---     
   main.Add(trails);
 
//--- trailing stop
   CTrails *trails=new CTrails();
   //--- setting breakeven
   CTrail *trail_be=new CTrail();
   //trail_be.Set(BELevel,BEOpenPriceDist,0);   
   trail_be.Set(230,250,0);   
   trails.Add(trail_be);
   //--- setting trailing stop
   CTrail *trail=new CTrail();
   //trail.Set(trail_value,trail_start,trail_step);
   trail.Set(400,500,10);
   trails.Add(trail);
   //---     
   main.Add(trails);

Don't work either.

 
mbjen:

Don't work either.

Try to lower your breakeven/trailing activation target. Just because you have set a breakeven or trailing does not mean the market is obliged to hit it.

 
Enrico Lambino:

Try to lower your breakeven/trailing activation target. Just because you have set a breakeven or trailing does not mean the market is obliged to hit it.


I'm checking at the same market history period in backtest. If I enable both TS (regular trailing stop) and BE only TS works and BE don't work (I don't see the stop line). If I disable TS BE works fine. I test in backtest and check the stop lines. 

 
mbjen:

I'm checking at the same market history period in backtest. If I enable both TS (regular trailing stop) and BE only TS works and BE don't work (I don't see the stop line). If I disable TS BE works fine. I test in backtest and check the stop lines. 

What is the value of your takeprofit? Is it the same as or greater than the activation price (in points) for BE?
 
mbjen:

Don't work either.

Your first code activates breakeven, not trailingstop. If there would be any further modification of SL, it would be takeprofit. But if your TP is 500 points, the trailing would not activate at all at 500 points, since the trade has already left the market at that point.

Your second code uses trailingstop, but not breakeven. Because even before the breakeven can be applied, the SL has already moved above the breakeven price.