Module 1: Starting to Program
Module 2: Indicators and Functions
Module 3: Variables
Module 4: Inputs
Module 5: Exit Techniques
Module 6: Stop Orders and Limit Orders
Module 7 Using Multiple DataStreams in a Strategy
Final Strategy Coding Project
Module 8: Plot Studies and Their Uses
Module 9: Writing to Files
Module 10: How to Code Your Own Indicators and Functions

Custom Trailing Stops and Targets

In this Lesson You'll Learn:

Stop and Limit Orders

This lesson assumes that you know how to code stop and limit orders in Easylanguage. If you aren't familiar with this, please take the lessons in the next module and then come back. 

 

While you may use the setpercenttrailing function to set a trailing stop, you may want to have some more flexibility.

Perhaps you want to use a moving average or some other measure to trail price. In that case, you may simply use a stop or limit order together to create your own trailing stops and targets.

Let’s cover some examples!

Example 1: Moving Average Trailing Stop

If you’d like to use a moving average as the trailing stop level, you just set a stop order for the next bar at the moving average, like below

Sell next bar at average(close,20) stop;

 

Now the stop level will be updated each time as a new bar form, and a stop order will be placed for the next bar.

Example 2: Moving Average Profit Target

To use a moving average that’s above the price as a profit target, you’ll have to place a sell limit order at the moving average.

Sell next bar at average(close,20) limit;

Use Market Orders Instead!

Sometimes you may want to use market orders instead, that are executed if the trailing stop or target level is reached.

While this means that you’ll have to wait for the market to close above or below the stop or target level, it may work better sometimes. In addition, it’s a simpler order type that leaves less margin for errors.

Below you see how we exit a trade if it closes above the 20-period moving average

If close crosses over average(close,20) then sell next bar open;

Login to Your Account



Signup Here
Lost Password