Exit in given timeframe

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #130044 quote
    gkozmagkozma
    Participant
    New

    Hi All,

    Can anyone help with a coding question?  I would like the also to exit the position after a certain time, ie on the 5 minutes chart, i would like the position to close 20 minutes after entry.

     

    thank you

    #130055 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    20 minutes is 4 bars, si you can write:

    IF BarIndex >= (TradeIndex + 4) THEN
       SELL      AT MARKET
       EXITSHORT AT MARKET
    ENDIF
    Juan Salas and gkozma thanked this post
    #130056 quote
    Juan SalasJuan Salas
    Participant
    Master

    Hi Gokzma,

    Remember using the proper forum. ProBuilder is for indicators and ProOrder for strategies. I have already moved your topic to ProOrder. Read the forum rules in case you have any doubt.

    Regarding your question, I attached a piece of code that you can use:

    IF condition AND NOT ONMARKET THEN
    BUY 1 CONTRACT AT MARKET // Once your condition is met, the code will buy at market
    x = barindex // x = number of the candle in which we have opened the operation
    ENDIF
     
    IF barindex = x + n THEN  // n is the number of candles after the opening. Since you are in a 5 m TF, and want to close after 20 m, then n=4
    SELL AT MARKET
    ENDIF

    I hope it is ok,

    Juan

    gkozma thanked this post
    #130057 quote
    Juan SalasJuan Salas
    Participant
    Master

    Roberto,

    You are too fast for me :)))

    #130060 quote
    gkozmagkozma
    Participant
    New

    Much appreciate, apologies for posting it in the wrong forum in the first place.

    #130067 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    @Juan Salas

    it’s good to have two different working approaches!

    #130087 quote
    VonasiVonasi
    Moderator
    Master

    ….and I would have done it like this:

    if barindex - tradeindex = 4 then

    …so that’s three ways.

    robertogozzi and Juan Salas thanked this post
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Exit in given timeframe


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
gkozma @gkozma Participant
Summary

This topic contains 6 replies,
has 4 voices, and was last updated by VonasiVonasi
6 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/05/2020
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...