Problem with time 1 minute and request.security

32 views Asked by At

I wanted to know why when I want to see the crossover and crossunder that occurred in the 4-hour timeframe in the 1-minute timeframe, it is not displayed in the table for the symbol related to the 4-hour timeframe, but conversely, I can see the crossover in the 1-minute timeframe in the 4-hour timeframe.

Please, if you have any information, I would appreciate your help. Thank you.

See a picture of my problem

input_daily = input.timeframe("1", "Daily Time Frame")
input_mine = input.timeframe("240", "Daily Time Frame")
// 
isBullish(timeframe) =>
    s1 = ta.crossover(periodLine103, periodLine216)
    s2 = ta.crossunder(periodLine103, periodLine216)
    crossoverResult = request.security(syminfo.tickerid, timeframe, s1) 
                       and not request.security(syminfo.tickerid, timeframe, s2)
    crossoverResult

// 
isBearish(timeframe) =>
    s1 = ta.crossover(demo1, demo2)
    s2 = ta.crossunder(demo1, demo2)
    crossunderResult = request.security(syminfo.tickerid, timeframe, s2) 
                         and not request.security(syminfo.tickerid, timeframe , s1)
    crossunderResult


tsmeee = isBullish(input_daily)
tsmeee1 = isBearish(input_daily)
TM240 = isBullish(input_mine)
TM1240 = isBearish(input_mine)

var table myTable = table.new(position = position.top_right, columns = 30, rows = 3, bgcolor = #e1e1e1, frame_color = #191919, frame_width = 1, border_width = 1, border_color = #232323)
table.cell(myTable, column = 1, row = 0, text = "1")
table.cell(myTable, column = 2, row = 0, text = "240")

table.cell(myTable, column = 0, row = 0, text = "time", bgcolor = #f0f0f0)
table.cell(myTable, column = 0, row = 1, text = "cross", bgcolor = #f0f0f0)


if tsmeee
    table.cell(myTable, column=1, row=1, text="▲", text_color=color.rgb(26, 178, 59))
else if tsmeee1
    table.cell(myTable, column=1, row=1, text="▼", text_color=color.rgb(151, 17, 17))


if TM240
    table.cell(myTable, column=2, row=1, text="▲", text_color=color.rgb(26, 178, 59))
else if TM1240
    table.cell(myTable, column=2, row=1, text="▼", text_color=color.rgb(151, 17, 17))

1

There are 1 answers

0
karatedog On

There is no magic, the 1 minute timeframe has simply more granularity.

Crossover checks a previous value-pair and a current value-pair, and that's it. If the values in those value-pairs have swapped place (like: prev. low is now higher than prev high), that's a crossover.

If you look at a single candle, you can see when the Open and Close price happened however you cannot see how the price moved intrabar. Maybe it's the High that was reached first, then Low, or the opposite.

Based on this, your conditions might trigger with a different result or in a different order in a lower timeframe. Just imagine you have a Stop Loss and a Take Profit set up, then the next candle goes over both. Depending on which was reached first, you either win or lose the trade.