Exit on the close of the candle

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

    HI All

     

    I am looking for simple code to exit the trade when weekly signal close?

    The strategy i am working on is using weekly signals which enters the trade if weekly candle from previous week closed above SMA5  and exit that trade at the end of the week (i.e. Friday close of market).

    so in the strategy how do i write the code to close the trade at the end of Friday ?

     

    Thanks in Advance.

    #229135 quote
    phoentzs
    Participant
    Master

    This only works via MTF in a smaller time frame.

    If onmarket and Time>=220000 and dayofweek=5 then 
    Sell at market
    Exitshort at market
    ENDIF
    #229174 quote
    Iván González
    Moderator
    Master

    Good morning. First you have to define the indicators in the weekly timeframe and then go down to a timeframe lower than the daily one so that it allows you to close before the market closes. For example, if you use a 1H timeframe then you can close the position on Friday at 21:00. It would be something like this:

    defparam cumulateorders = false
    timeframe (weekly)
    sma5 = average[5](close)
    
    timeframe(1h)
    if close > sma5 and dayofweek=5 and time >210000 then
    buy 10000 cash at market
    endif
    
    if onmarket and dayofweek=5 and time > 200000 and time < 220000 then
    sell at market
    endif
    
    graphonprice sma5 coloured("red")
    WhyAskOZ thanked this post
    #229296 quote
    WhyAskOZ
    Participant
    New

    Ivan

    why is the time frame used 21000 or 20000 ? what does 3pm means ? as currently code sell stock at 4pm in Australia time which is basically not the best time to sell stock and i want to set it as 3pm then what will be time value ?

    #229307 quote
    Iván González
    Moderator
    Master

    Hi!
    Sorry… I wrote the code for Europe…
    In Spain NYSE ends at 22:00, so that’s why I wrote 21:00. In Australia you should write the correct time.
    You just need to change time and it will work.

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

Exit on the close of the candle


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
WhyAskOZ @g42dav Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by Iván González
1 year, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/03/2024
Status: Active
Attachments: No files
Logo Logo
Loading...