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



Everything else works; TOS ThinkScript AddOrder does not.


Discussion in ThinkOrSwim

Updated by Zogger99
    1. trending_up 942 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 1 replies
    2. attach_file 2 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
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

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

 
Search this Thread
 

Everything else works; TOS ThinkScript AddOrder does not.

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

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;
#DowntrendValue.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

#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;
#Candle1Value.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

#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;
#Candle2Value.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

#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;
#Candle3Value.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

#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;
MarkThisBar.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


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;
#PriceIs.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

#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

Can you help answer these questions
from other members on futures io?
T​​​​​​radestation datafeed (real time and historical) to NT8
NinjaTrader
help to convert from thinkscript to ninjascript
NinjaTrader
Need a near crosses scan help for TOS
ThinkOrSwim
Price Down, Volume Up, Open Interest Down
Traders Hideout
Looking freelancer for MT4 Indicator
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Legal question and need desperate help
69 thanks
Building a high-performance data system
14 thanks
Risk reward question
11 thanks
TopstepTrader's Michael Patak (Founder) - Ask Me Anything (AMA)
11 thanks
Is Orderflow An Outdated Concept?
11 thanks
 
(login for full post details)
  #2 (permalink)
Kannapolis, NC
 
 
Posts: 2 since Apr 2019
Thanks: 281 given, 1 received

Not sure if you figured this out,

I uncommented the addOrder lines and it looks like it worked fine.

I wonder if you have the Strategy set to plot the trades?
When you click the gear for the strategy, in the upper right there is a check box for Show Study - make sure it's checked off.

Attached Thumbnails
Click image for larger version

Name:	image_822.png
Views:	11
Size:	88.0 KB
ID:	303160   Click image for larger version

Name:	image_443.png
Views:	7
Size:	114.9 KB
ID:	303161  
Reply With Quote


futures io Trading Community Platforms and Indicators ThinkOrSwim > Everything else works; TOS ThinkScript AddOrder does not.


July 20, 2020


Upcoming Webinars and Events
 

Getting Comfortable with Price Action Patterns w/Earn2Trade

Aug 4
 

Live Video Panel: Ask Me Anything w/Ironbeam Brokerage

Aug 6
     



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