Back testing specific dates


Category:
0
0

Hi Pete,

When testing back strategies is there a way to test for specific dates or strategy between specific dates?

Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on November 30, 2020 12:42 pm
96 views
0
This is in Thinkorswim platform
( at November 30, 2020 12:44 pm)
0
Private answer

You are going to have to be more specific than that. There are numerous examples already in the forum that show how to buy on specific dates, days of the week or days of the month. There is nothing in the settings that can facilitate this. Every case must be evaluated and a custom solution is always requred.

I am moving this post out of the "Alerts and Notifications" topic and into the "Strategy Guide" topic to better fit your request.

Edit: The code for the chart strategy was provided in the comments section below. I will include a copy of that here, properly formatted so that everyone has a clear view. Below the original I will include my modifications that correct the errors preventing it from working as intended.

input BeginDate = 20201123;
input EndDate = 20201125;
def startOfScan = DaysFromDate(BeginDate);
def endOfScan = DaysTillDate(EndDate);
plot scanPeriod = startOfScan or endOfScan;
AddLabel (Yes, startOfScan);
AddLabel (Yes, endOfScan);
Input price = close;
Input ma8 = 8;
def EMA8 = ExpAverage(Price, ma8);
def Buy = if price > EMA8 then 1 else 0;
def Sell = if price < EMA8 then 1 else 0;
AddOrder(OrderType.BUY_AUTO, Buy and scanPeriod,close,1, name = "Buy");
AddOrder(OrderType.SELL_AUTO, Sell and scanPeriod,Close,1, name = "Sell");

CAUTION: The AddOrder() statements provided in this original code have serious mistakes in the way it selects and displays the entry and exit prices. Do not attempt to use this code for back-testing unless you are willing and able to correct the AddOrder() statements.

Now here is the same code with my modifications to make the start and end dates fully functional. Please note that I am not correcting the errors in the AddOrder() statements in this modified section of code.

input BeginDate = 20201123;
input EndDate = 20201125;
def startOfScan = DaysFromDate(BeginDate) >= 0;
def endOfScan = DaysTillDate(EndDate) >= 0;
plot scanPeriod = startOfScan and endOfScan;
AddLabel (Yes, startOfScan);
AddLabel (Yes, endOfScan);
Input price = close;
Input ma8 = 8;
def EMA8 = ExpAverage(Price, ma8);
def Buy = if price > EMA8 then 1 else 0;
def Sell = if price < EMA8 then 1 else 0;
AddOrder(OrderType.BUY_AUTO, Buy and scanPeriod,close,1, name = "Buy");
AddOrder(OrderType.SELL_AUTO, Sell and scanPeriod,Close,1, name = "Sell");

For those who are interested in correcting the errors in the AddOrder() statements I will provide a link to a previous post where I explain how to get the entry and exit prices into the correct alignment:

https://www.hahn-tech.com/ans/parablic-sar-signal-not-firing-in-tos-strategy/

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 30, 2020 12:56 pm
0
Sorry – This is the code that is not working. This code is written to Buy when Price>8EMA and sell when Price <8EMA input BeginDate = 20201123; input EndDate = 20201125; def startOfScan = DaysFromDate(BeginDate); def endOfScan = DaysTillDate (EndDate); plot scanPeriod = startOfScan or endOfScan; AddLabel (Yes, startOfScan); AddLabel (Yes, endOfScan); Input price = close; Input ma8 = 8; def EMA8 = ExpAverage(Price, ma8); def Buy = if price > EMA8 then 1 else 0; def Sell = if price < EMA8 then 1 else 0; AddOrder(OrderType.BUY_AUTO, Buy and scanPeriod,close,1, name = "Buy"); AddOrder(OrderType.SELL_AUTO, Sell and scanPeriod,Close,1, name = "Sell");
( at November 30, 2020 6:33 pm)
0
I have updated my answer to include the solution you requested.
( at November 30, 2020 7:00 pm)
0
Hi Pete, I was able to search little bit more of thinkscript help menu and able to get it working with below code input EndDate = 20090101; plot price = if DaysTillDate(EndDate) >= 0 and DaysTillDate(EndDate)
( at November 30, 2020 7:17 pm)