Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Multi Instrument Indicator - OnBarUpdate problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Multi Instrument Indicator - OnBarUpdate problem

    I am writing a correlation indicator for 2 instruments. I am confused on how onBarUpdate is called. I have declared my instruments as below and added print statements for output.
    I expected, to get 1 minute values from each instrument one after another. the output sample is on the bottom. Looks like NQ output and ES are not in sync. What am I missing. How can I get the minute bars of NQ and ES one after each other? How can 4 minutes of NQ come before the first minute of ES? Is CurrentBar representing each minute?



    protected override void Initialize()
    {


    Add(FirstInstrument,PeriodType.Minute,1); // Closes[1] = BarsInProgressIndex() /ES
    Add(SecondInstrument,PeriodType.Minute,1); // Closes[2] = BarsInProgressIndex() /NQ
    }

    protected override void OnBarUpdate()
    {


    if (BarsInProgress == 0)
    Print("ES " + CurrentBar);

    if (BarsInProgress == 1)
    Print("NQ " + CurrentBar);

    }

    --------------------------------------
    NQ 0
    NQ 1
    NQ 2
    NQ 3
    ES 0
    NQ 4
    NQ 5
    NQ 6
    NQ 7
    NQ 8
    ES 1
    NQ 9
    NQ 10
    NQ 11
    NQ 12
    NQ 13
    ES 2
    NQ 14
    NQ 15
    NQ 16
    NQ 17
    NQ 18
    ES 3
    NQ 19
    NQ 20
    NQ 21
    NQ 22
    NQ 23
    ES 4
    NQ 24
    NQ 25
    NQ 26
    NQ 27
    NQ 28
    ES 5
    NQ 29
    NQ 30
    NQ 31
    NQ 32
    NQ 33
    ES 6
    NQ 34
    NQ 35
    NQ 36
    ES 7
    NQ 37
    NQ 38
    NQ 39
    ES 8
    NQ 40
    NQ 41
    NQ 42
    NQ 43
    NQ 44
    ES 9
    NQ 45
    NQ 46
    NQ 47
    NQ 48
    NQ 49
    ES 10
    NQ 50
    NQ 51
    NQ 52
    NQ 53
    NQ 54
    ES 11
    NQ 55
    NQ 56
    NQ 57
    NQ 58
    NQ 59
    ES 12
    NQ 60
    NQ 61
    NQ 62
    NQ 63
    NQ 64
    ES 13
    NQ 65
    NQ 66
    NQ 67
    NQ 68
    NQ 69
    ES 14
    NQ 70
    NQ 71
    NQ 72
    NQ 73
    NQ 74
    ES 15
    NQ 75
    NQ 76
    NQ 77
    NQ 78
    ES 16
    NQ 79
    NQ 80
    NQ 81
    NQ 82
    NQ 83
    ES 17
    NQ 84
    NQ 85
    NQ 86
    NQ 87
    NQ 88
    ES 18
    NQ 89
    NQ 90
    NQ 91
    NQ 92
    NQ 93
    ES 19
    NQ 94
    NQ 95
    NQ 96
    NQ 97
    NQ 98
    ES 20
    NQ 99
    NQ 100

    #2
    Hello afshinmoshrefi, how did you generate the printout? From backtesting or realtime monitoring the script? What is the primary instrument you run here? You add 2 instruments, and since indexes are 0 based you would then access them with BarsInProgress 1 + 2, not 0 + 1.

    A correlation indicator for NT7 is already done by one of our forums members and available in the sharing section for your use and review :

    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ZenCortexAuCost, Today, 04:24 AM
    0 responses
    5 views
    0 likes
    Last Post ZenCortexAuCost  
    Started by ZenCortexAuCost, Today, 04:22 AM
    0 responses
    2 views
    0 likes
    Last Post ZenCortexAuCost  
    Started by SantoshXX, Today, 03:09 AM
    0 responses
    15 views
    0 likes
    Last Post SantoshXX  
    Started by DanielTynera, Today, 01:14 AM
    0 responses
    3 views
    0 likes
    Last Post DanielTynera  
    Started by yertle, 04-18-2024, 08:38 AM
    9 responses
    42 views
    0 likes
    Last Post yertle
    by yertle
     
    Working...
    X