Page 1 of 1

Cycle Indicator

Posted: Mon Sep 06, 2021 8:42 pm
by Birinni
Hi Guys,

This is my first indicator so, be kind with me... :whoops:


I want to use this indicator into a strategy, but i need to use it with different timframe at the same time.
I don't know how to chage my code for achive the result.

could u help me?

TY


study("Cycle", overlay = false, format=format.price, precision=2, resolution="")


//***************************************************
//* MIDDLE CALCULATIONS *
//***************************************************
//A
KAinput = input (3, title = "A Stoch period")
kA = 100*((close - lowest(low,KAinput)) / (highest(high,KAinput) - lowest(low, KAinput)))
A=sma(kA,5)
//B
KBinput = input (3, title = "B Stoch period")
kB = 100*((close - lowest(low,KBinput)) / (highest(high,KBinput) - lowest(low, KBinput)))
B=sma(kB,14)
//C
KCinput = input (14, title = "C Stoch period")
kC = 100*((close - lowest(low,KCinput)) / (highest(high,KCinput) - lowest(low, KCinput)))
C=sma(kC,45)
//D
KDinput = input (20, title = "D Stoch period")
kD = 100*((close - lowest(low,KDinput)) / (highest(high,KDinput) - lowest(low, KDinput)))
D=sma(kD,75)


//***************************************************
//* INDICATOR FORMULE *
//***************************************************

I=(4.1*A+ 2.5*B+ C + 4*D)/11.6
mm=sma(I,9)

Cycle= I-mm


//***************************************************
//* PLOTS *
//***************************************************

p1=plot(Cycle,color=color.blue)
p2=plot(0, color = color.gray)

fill(p1, p2, color = Cycle > 0 ? color.green : color.red)

Re: Cycle Indicator

Posted: Sun Jan 30, 2022 9:54 pm
by processingclouds
Hey Birinni,

I see you want to add a higher time frame calculation over your current calculation.

I have organized the code into parts and created this in version 5 of pine script.

So now you have the option to plot higher time frame on the chart and also as a bonus i have added that it will plot arrows on the chart when both Higher Time Frame and Current Frame rate are both above 0 line together or below together.

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © processingclouds
// processingclouds@gmail.com

// Extended version of Birinni's Cycle Indicator from forum pinescripters.net

// Supports Higher Time Frame 
// Also plots arrow to show where Higher Time Frame and current Frame are above or below 0 line together

//@version=5
indicator("Extended Birinni Cycle v2.0", overlay = false, format=format.price, precision=2)

//  Inputs {
frame1   = input.string (title="Timeframe", defval="60") // Valid Values are numbers to show minutes and than  D , 3D, 5D, W, 2W, M, 2M and so on
KAinput = input.int (3, title = "A Stoch period")
KBinput = input.int (3, title = "B Stoch period")
KCinput = input.int (14, title = "C Stoch period")
KDinput = input.int (20, title = "D Stoch period")
// - End Inputs }


//  MIDDLE CALCULATIONS {

// Higher Time Frame Values
frm1Close = request.security(syminfo.tickerid, frame1, close)
frm1High = request.security(syminfo.tickerid, frame1, high)
frm1Low = request.security(syminfo.tickerid, frame1, low)

frm1kA = 100*((frm1Close - ta.lowest(frm1Low,KAinput)) / (ta.highest(frm1High,KAinput) - ta.lowest(frm1Low, KAinput)))
frm1kB = 100*((frm1Close - ta.lowest(frm1Low,KBinput)) / (ta.highest(frm1High,KBinput) - ta.lowest(frm1Low, KBinput)))
frm1kC = 100*((frm1Close - ta.lowest(frm1Low,KCinput)) / (ta.highest(frm1High,KCinput) - ta.lowest(frm1Low, KCinput)))
frm1kD = 100*((frm1Close - ta.lowest(frm1Low,KDinput)) / (ta.highest(frm1High,KDinput) - ta.lowest(frm1Low, KDinput)))
frm1A = ta.sma(frm1kA,5)
frm1B = ta.sma(frm1kB,14)
frm1C = ta.sma(frm1kC,45)
frm1D = ta.sma(frm1kD,75)

kA = 100*((close - ta.lowest(low,KAinput)) / (ta.highest(high,KAinput) - ta.lowest(low, KAinput)))
kB = 100*((close - ta.lowest(low,KBinput)) / (ta.highest(high,KBinput) - ta.lowest(low, KBinput)))
kC = 100*((close - ta.lowest(low,KCinput)) / (ta.highest(high,KCinput) - ta.lowest(low, KCinput)))
kD = 100*((close - ta.lowest(low,KDinput)) / (ta.highest(high,KDinput) - ta.lowest(low, KDinput)))
A = ta.sma(kA,5)
B = ta.sma(kB,14)
C = ta.sma(kC,45)
D = ta.sma(kD,75)
// - End Middle Calculations}

//  INDICATOR FORMULE {
I = (4.1 * A + 2.5 * B + C + 4 * D)/11.6
mm = ta.sma(I, 9)
Cycle = I - mm

frm1I=(4.1 * frm1A + 2.5 * frm1B + frm1C + 4 * frm1D)/11.6
frm1mm = ta.sma(frm1I, 9)
frm1Cycle = frm1I - frm1mm
// - End Indicator Formula}

//  PLOTS {
pZero = plot(0, color = color.gray)

// Plot Higher Time Frame1
frm1p1 = plot(frm1Cycle, color=color.black)
fill(frm1p1, pZero, color = frm1Cycle > 0 ? color.purple : color.silver)

// Plot Current Chart TimeFrame
p1 = plot(Cycle, color=color.blue)
fill(p1, pZero, color = Cycle > 0 ? color.green : color.red)

bool barUp = frm1Cycle > 0 and Cycle > 0
bool barDn = frm1Cycle < 0 and Cycle < 0
plotchar(barUp, "Up", "▲", location.top, size = size.tiny)
plotchar(barDn, "Down", "▼", location.bottom, size = size.tiny)
// - End Plots}