Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

  • Forums
  • Pinescript
  • Pinescript Strategy - How do I open a trade on specific day of the month

Pinescript Strategy - How do I open a trade on specific day of the month

Jan 21, 2021 - 1:25 AM

Viewed 5193 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/22506 COPY
  • Hi

    I'm building a backtest strategy part of which is opening a trade on a specific day of the month. For example if the day is the 15th open a trade. I'll then keep it open until a certain set of criteria are met.

    Any ideas on how I do this?

    Thanks

    TJ

    0
  • Hi TJ

    The answers you're looking for are all logged here
    https://www.tradingview.com/pine-script-reference/v4/#fun_dayofweek

    
    today = dayofweek(time)
    
    // test if that's the 15th of the month
    if today == 15
    
       // open trade on open condition
       // close trade on close condition
    
    
    This post was edited Jan 21, 2021 08:56AM
    0

    Dave - Helping traders becoming the best version of themselves
  • Thanks works well! The only problem is if the 15th is not a trading day it doesn't execute :-(

    This post was edited Jan 24, 2021 09:38AM
    0
  • Hello

    Then you have to update the logic to figure out if you want to take the trade on a Monday, if the 15 happens to be on a Saturday or on a Sunday

    Documentation is here: https://www.tradingview.com/pine-script-reference/v4/#var_dayofweek{dot}saturday

    0

    Dave - Helping traders becoming the best version of themselves
  • Hi what I'm trying to do is the following:

    1) On a specific day of the month (any) go long with 1/3 of the capital
    2) If there's no stop buy another third as per #1 a month later
    3) As #2 if there is no stop buy the final third in month 3
    4) Hold the position until the stop is hit
    5) Once the stop is hit add one month and then go back to #1
    Stop) The stop needs to be updated each month at the same time, i.e. a monthly shifting trailing stop.

    Can this be done in tradingview pinescript?

    Thanks

    0
  • can you please share how can a order be given at a specific time?

    0
CONTENTS