Buy Close sell Open AAPL

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #207770 quote
    andyafonso
    Participant
    New

    Hi again!

    I have a hard time figuring out why my system doesnt do what i want it to do.

    I want to buy the close if it’s above moving average 200 and closing above 3%.

    Then i want to sell this position the day after at open.

    Since i live in Sweden the trading hours for the NY stockxchange is 15:30 -> 22:00.

    Stock is AAPL (just an example).

    // Buy a strong close and sell the open in a strong trend.
    // Instrument: AAPL, 30min, 9:30 - 4:00 Eastern Time, 1 point spread, account size: 10.000 Euro
    
    // ProOrder code parameter
    DEFPARAM CumulateOrders = False
    
    // Define intraday trading window
    ONCE timeSell = 153000
    ONCE timeBuy = 220000
    
    // Define position size
    ONCE positionSize = 10
    
    // Define indicators of Moving Avarage
    ma1 = Average[200](close)
    ma2 = close[0] > ma1
    
    // Define a strong close in percentage
    c1 = 3
    c2 = (DClose(0) - DClose(1))/DClose(1) *  100
    
    // Open long position
    IF NOT LongOnMarket AND Time = timeBuy AND ma1 AND c2 >= c1 THEN
    BUY positionSize SHARES AT MARKET
    ENDIF
    
    // Sell long position
    If LongOnMarket AND Time = timeSell THEN
    SELL AT MARKET
    ENDIF

    When i backtest i get 10 trades only and the system doesnt sell the positions the day after.

    #207772 quote
    robertogozzi
    Moderator
    Master

    It opens trades at 22:00 (when the 21:30 candle closes) and exits at 15:30 (when the 15:00 candle closes, provided there is one).

    Try replacing Time with OpenTime.

    andyafonso thanked this post
    #207775 quote
    andyafonso
    Participant
    New

    Hi again,

    Got it to work now, thanks alot! The system is closing the position after 30 min now (16:00) instead of 15:30. I guess when i change the time the system will not find a closing candle to sell it on.

    #207781 quote
    andyafonso
    Participant
    New
    // Buy or Sell a strong/weak close and sell the open in a strong/weak trend.
    // Instrument: Tesla, 10min, 9:30 - 4:00 Eastern Time, 1 point spread, account size: 10.000 Euro
    
    // ProOrder code parameter
    DEFPARAM CumulateOrders = False
    
    // Define intraday trading window
    ONCE timeSell = 153000
    ONCE timeBuy = 220000
    
    // Define position size
    ONCE positionSize = 50
    
    // Define indicators of Moving Avarage trend positive or negative
    ma1 = Average[200](close)
    ma2 = close[0] > ma1
    ma3 = close[0] < ma1
    
    // Define indicators of ADX trend indicator if its strong or weak
    trend1 = ADX[14] > 30
    trend2 = ADX[14] < 30
    
    // Define a strong close in percentage
    c1 = 3
    c2 = (DClose(0) - DClose(1))/DClose(1) *  100
    c3 = -3
    
    // Open long position
    IF NOT LongOnMarket AND Time = timeBuy AND ma1 AND c2 > c1 AND trend1 THEN
    BUY positionSize SHARES AT MARKET
    ENDIF
    
    // Sell long position
    If LongOnMarket AND OpenTime = timeSell THEN
    SELL AT MARKET
    ENDIF
    
    // Open short position
    IF NOT ShortOnMarket AND Time = timeBuy AND ma3 AND c2 < c1 AND trend2 THEN
    SELLSHORT positionSize SHARES AT MARKET
    ENDIF
    
    // Close short position
    IF ShortOnMarket and OpenTime = timeSell THEN
    EXITSHORT AT MARKET
    ENDIF

    Here is the final version, either short or buy close depending on the trend and sell/covers the day after.

    dashboard.png dashboard.png equity.png equity.png
    #207784 quote
    andyafonso
    Participant
    New

    Want to add it works very poorly overall on other stocks. But it was a fun project 🙂 On to the next!

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

Buy Close sell Open AAPL


General Trading: Market Analysis & Manual Trading

New Reply
Author
author-avatar
andyafonso @andyafonso Participant
Summary

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

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 01/20/2023
Status: Active
Attachments: 2 files
Logo Logo
Loading...