NexusFi: Find Your Edge


Home Menu

 





Help with thinkscript Strategy Closing a Position


Discussion in ThinkOrSwim

Updated
    1. trending_up 4,038 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
Leevize
Hillsboro Oregon
 
Posts: 2 since Feb 2018
Thanks Given: 2
Thanks Received: 0

thinkscript newb here.
This strategy script will get into a trade but I can't seem to figure out how to get it to close the trade. Anyone know what I'm doing wrong here?

 
Code
input length = 14;
input trendLevel = 20;
input maxLevel = 50;
input PriceMovmentProfit = 0.10;
input PriceMovmentLoss = 0.10;
input averageType = AverageType.WILDERS;

def ExitpriceProfit = EntryPrice() + PriceMovmentProfit;
def CurrentPrice = getaveragePrice();

def hiDiff = high - high[1];
def loDiff = low[1] - low;

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
def DIplus = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def DIminus = 100 * MovingAverage(averageType, minusDM, length) / ATR;

def DX = if (DIplus + DIminus > 0) then 100 * AbsValue(DIplus - DIminus) / (DIplus + DIminus) else 0;
def ADX = MovingAverage(averageType, DX, length);

#dmiplus is greater than dmiminus and adx is above trendLevel
AddOrder(OrderType.BUY_TO_OPEN
    ,(DIplus[1] < DIminus[1])
    and (DIplus > DIminus)
    and ADX > trendLevel
    , tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "Uptrend " );


AddOrder(OrderType.BUY_TO_CLOSE,  ExitpriceProfit,  tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "CLOSE " + ExitpriceProfit );


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My Rant with AMP Futures
Trading Reviews and Vendors
EA
Platforms and Indicators
Trump Media to sell instant access to market-moving soci …
Traders Hideout
No book, only a stair: journaling fills where price move …
Cryptocurrency
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Mes vs MNQ
6 thanks
NexusFi site changelog and issues/problem reporting
5 thanks
BERN ALGOS algo trading journal
3 thanks
Johnnys Journal
2 thanks
TopStep Trader disappointment
2 thanks
  #2 (permalink)
 Vacationer 
Sarasota, Florida
 
Experience: Intermediate
Platform: TOS, IB, TS
Broker: TD Ameritrade, IB, TS
Trading: ES, NQ, YM, RTY
Posts: 27 since Jan 2018
Thanks Given: 38
Thanks Received: 13

Leevise,

From what I can see in your last line of code, this AddOrder should be " Sell_To_Close". Hope this helps.

Haven't gone thru all the code to see if your variable actually becomes true , but I think this order type is worth noting.

Good luck,


Reply With Quote
Thanked by:
  #3 (permalink)
Leevize
Hillsboro Oregon
 
Posts: 2 since Feb 2018
Thanks Given: 2
Thanks Received: 0



Vacationer View Post
Leevise,

From what I can see in your last line of code, this AddOrder should be " Sell_To_Close". Hope this helps.

Haven't gone thru all the code to see if your variable actually becomes true , but I think this order type is worth noting.

Good luck,

Wow, thought i tried that one. That was it. Thanks so much.


Reply With Quote




Last Updated on February 16, 2018


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts