Everything else works; TOS ThinkScript AddOrder does not. - ThinkOrSwim Programming | futures io social day trading
futures io futures trading

Everything else works; TOS ThinkScript AddOrder does not.
Updated: Views / Replies:203 / 0
Created: by gmftrs 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 100,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

Everything else works; TOS ThinkScript AddOrder does not.

  #1 (permalink)
ColoradoSprings Colorado/USA
Posts: 2 since Sep 2019
Thanks: 0 given, 1 received

Everything else works; TOS ThinkScript AddOrder does not.

I need some help here. I want to backtest a strategy. Below is my TOS ThinkScript code to mark a trade entry and then exit the trade either by hitting the stop loss or the profit target. I cannot get the trade to mark an open price bar, let alone a close.

When the AddOrder code is commented out, the script accurately marks the price chart with an UP arrow where the trade should open. Also, the AddLabel command shows at the top of the chart. However, when the AddOrder code is active, then the AddLabel and the UP arrow does not show - and neither does the script mark the open.

You’ll notice numerous commented out lines. I use these for debugging purposes and, when individually active, they all display on the price chart. So I know everything is working up to the AddOrder code.

It’s my understanding that, if the script is working properly, I should be able to see where the trade begins and where it ends on the price chart when the code is applied to the Price area within the Edit Studies window. Can you spot where I am in error? Thanks for any feedback anyone can provide. Here’s my script in its entirety…

input atrMult = .25;
input atrLength = 20; #Average this many prev candles to get the avg length
input PctCandleBodySize = .25; #Candle body must be at least this % of it's range.
input TrendLength = 5; #Look back this far for downtrend confirmation

#Do we have a downtrend coming into the pattern? Check the slope using the Typical Price.
def CalcSlope = (hlc3 - hlc3[TrendLength]) / TrendLength;
def DownTrendOK = if CalcSlope < 0 then yes else no;

#For debug purposes...
#plot DowntrendValue = downTrendOK;

#Qualify the 1st candle.
def Candle1Down = if open[2] > close[2] then yes else no;
def Candle1BodySizeOK = AbsValue(open[2] - close[2]) / AbsValue(high[2] - low[2]) >= PctCandleBodySize;
def Candle1OK = if Candle1Down then yes else no;

#For debug purposes...
#plot Candle1Value = Candle1OK;

#Qualify the 2nd candle...
def Candle2Up = if open[1] < close[1] then yes else no;
def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax[1] > BodyMax[2] and BodyMin[1] < BodyMin[2];
#def Candle2Engulf = if open[1] < close[2] and close[1] > open[2] then YES else NO;
def Candle2BodySizeOK = AbsValue(open[1] - close[1]) / AbsValue(high[1] - low[1]) >= PctCandleBodySize;
def Candle2OK = if Candle2Up and IsEngulfing then yes else no;

#For debug purposes...
#plot Candle2Value = Candle2OK;

#Qualify the third candle...
def Candle3SizeOK = TrueRange(high = high, close = close, low = low) > ATR(length = atrLength, "average type" = "SIMPLE") * atrMult;
def Candle3UpDayOK = close > open ; #Needs to be an UP candle
def Candle3BodySizeOK = AbsValue(open - close) / AbsValue(high - low) >= PctCandleBodySize;
def Candle3GapOK = if open > close[1] then yes else no;
def Candle3OK = if Candle3SizeOK and Candle3UpDayOK and Candle3GapOK then yes else no;

#For debug purposes...
#plot Candle3Value = Candle3OK;

#Arrow marks the spot...
def MeetsCriteria = if Candle1OK + Candle2OK + Candle3OK == 3 then yes else no; # + DowntrendOK; MeetsCriteria set to value 1;

#No need to plot MeetsCriteria arrow
#def MarkThisBar = if MeetsCriteria ==1 then 1 else 0;
plot MarkThisBar = if MeetsCriteria ==1 then 1 else 0;

AddLabel(yes, "Arrows point to a Downside Reversal marked by an engulfing UP candle followed by an upward gap. BUY at the gap w/pos Mkt Tone while coming off support.", Color.GREEN);

#Profit Tracking code
#Define the trade plan - numeric
def StopLoss = if MeetsCriteria then low[1] else StopLoss[1]; #The low of the engulfing candle
def BuyPrice = if MeetsCriteria then open else BuyPrice[1]; #The open of the gapping candle
def ProfitTarget = if MeetsCriteria then (BuyPrice * 1.025) else ProfitTarget[1]; #Target will be 2.50% of the BuyPrice

#For debug purposes...
#plot PriceIs = if MeetsCriteria then ProfitTarget else double.Nan;

#Open BUY and SELL signals
def buy = if MeetsCriteria then yes else no;
def StopHit = close <= StopLoss;
def ProfitHit = close >= ProfitTarget;
def SellLoss = if StopHit then close else SellLoss[1];
def SellProfit = if ProfitHit then close else SellProfit[1];

#This is where the profit/loss values would be calculated
#AddOrder(OrderType.BUY_TO_OPEN, buy, open, tradeSize = 1, tickcolor = Color.GRAY, arrowcolor = Color.GRAY);
#AddOrder(OrderType.SELL_TO_CLOSE, ProfitHit, SellProfit, tradeSize = 1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Profit");
#AddOrder(type = OrderType.SELL_TO_CLOSE, StopHit, SellLoss, tradeSize = 1, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Loss");

Reply With Quote


futures io > > > > > Everything else works; TOS ThinkScript AddOrder does not.

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

futures io is celebrating 10-years w/ over $18,000 in prizes!

Right now

$250 Amazon Gift Cards with our "Thanks Contest" challenge!

Right now

Webinar: The Seven Most Effective Trading Setups w/Peter Davies @ Jigsaw

Oct 17

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display entry price into AddOrder line bobbydigital83 ThinkOrSwim 2 March 29th, 2019 11:09 PM
AddOrder(): Does this dang thing work? aventeren ThinkOrSwim 7 January 28th, 2018 07:01 PM
TOS not working for me, anyone else? aburakan ThinkOrSwim 2 September 30th, 2015 12:49 PM
Does anyone else use continuum and not have absent data for 7/18? nepenthean Reviews of Brokers and Data Feeds 3 July 24th, 2014 01:05 PM
Cheap Dollar Fuels One-Way Bets in Everything Else Quick Summary News and Current Events 0 April 29th, 2011 12:00 AM

All times are GMT -4. The time now is 06:23 PM. (this page content is cached, log in for real-time version)

Copyright © 2019 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