position time

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #140880 quote
    alex20258alex20258
    Participant
    Average

    Hi everyone,
    I would like to insert in this code, that if after a certain amount of time i’m still in position, it is automatically closed,
    I have tried but have not succeeded until now
    if you can, thank you very much
    Alex

    a=endpointaverage[x] (close)
    
    if a[1]<a then
    alex=200
    endif
    
    if a[1]>a then
    alex=100
    endif
    
    if longonmarket then
    a=1
    endif
    if shortonmarket then
    a=2
    endif
    
    
    if alex crosses over 150 and countofposition=0  then
    exitshort at market
    buy at market
    b= currenttime
    endif
    
    if alex crosses under 150 and countofposition=0 then
    sell at market
    sellshort at market
    b= currenttime
    endif
    
    SET TARGET $PROFIT 10
    SET STOP $LOSS 200
    
    if a=1 and b+010000 = currenttime then
    sell at market
    endif
    
    if a=2 and b+010000 = currenttime then
    exitshort at market
    endif
    
    #140881 quote
    FrancescoFrancesco
    Participant
    Veteran

    Just add this to your code

    if onmarket and (BarIndex - TradeIndex) >=barnumber then
    sell at market
    exitshort at market
    endif

    Insert instead of “bar number” your desired quantity; keeping in mind that based on the timeframe of the strategy you have to calculate how many “bar numbers” you need to preset the position stop.

    i.e.: on a 5min strategy, 5 bar numbers will be equivalent to 25 minutes.

    #140894 quote
    alex20258alex20258
    Participant
    Average

    ok

    Thank you so much

Viewing 3 posts - 1 through 3 (of 3 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

position time


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
alex20258 @alex20258 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by alex20258alex20258
6 years, 2 months ago.

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