Please help me reference the variables of my original buy/sell signal

Forums ProRealTime English forum General trading discussions Please help me reference the variables of my original buy/sell signal

Viewing 5 posts - 1 through 5 (of 5 total)
  • #186910

    Hi,

    I am sorry to be asking such a basic question. I am having trouble from the manual and training courses on solving this.

    Let’s say some variables and criteria have been met for me to initiate a long position at time T.

    I would like to be able to add to that position and average down if the price falls any time after T.

    The most I could gather was that you can only reference data from “n” units in the past.

    Since the number of candles past since T is dynamic, I want to be able to define and “anchor” the values of the first buy signal to reference later.

    Thank you so much for your help. I promise I will be better than this one day!

     

    <style class=”dark-mode–filters”></style>

     

    #186913

    Hey @lucfral,

     

    I want to be able to define and “anchor” the values of the first buy signal to reference later.

    Any variable you declare a first time with ONCE, you can reference later. For example :

    Preserving the price can be done in other (more formal and direct) ways too, but this is literally what you ask for and very useful in PRT coding in general.
    If you would leave out the keyword ONCE then you would not be able to refer to BuyPrice in later calls of your code unless you would know how many bars ago you obtained a position the last time (and these are the more formal and direct means, all working with [n] one way or the other, n being a number of bars back).

    Have fun with it all !
    Peter

    1 user thanked author for this post.
    #186926

    This version makes sure BuyPrice is not overwritten at each additional entry:

     

    1 user thanked author for this post.
    #186942

    Thank you both so much for your help It really means a lot.

    Is there any way to create an IF statement based on the number of open contracts/position size?

    Eg IF number of contracts/shares open is a certain amount or within some range, do or don’t do some other thing.

    I looked through the glossary and it doesn’t appear that there is a code for this.

    Thanks again!

     

    #186950

    CountOfPosition returns the number of contracts/lots traded (positive for Long trades, such as 3, negative for Short trades, such as -3).

    Using ABS(CountOfPosition) makes both positive. You may also use CountOfLongShares and CountOfSnborgtShares, but I prefer CountOfPosition .

    Example:

     

     

Viewing 5 posts - 1 through 5 (of 5 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login