Strategy to buy open of first trading day of the week


Category:
0
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,
I recently watched your “Thinkorswim Strategy Guide” youtube video.
I’ve been trying to search in vain for a way to create a strategy that involves buying at open on Monday or whatever the first trading day of the week is, then selling out at a certain percentage gain intraday (However long that may take, either that day, the same week or the following week). Then repeating the process on the first trading day of the following week. I have some code that seems to work partially on the weekly chart. Thank you for any help that you can give.

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
Posted by (Questions: 1, Answers: 1)
Asked on August 15, 2020 7:01 pm
479 views
0
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:

input profitPercent = 4.0;
input tradeSize = 100;
def newWeek = GetWeek() <> GetWeek()[1];
def firstDayOfWeek = newWeek and !newWeek[1];
AddOrder(OrderType.BUY_TO_OPEN, firstDayOfWeek[-1], open[-1], tradeSize, Color.GREEN, Color.GREEN, "First Day Of Week");
AddOrder(OrderType.SELL_TO_CLOSE, high > EntryPrice() * (1 + profitPercent * 0.01), close[-1], tradeSize, Color.RED, Color.RED, "Profit Exit");

Screenshot below show how this chart strategy behaves on the 30 min intraday chart (left) as well as the daily chart (right).

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 16, 2020 8:42 am
0
Thanks Pete!! That works very well on the Intraday charts. I was kind of hoping to see the results on the daily chart, but the daily close candle throws the results off. 180D5M or 180D1M seems to give the results I am looking for. Thanks again!!
( at August 16, 2020 3:01 pm)