NexusFi: Find Your Edge


Home Menu

 





Command to go flat at end of the session


Discussion in ThinkOrSwim

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




 
Search this Thread

Command to go flat at end of the session

  #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?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Deepmoney LLM
Elite Quantitative GenAI/LLM
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
 

  #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 Twitter Reply With Quote





Last Updated on September 10, 2019


© 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