NexusFi: Find Your Edge


Home Menu

 





Command to go flat at end of the session


Discussion in ThinkOrSwim

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




 
Search this Thread
  #1 (permalink)
 Cabdoctor 
Sacramento CA/USA
 
Experience: Intermediate
Platform: TOS, Sierra Chart
Trading: Emini ES
Posts: 10 since Jul 2019
Thanks Given: 2
Thanks Received: 0

Building a strategy and was looking for an easy way to command the strat to close out all positions at the end of RTH, or even better at a set time each day. Thank you in advance.


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The Backwardation Signal: How the CL Futures Curve Tells …
Commodities
CME Launches Bitcoin Volatility Futures June 1 -- First …
Cryptocurrency
Prediction Markets Expiry Day: Trump Eyes War Exit, $230 …
Prediction Markets & Event Contracts
CPI Eve: Fed Hike Odds Hold at 52% for the First Time, I …
Prediction Markets & Event Contracts
Peace Deal Forward Curve: May 22%, June 51%, December 81 …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
205 thanks
Sober Journey With S&P
21 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
Thanks Mike. Godspeed.
7 thanks
  #2 (permalink)
 kjhosken 
Seattle, WA/USA
 
Experience: Intermediate
Platform: TOS, TS
Trading: Forex, crude
Posts: 96 since Sep 2016
Thanks Given: 7
Thanks Received: 35


Cabdoctor View Post
Building a strategy and was looking for an easy way to command the strat to close out all positions at the end of RTH, or even better at a set time each day. Thank you in advance.

Here is my positioning code snippet for thinkscript, feel free to use and modify to fit your needs:

 
Code
input mode = {default reverse, normal, other};

def bullish;
def bearish;
def entryPriceS;
def entrypriceL;

switch (mode) { 
case reverse: 
    bullish = 1;
    bearish = 5;
    entryPriceS = 2;
    entrypriceL = 3;
case normal:
    bearish = 4;
    bullish = 2;
    entryPriceS = 7;
    entrypriceL = 5;
case other:
    bearish = 4;
    bullish = 4;
    entryPriceS = 2;
    entrypriceL = 0;
}
;

def signalUP = bullish and !bullish[1];
def signalDN =  bearish and !bearish[1];
def LX = signalDN;
def SX = signalUP;
input usetimefilter = yes;

#positioning
input rthopen = 0400;
input rthclose = 2000;
def RTH = if usetimefilter == yes then if SecondsFromTime(rthopen) >= 0 and
               SecondstillTime(rthclose) >= 0
            then 1
            else 0 else 1;

AddOrder(OrderType.buy_AUTO,rth == 1 and signalup, entrypriceL, tickcolor = GetColor(6), arrowcolor = GetColor(4), name = "LE");
AddOrder(OrderType.SELL_AUTO,rth == 1 and signaldn, entrypriceS, tickcolor = GetColor(6), arrowcolor = GetColor(5), name = "SE");

AddOrder(OrderType.BUY_TO_CLOSE, rth == 0, tickcolor = GetColor(4), arrowcolor = GetColor(3), name = "EODExit");
AddOrder(OrderType.SELL_TO_CLOSE, rth == 0, tickcolor = GetColor(4), arrowcolor = GetColor(3), name = "EODExit");

AddOrder(OrderType.BUY_TO_CLOSE, rth == 1 and SX, tickcolor = GetColor(4), arrowcolor = GetColor(3), name = "SX");
AddOrder(OrderType.SELL_TO_CLOSE, rth == 1 and LX, tickcolor = GetColor(4), arrowcolor = GetColor(3), name = "LX");
#end of code


Follow me on X Reply With Quote




Last Updated on September 10, 2019


© 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