This code snippet demonstrates how to implement a robustness tester for trading strategies based on conditional trading days, months, and years using the ProBuilder language. The purpose is to test the strategy under various temporal conditions to assess its performance consistency.
//Day Month and Year Robustness Tester
//By Vonasi
//20190901
//0 = all days
//1 = odd days only
//2 = even days only
//3 = odd months only
//4 = even months only
//5 = even years only
//6 = odd years only
//7 = odd days in odd months only
//8 = even days in even months only
//9 = even days in odd months only
//10 = odd days in even months only
//11 = even months in even years only
//12 = odd months in odd years only
//13 = even months in odd years only
//14 = odd months in even years only
//15 = odd days in odd months in odd years only
//16 = even days in even months in even years only
//17 = even days in odd months in odd years only
//18 = odd days in even months in even years only
//19 = odd days in even months in odd years only
//20 = even days in odd months in even years only
//21 = even days in even months in odd years only
//22 = odd days in odd months in even years only
oddday = opendayofweek mod 2 = 1
evenday = opendayofweek mod 2 = 0
oddmonth = openmonth mod 2 = 1
evenmonth = openmonth mod 2 = 0
oddyear = openyear mod 2 = 1
evenyear = openyear mod 2 = 0
tradeon = 0
if choice = 0 then tradeon = 1 endif
//odd days only
if choice = 1 and oddday then tradeon = 1 endif
//even days only
if choice = 2 and evenday then tradeon = 1 endif
//odd months only
if choice = 3 and oddmonth then tradeon = 1 endif
//even months only
if choice = 4 and evenmonth then tradeon = 1 endif
//even years only
if choice = 5 and evenyear then tradeon = 1 endif
//odd years only
if choice = 6 and oddyear then tradeon = 1 endif
//odd days in odd months only
if choice = 7 and oddday and oddmonth then tradeon = 1 endif
//even days in even months only
if choice = 8 and evenday and evenmonth then tradeon = 1 endif
//even days in odd months only
if choice = 9 and evenday and oddmonth then tradeon = 1 endif
//odd days in even months only
if choice = 10 and oddday and evenmonth then tradeon = 1 endif
//even months in even years only
if choice = 11 and evenmonth and evenyear then tradeon = 1 endif
//odd months in odd years only
if choice = 12 and oddmonth and oddyear then tradeon = 1 endif
//even months in odd years only
if choice = 13 and evenmonth and oddyear then tradeon = 1 endif
//odd months in even years only
if choice = 14 and oddmonth and evenyear then tradeon = 1 endif
//odd days in odd months in odd years only
if choice = 15 and oddday and oddmonth and oddyear then tradeon = 1 endif
//even days in even months in even years only
if choice = 16 and evenday and evenmonth and evenyear then tradeon = 1 endif
//even days in odd months in odd years only
if choice = 17 and evenday and oddmonth and oddyear then tradeon = 1 endif
//odd days in even months in even years only
if choice = 18 and oddday and evenmonth and evenyear then tradeon = 1 endif
//odd days in even months in odd years only
if choice = 19 and oddday and evenmonth and oddyear then tradeon = 1 endif
//even days in odd months in even years only
if choice = 20 and evenday and oddmonth and evenyear then tradeon = 1 endif
//even days in even months in odd years only
if choice = 21 and evenday and evenmonth and oddyear then tradeon = 1 endif
//odd days in odd months in even years only
if choice = 22 and oddday and oddmonth and evenyear then tradeon = 1 endif
Explanation of the Code:
tradeon is initialized to 0 (false). This variable will control whether a trade should be executed based on the specified conditions.choice (which is set during optimization) to determine under which conditions trades should be executed. For example, if choice is 1, trades will only be executed on odd days.tradeon variable to 1 (true) if the current date matches the criteria set by the choice variable.Check out this related content for more information:
https://www.prorealcode.com/topic/day-month-year-strategy-robustness-tester/#post-106072
Visit Link