Exit at close for trailing stop strategy - ThinkOrSwim Programming | futures io social day trading
futures io futures trading

Exit at close for trailing stop strategy
Updated: Views / Replies:2,594 / 0
Created: by skorpyo Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Thread Tools Search this Thread

Exit at close for trailing stop strategy

  #1 (permalink)
Trading Apprentice
Bucharest + Romania
Futures Experience: Advanced
Platform: Thinkorswim, NinjaTrader, Metatrader
Favorite Futures: Options, Forex
Posts: 2 since Jul 2013
Thanks: 0 given, 0 received

Exit at close for trailing stop strategy

Hi guys,

I'm having an issue with a strategy here. I'm using a volatility based trailing stop similar to the chandelier stop. While backtesting i saw that the strategy records entering and exiting at the calculated stop price instead of the closed candle price.

In other words although the strategy waits for the candle to close before exiting and reversing, it records doing so at the stop price and not the actual closed candle price.

Where am i going wrong with the code here?

Thanks guys.

# Input Declarations:
input mult = 3.0; #Multiple of Average True Range to use
input length = 10; #Average True Range period
# Input to select Close or High/Low for switching:
input Style = {default Close, HighLow};
def type;
switch (Style){
case Close:
type = 1;
case HighLow:
type = 0;
# Set parameters based on switch selection:
def uu = if type then close else high;
def ll = if type then close else low;
def na = Double.NaN;
# Calculate average range for volatility:
def atr = ExpAverage(high - low, length);
# Calculate initial short and long volatility stop values:
def svs = low + Ceil(mult * atr / TickSize()) * TickSize();
def lvs = high - Ceil(mult * atr / TickSize()) * TickSize();
# Set up the trailing stop logic:
rec shortvs = if IsNaN(shortvs[1]) then svs else if uu > shortvs[1] then svs else Min(svs, shortvs[1]);
rec longvs = if IsNaN(longvs[1]) then lvs else if ll < longvs[1] then lvs else Max(lvs, longvs[1]);
# Detect if we breached the trailing stop (close or high/low):
def longswitch = if uu >= shortvs[1] and uu[1] < shortvs[1] then 1 else 0;
def shortswitch = if ll <= longvs[1] and ll[1] > longvs[1] then 1 else 0;
# This logic remembers the direction and changes when needed:
rec direction = CompoundValue(1, if IsNaN(direction[1]) then 0 else
if direction[1] <= 0 and longswitch then 1
else if direction[1] >= 0 and shortswitch then -1
else direction[1], 0);

# Set up the two plots. "na" makes the current value disappear
# if we're trading in the opposite direction:
def short = if direction > 0 then na else shortvs;
def long = if direction < 0 then na else longvs;

def stopout = if direction[1] < 0 and direction > 0 then 1 else 0;
def stopprice = shortvs[1];
AddOrder(OrderType.BUY_TO_CLOSE, stopout, stopprice);

I also have another separate script for the opposite side running them both at the same time.

def stopout = if direction[1] > 0 and direction < 0 then 1 else 0;
def stopprice = longvs[1];
AddOrder(OrderType.SELL_TO_CLOSE, stopout, stopprice);

Reply With Quote


futures io > > > > > Exit at close for trailing stop strategy

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Upcoming Webinars and Events (4:30PM ET unless noted)

Wyckoff Hunting for Great Risk/Reward Ratio w/Gary Fullett

Elite only

Digging into the Details of iSystems w/Stage 5 & iSystems

Jun 5

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using SuperTrend for trailing stop in a strategy - help needed DarrenH NinjaTrader Programming 16 September 29th, 2017 10:03 PM
Simple trailing stop strategy jeemba EasyLanguage Programming 2 August 2nd, 2013 07:05 AM
Auto Trading Strategy - Exit On Close Price error TheGaryGuy NinjaTrader 3 January 23rd, 2013 08:00 AM
Trailing stop indicator Buscador The Elite Circle 3 November 15th, 2012 12:57 PM
Strategy Disables When Trailing Stop Filled graygoat NinjaTrader Programming 2 September 27th, 2012 05:16 PM

All times are GMT -4. The time now is 08:13 AM.

Copyright © 2018 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2018-05-24 in 0.07 seconds with 19 queries on phoenix via your IP