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
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?
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.
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.
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
Yes, if you want to get other variations, just change the periods under brackets.
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.
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