Coding 5 consecutive higher close

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #238524 quote
    jespermort
    Participant
    New

    Hi everyone!

    I am very new to coding algos for use in prorealtime and I was wondering if someone could help me with a simple question:

    I want to define a requirement to enter trades for example that in order to go long on market the close of all 5 previous bars has to be higher than the previous bar, e.g.

    if close[0]>close[1]>close[2]>close[3]>close[4]>close[5] then 
      buy 1 contract at market
    endif

    What would be the proper way to code this?

    Thanks a lot!

    Kind regards

    #238525 quote
    JC_Bywan
    Moderator
    Master

    Hi,

    for each close higher than previous close 5 times in a row, the long and boring way would be:

    if close>close[1] AND close[1]>close[2] AND close[2]>close[3] AND close[3]>close[4] AND close[4]>close[5] then

     

    but you may write it faster with:
    if summation[5](close>close[1])=5 then

     

    Moderation points:

    – please take into account forum usage highlighted in yellow box at bottom of current page, in this particular case title choice (in order to avoid all ropics in the forum named “help needed”), thanks. I’ll edit your title to replace the “coding help…” with something telling readers about the actual content to decide opening it or not. For example: “coding 5 consecutive higher close” (unless the query itself was misunderstood).

    – also moving topic from probuilder forum (indicators) to proorder forum (backtests and automatic strategies sending orders)
    Iván González thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Coding 5 consecutive higher close


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jespermort @jespermort Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by JC_Bywan
1 year, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/05/2024
Status: Active
Attachments: No files
Logo Logo
Loading...