Variation from candle high to low and low to high

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #61568 quote
    jbyrnejbyrne
    Participant
    Average

    Hi,

    I can’t find out how to use the ‘variation’ function to start counting from the candle high, and stop at the candle low and vise versa.

    I want to measure the price difference between a candle high and another candles low(or vise versa) over a period of time. I have been using the summation function as well to do this. Here’s the line of code that I’m using for context if needed;

    RISE = 0
    FOR y = 2 to 120 DO
    if (summation[y](Variation(close))>=1) THEN
    RISE = RISE + 1
    ELSE
    BREAK
    ENDIF
    
    NEXT
    
    FALL = 0
    FOR y = 2 to 120 DO
    if (summation[Y](Variation(close))>=-1) THEN
    FALL = FALL + 1
    ELSE
    BREAK
    ENDIF

     

    Thanks in advance

    #61569 quote
    NicolasNicolas
    Keymaster
    Legend

    You have mixed 2 different ways to make your calculation. However, I don’t understand the code you made because of your RISE and FALL variables? Do you only want to know the price distance in percentage between 2 bars or counting how many times the price has ascended and declined?

    #61570 quote
    jbyrnejbyrne
    Participant
    Average

    The code that’s shown is just code I’ve put together myself using examples found in the PRT documentation. I would actually like for the code to return the distance between high and low but don’t know how to do that either. So just ignore the RISE and FALL, I only put the code in the post incase it wasn’t clear what I was talking about.

    #61579 quote
    NicolasNicolas
    Keymaster
    Legend

    Ok, so the variation between two Closes could be programmed as follows:

    var = (high[1]-low[120])/close*100

    It measures the distance in percentage between the High of the previous bar to the Low of the 120th one before the current period.

    jbyrne thanked this post
    #61591 quote
    jbyrnejbyrne
    Participant
    Average

    okay, so do I have to repeat that line for every possible amount of periods? Since 120 periods is a maximum amount of time, not a required amount

    #61592 quote
    NicolasNicolas
    Keymaster
    Legend

    Yes, if you want to get other variations, just change the periods under brackets.

    jbyrne thanked this post
    #61593 quote
    jbyrnejbyrne
    Participant
    Average

    I better start copy pasting then! But before I do, how can I get it so that a position is opened once half of the distance from high to low is reached? So then my system is complete and I don’t have re-do all 240 different cases in the near future.

    #61649 quote
    jbyrnejbyrne
    Participant
    Average

    I used the code you just gave me and I doesn’t seem to work. The code runs but doesn’t work as intended, any ideas why?

    defparam CUMULATEORDERS = false
    
    IF (CurrentTime >= 150000) THEN
    Sleep = 1
    ELSE
    Sleep = 0
    ENDIF
    
    IF (CurrentTime = 160000) THEN
    EOD = 1
    ELSE
    EOD = 0
    ENDIF
    
    IF (CurrentTime < 083000) THEN
    WakeUp = 1
    ELSE
    WakeUp = 0
    ENDIF
    
    If (WakeUp = 0) and (Sleep = 0) THEN
    TTime = 1
    ELSE
    TTime = 0
    ENDIF
    
    RISE = 0
    FOR y = 2 to 120 DO
    if ((high[1]-low[y])/close*100)> 0.01 THEN
    RISE = RISE + 1
    ELSE
    BREAK
    ENDIF
    next
    
    FALL = 0
    FOR y = 2 to 120 DO
    if ((low[1]+high[y])/close*100)> 0.01 THEN
    FALL = FALL + 1
    ELSE
    BREAK
    ENDIF
    next
    
    Percentage = 3
     
    Bull = close > (DClose(1) * (1 + (Percentage/100)))
    Bear = close < (DClose(1) * (1 - (Percentage/100)))
    
    IF BULL and FALL and TTime = 0 THEN
    BUY 1 Contract AT Market
    ENDIF
     
    IF BEAR and RISE and TTime = 0 THEN
    SELLSHORT 1 Contract AT Market
    ENDIF
    
    IF EOD and Longonmarket then
    sell at market
    endif
    
    If EOD and Shortonmarket then
    sellshort at market
    endif
    
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Variation from candle high to low and low to high


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jbyrne @jbyrne Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by jbyrnejbyrne
8 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/05/2018
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...