Code for "close trade after 20 candles"

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #90965 quote
    Nick FX Junkie
    Participant
    Average

    Good Evening All,

    I’m currently working on a coding strategy and I want the automation to close the trade on the 21st candle (after 20 candles).

    Can someone please assist me with codes for closing both long and or short trades after 20 candles. (whichever trade is open at the time long or short, not simultaneous)

    Any assistance would be greatly appreciated.

    Cheers,

    Nick

    #90968 quote
    Vonasi
    Moderator
    Master

    Welcome to the forums. I have moved your topic to the ProOrder forum as that is the correct place for strategy questions. You posted in the ProBuilder forum which is for indicator questions. Please try to post in the correct forum with any future topics to ensure you are posting in the best place to find your answers. 🙂

    #90969 quote
    Vonasi
    Moderator
    Master

    The index of the candle that you last entered a trade on is stored as TRADEINDEX and the current candle is BARINDEX. So if BARINDEX minus TRADEINDEX = 20 then 20 candles have passed.

    In ProOrder it is not possible to have a short and a long position open in a strategy simultaneously.

    Try something like this:

    if onmarket and barindex - tradeindex >= 20 then
    sell at market
    exitshort at market
    endif
    Bel and Nick FX Junkie thanked this post
    #91566 quote
    Nick FX Junkie
    Participant
    Average

    Legend… Thank you so much!

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

Code for "close trade after 20 candles"


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Nick FX Junkie
7 years ago.

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