Dollar Cost Average vs Strategy


Category:
0
0

Hi Pete Hahn,

 

Once again, great site, videos and overall content!!

I have a question.

 

I have created a script (or, to put it mildly, copied and cobbled a script together using your help!) that does Dollar Cost Average over the time frame selected, shown below:

 

input tradeSize = 0;
input endDate = 20200101;
input dollar = 500;

def exit = GetYYYYMMDD() > endDate;
def signal = GetMonth() <> GetMonth()[1];

AddOrder(OrderType.BUY_TO_OPEN, signal, open[-1], round(dollar/open,0), Color.CYAN, Color.CYAN);

AddOrder (orderType.BUY_TO_OPEN,signal,open[-1],tradesize,color.cyan,color.cyan);

AddOrder(OrderType.SELL_TO_CLOSE, exit, open[-1], tradeSize, Color.MAGENTA, Color.MAGENTA);

 

I can choose for one of two things:

  1. To buy a certain amount of stock every month
  2. To buy a certain dollar amount of stock every month

It then sells all my positions at the specified end date.

 

I am looking for help with two things:

  1. How would count the amount of trades that have occurred, and show it as a label, without having to go to the “Show report” and physically count each trade.

 

2. Lets say I wanted to set up a strategy, that bought stock every time a signal occurred (for example, RSI was overbought) and wanted to compare this to the DCA strategy.
I want the DCA to buy $100 worth of stock every month, resulting in $1200 spent in the calendar year. The RSI overbought strategy ends up creating a signal, for example, 4 times in the year. Is there a way that no matter how often the signal buys a stock, it’ll only buy a fraction of $1000 in the year.

To try to explain better.

 

DCA                                                RSI

1 $100

2 $100

3 $100                                    $300

4 $100

5 $100

6 $100

7 $100

8 $100                             $500

9 $100                             $100

10 $100

11 $100

12 $100

 

Hopefully, it shows what I mean. DCA has a signal once a month, with $100 worth of stock being bought.

RSI has a signal sporadically, but in the above example, the signal to buy occurs in month 3, 8 and 9. Therefore I wold want in month 3 to buy $300 worth of shares (as 3 months x $100) and in month 8 to buy $500 (as from month 3 to month 8 = 5 months = $500).

So rather than buying stock every month, you save the same amount and buy whenever the signal occure.

 

(I hope I explained this!!)

Marked as spam
Posted by (Questions: 2, Answers: 2)
Asked on May 19, 2020 4:25 pm
90 views
0
Private answer

I have no idea if it is possible or how to do this. I don't have several hours of time to try to work out a solution. I get 15 min max per solution in the Q&A forum.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 19, 2020 6:01 pm