count of bars

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #76105 quote
    immo_vienna
    Participant
    Average

    hi guys,

    i want to count the bars – and exit the market after 16 days /bars.

    i know there is

    if onmarket and barindex-tradeindex > 15 then
    sell at market
    endif

    but i dont like to use barindex – because it depends on when u started a system or on the chart.

    so i am looking for another try like

     

    N=summation[15]
    
    if onmarket and n>15 then
    sell at market
    endif

    is this possible? i just want to exit after x days/bars

    #76107 quote
    Vonasi
    Moderator
    Master

    I do not understand what the issue is with:

    if onmarket and barindex-tradeindex > 15 then

    ….as it works perfectly in all situations for counting how many bars you have been on the market for. When the chart data started is irrelevant as BARINDEX and TRADEINDEX are just a filing system that gives a bar a numerical label.

    I guess you could try something like:

    if summation[15](countofposition <> 0) = 15 then
    sell at market 
    endif

    Not tested and as I say I do not understand why you are trying to re-invent the wheel.

    immo_vienna thanked this post
    #76157 quote
    immo_vienna
    Participant
    Average

    @vonasi – thx for ur quick reply i really thank u!

    // Bedingungen zum Ausstieg von Short-Positionen
    yy1 = (close < average[10](close)-std[20](close)) // hier ggf. auch + und close[1]
    yy2 = (close < close[1])
    yy3 = barindex-tradeindex >= 15
    yy4 = positionperf <= 0
    yy = yy1 and yy2 or yy3 or yy4
    
    if yy then
    exitshort at market
    endif

    i did that at yy3 – but now i get 16 bars – so thats what i meant…. 🙁

    #76163 quote
    Vonasi
    Moderator
    Master

    The decision to close it is made at the close of the 15th bar but the close does not happen until the open of bar 16 I’m guessing.

    #76165 quote
    immo_vienna
    Participant
    Average

    hmm thx think thats right – automated trading is at close.. so could be the 16th to exit….

    yy4 = positionperf(close[1]) <= -1

    do u think thats right? i want to say:

    if the profit of the open trade is negative since the bar before, system has to sell this order…

    #76166 quote
    robertogozzi
    Moderator
    Master

    mmo_vienna, your code

    N=summation[15]
     
    if onmarket and n>15 then
    sell at market
    endif

    will never be true (also, SUMMATION lacks what it has to SUM) since N will never be > 15, as you wrote 15 within brackets!

    #76167 quote
    immo_vienna
    Participant
    Average

    yes thats true.. tried some things but dont work :S

    #76168 quote
    Vonasi
    Moderator
    Master

    if the profit of the open trade is negative since the bar before, system has to sell this order…

     

    yy4 = close[1] > positionprice and close < close[1]
    immo_vienna thanked this post
    #76169 quote
    immo_vienna
    Participant
    Average

    thx for this!

    but i get negative results :/

    17-07-_2018_19-26-21.png 17-07-_2018_19-26-21.png
    #76171 quote
    Vonasi
    Moderator
    Master

    but i get negative results :/

    You provide the questions – the answers can not always be guaranteed to be profitable! 🙂

    #76172 quote
    immo_vienna
    Participant
    Average

    haha yes but shouldn’t the order been closed when i have this code? if profit ist negative then…

    #76173 quote
    Vonasi
    Moderator
    Master

    Not if on the last bar it was in profit and then on this bar it fell back again into a loss.

    #76175 quote
    immo_vienna
    Participant
    Average

    so if i want to say if order is negative and stays negative the next bar i have to write it in a loop right?

    #76176 quote
    Vonasi
    Moderator
    Master

    I’m not certain of what you are trying to achieve. Maybe this?

    yy4 = close[1] > positionprice and close < close[1] and close > positionprice
    #76177 quote
    immo_vienna
    Participant
    Average

    i want to say:

    if my open order is negative -€ since 2 bars or more than -100€ the system must sell this order and buy in other direction

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

count of bars


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 15 replies,
has 3 voices, and was last updated by Vonasi
7 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/17/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...