Barindex – tradeindex trailing stop

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #161997 quote
    Albaran
    Participant
    Average

    Hi there,

    I’m having trouble visualizing how to code a longstop using the following line of code:

    Longstop = average[barindex - tradeindex](close)

    In this example, the system will stop immediately because the indicator has received a parameter that isn’t a number (that’s what PRT says even though I’m not sure to understand this.)

    Be that as it may, to thwart this, I simply modified the previous line of code like this:

    Longstop = average[barindex + 1 - tradeindex](close)

    Now the question that I’m asking myself is whether I need to update the close into Close[1] so as to include the close at the moment I’m in the market in my longstop?

    Because BarIndex has been artificially advanced, does that mean that I have to go back further in time in order for the longstop to take into consideration the close at the moment I’m in the market?

    I would assume so but I’d like a second opinion! Thanks for getting back to me, would be much appreciated!

    #162011 quote
    robertogozzi
    Moderator
    Master

    In your first example at extremes barindex tradeindex can be 0 (which returns an error) or a huge number (such as 1450 or 21716,…).

    In your second example, say barindex= 280 and tradeindex=275, the difference is 6, that is CLOSE[0] (which is barindex 280) through CLOSE[5] (which is barindex  275), so you do NOT need to use [1] next to CLOSE.

    #162014 quote
    Albaran
    Participant
    Average

    I forgot to mention that the longstop also needs to kick in at the very next bar I’m in the market – like a normal stop behavior sort to speak! Does that change anything?

    #162018 quote
    robertogozzi
    Moderator
    Master

    No, it doesn’t, since BARINDEX will increase and the result of the expression will, as well. Nothing changes!

    Albaran thanked this post
    #162022 quote
    Albaran
    Participant
    Average

    Okay, thanks a lot! I guess i got confused because of the addition of that +1 constant 🙂

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

Barindex – tradeindex trailing stop


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Albaran @albaran Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Albaran
5 years ago.

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