♥ 0 |
Strategy to buy on open of Monday or first trading day of the week then sell at % gain dictated by user input Hello Pete, David input weeklypercentdesired = 3; addOrder(ordertype.buy_to_open, Open, name = “WeeklyOpenBuy”); def sell = high > Open*(1 + weeklypercentdesired/100); addOrder(ordertype.Sell_to_Close, sell, name = “3PercentGainSell”);
Marked as spam
|
Private answer
Thinkorswim includes some very helpful data/time functions to accomplish this. The one I use most frequently for projects is the GetDay() function. However they also have functions for GetWeek(), GetMonth() and GetYear(). Here is a link to the GetWeek() function I use for this solution: https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Date---Time/GetWeek This function allows us to always pick the first trading day of the week even if Monday is a Holiday. Here is the code that buys at the open of the first day of the week and takes profit at user adjustable percent above the entry price:
Screenshot below show how this chart strategy behaves on the 30 min intraday chart (left) as well as the daily chart (right). Marked as spam
|
Please log in to post questions.