Simulation savings plan once a month

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #227290 quote
    phoentzs
    Participant
    Master

    So far I have failed to code a kind of ETF savings plan simulation. A savings plan works like this… on the 1st or last day of each month you buy a share of an ETF, for example SP500. So that means cumulative orders true. That would be the standard. But I want to know whether it is really better to only buy when the price is above a certain MA, the standard here is usually the SMA200 in Daily. And then whether it is better to sell all shares if the price slips below this SMA or to simply hold and not buy any new shares. What I’m having trouble with is that the code only buys once a month, cumulate Orders=true

    Can someone please code this simulation for me?

    #227654 quote
    robertogozzi
    Moderator
    Master

    This is the code:

    ONCE LastDay = 0
    IF Month <> Month[1] THEN
    BUY 1 CONTRACT AT MARKET
    LastDay = 31
    IF OpenMonth = 4 OR OpenMonth = 6 OR OpenMonth = 9 OR OpenMonth = 11 THEN
    LastDay = 30
    ELSIF OpenMonth = 2 THEN
    YY      = OpenYear
    LastDay = 28
    IF YY MOD 4 = 0 THEN
    IF YY MOD 100 = 0 THEN
    IF YY MOD 400 = 0 THEN
    LastDay = 29
    ENDIF
    ELSE
    LastDay = 29
    ENDIF
    ENDIF
    ENDIF
    DoW = DayOfWeek - 1
    FOR i = Day TO LastDay
    Dow = Dow + 1
    IF Dow = 7 THEN
    Dow = 0
    ENDIF
    NEXT
    IF Dow = 0 THEN
    LastDay = LastDay - 2
    ELSIF DoW = 6 THEN
    LastDay = LastDay - 1
    ENDIF
    ENDIF
    IF Day = LastDay THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF

    you may add your conditions to the entries, apart from the day.

    #227660 quote
    phoentzs
    Participant
    Master

    That looks good. Thanks Roberto.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Simulation savings plan once a month


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
phoentzs @phoentzs Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by phoentzs
2 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/02/2024
Status: Active
Attachments: No files
Logo Logo
Loading...