Comparing Price as condition

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #229067 quote
    Amin1233
    Participant
    Junior

    Hi I am trying to write a code to compare the price of previous bars and trigger a flag. what is wrong with this condition? It looks like the close[2]>close[3] doesnt return anything and T always become T=1 at 101000.

    If time=100000 then

    T=0

    end if

    If close[2]>close[3] and time>101000 then

    T=1

    Endif

    #229069 quote
    GraHal
    Participant
    Master

    It’s probably easier to say, in text, what you want to achieve?

    close[2]>close[3] doesnt return anything

    Abobe returns boolean logic, i.e. either 0 or 1.

    close[2]>close[3] and time>101000

    When close[2]>close[3] is coincident with time>101000 then T will stay at 1 until the next day at 100000 when T will become 0 for a minimum of 1 minute (until this cycle repeats).

    #229074 quote
    GraHal
    Participant
    Master

    T will become 0 for a minimum of 1 minute

    Above should have read … T will become 0 for a minimum of 10 minutes.

    #229075 quote
    Amin1233
    Participant
    Junior

    I want to have conditions to check if for the last 3 bars the price was closing lower each time and if so then make T=1

    #229079 quote
    GraHal
    Participant
    Master
    T = summation[3](Open>Close)=3
    #229082 quote
    JS
    Participant
    Senior

    If you want to check if the last three “closes” where lower, you can also use the following code…

    Including the current bar:

    Close[0]<Close[1] and Close[1]<Close[2]

    Or excluding the current bar:

    Close[1]<Close[2] and Close[2]<Close[3]

    The code will be (including the current bar):

    If Time>101000 then
    If Close[0]<Close[1] and Close[1]<Close[2] then
    T=1
    Else
    T=0
    EndIf
    EndIf
    
    Return T as "T"
    
    GraHal thanked this post
    Scherm­afbeelding-2024-03-02-om-11.49.11.png Scherm­afbeelding-2024-03-02-om-11.49.11.png
    #229092 quote
    Amin1233
    Participant
    Junior
    when I use the condition in strategy for back testing it doesn’t work. Close[0]<Close[1] and Close[1]<Close[2]  doesn’t return anything  The other formula (summation) also not right because i want to compare the closes, there might be a time when close is lower than open but the close is still higher than the privous bar, i need to compare the close of each bar.
    #229093 quote
    GraHal
    Participant
    Master
    T = summation[3](Close<Close[1])=3
    Above wont ‘return’ anything other than True / 1. But then you might code …
    If T = 1 Then
    SellShort at Market
    Endif
    #229094 quote
    JS
    Participant
    Senior

    Maybe someone else can help you…

    You’re clearly a lot further along when you can judge that the formulas are wrong and not working…

    #229121 quote
    Amin1233
    Participant
    Junior
    Thanks but still not working. I used the below code:
    if time=100000 then
    TL=0
    endif
    TL=summation[3](close<close[1])=3
    
    if time>101000 and time<140000 and TL=1 and countoflongshares<2 and close>open[1] then
    buy 2 contracts at market 
    set stop loss lowest[5]-close+10
    endif
    if longonmarket and close<open[1] then
    sell 2 contracts at market
    endif
    #229122 quote
    JS
    Participant
    Senior

    The code doesn’t work because you’ve taken a strange combination of conditions…

    TL=Summation[3](Close<Close[1])=3 in combination with Close>Open[1]

    Try:

    if time>101000 and time<140000 and TL=1 and countoflongshares<2 then

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

Comparing Price as condition


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Amin1233 @amin1233 Participant
Summary

This topic contains 10 replies,
has 3 voices, and was last updated by JS
1 year, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/02/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...