He creado gráficos basados ​​en un período de tiempo más alto para verlos en un período de tiempo más bajo. sin embargo, no se realizan gráficos cuando cambio a un período de tiempo más bajo, lo que podría ser un error en el código

study(title = "Trading system", shorttitle="TS", overlay =true)
//______________User inputs_________________
_1              = input(title = "═════ Bias Settings ═════",    type = input.bool,          defval = true)
i_resolution    = input(title = "Select Bias Resolution",       type = input.resolution,    defval ="75")


//____________ variables ____________________
var float highValue     = na
var float lowValue      = na
var float bias          = na
string barType          = na


//_____________Calculations
//Assign high low for bias calculations

tfhigh  = security(syminfo.tickerid,expression = high, resolution = i_resolution, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on )
tflow   = security(syminfo.tickerid,expression = low, resolution = i_resolution, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on )

highValue       := tfhigh < highValue[1] and tflow > lowValue[1] ? highValue[1] : tfhigh
lowValue        := tfhigh < highValue[1] and tflow > lowValue[1] ? lowValue[1] : tflow

// Define Bar Types
barType         := highValue > highValue[1] and lowValue > lowValue[1] ? "Up" : highValue < highValue[1] and lowValue < lowValue[1] ? "Down" : highValue > highValue[1] and lowValue < lowValue[1] ? "Out" : "In"

// Generate bias
bias            := barType == "Up" ? highValue : barType == "Down" ? lowValue : barType == "Out" and barType[1] == "Up" ? highValue : barType == "Out" and barType[1] == "Down" ? lowValue : bias[1]

// Bias shift to bullish or bearish
bullishcondition = bias > bias[1] and bias[1] < bias[2]
bearishcondition = bias < bias[1] and bias[1] > bias[2]

// Values to plot
upBias = valuewhen(bullishcondition, bias[1],0)
dnBias = valuewhen(bearishcondition, bias[1],0)
plot(upBias, color = color.green)
plot(dnBias, color = color.red)
0
Animesh Shah 22 ene. 2021 a las 07:17

1 respuesta

La mejor respuesta

Porque estas condiciones siempre son falsas

bullishcondition = bias > bias[1] and bias[1] < bias[2]
bearishcondition = bias < bias[1] and bias[1] > bias[2]

Para asegurarse de esto, colóquelo en el gráfico plot(bias, color = color.blue)

[adicional]

Si entiendo correctamente su comentario, todos los cálculos deben combinarse en una función y llamarse en security

//@version=4
study(title = "Help (Trading system)", shorttitle="TS", overlay =true)
//______________User inputs_________________
_1              = input(title = "═════ Bias Settings ═════",    type = input.bool,          defval = true)
i_resolution    = input(title = "Select Bias Resolution",       type = input.resolution,    defval ="75")


//____________ variables ____________________
// var float highValue     = na
// var float lowValue      = na
// var float bias          = na
// string barType          = na


//_____________Calculations
//Assign high low for bias calculations

bias() =>
    float highValue     = na
    float lowValue      = na
    float bias          = na
    string barType      = na
    // tfhigh  = security(syminfo.tickerid, expression = high, resolution = i_resolution, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on )
    // tflow   = security(syminfo.tickerid, expression = low, resolution = i_resolution, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on )
    
    tfhigh  = high
    tflow   = low

    highValue       := tfhigh < highValue[1] and tflow > lowValue[1] ? highValue[1] : tfhigh
    lowValue        := tfhigh < highValue[1] and tflow > lowValue[1] ? lowValue[1] : tflow
    
    // Define Bar Types
    barType         := highValue > highValue[1] and lowValue > lowValue[1] ? "Up" : highValue < highValue[1] and lowValue < lowValue[1] ? "Down" : highValue > highValue[1] and lowValue < lowValue[1] ? "Out" : "In"
    
    // Generate bias
    bias            := barType == "Up" ? highValue : barType == "Down" ? lowValue : barType == "Out" and barType[1] == "Up" ? highValue : barType == "Out" and barType[1] == "Down" ? lowValue : bias[1]
    
    // Bias shift to bullish or bearish
    bullishcondition = bias > bias[1] and bias[1] < bias[2]
    bearishcondition = bias < bias[1] and bias[1] > bias[2]
    
    // Values to plot
    upBias = valuewhen(bullishcondition, bias[1], 0)
    dnBias = valuewhen(bearishcondition, bias[1], 0)
    [upBias, dnBias]

[up, dn] = security(syminfo.tickerid, expression = bias(), resolution = i_resolution, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on )
plot(up, color = color.green)
plot(dn, color = color.red)
1
AnyDozer 27 ene. 2021 a las 04:54