NexusFi: Find Your Edge


Home Menu

 





Help with thinkscript Strategy Closing a Position


Discussion in ThinkOrSwim

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




 
Search this Thread

Help with thinkscript Strategy Closing a Position

  #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?
Are there any eval firms that allow you to sink to your …
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
ZombieSqueeze
Platforms and Indicators
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
23 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts