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

Using a secondary instrument as a filtering criteria possible?

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

    Using a secondary instrument as a filtering criteria possible?

    I would like to use two instruments to trigger a signal.

    Like this:

    If the main instrument short MA is above the main instrument longer MA and secondary instrument short MA is above longer MA create a signal
    Code:
    if
    			(
    				SMA(5)[0] > SMA(10)[0] 
    				[B]&&
    				"SMA(5)[0] > SMA(5)[0]"[/B]
    			)
    			{
    				DrawArrowUp("arrow"+CurrentBar, true, 0, Low[0]-ATR(10)[0]*2, Color.Green);
    
    			}
    where "SMA(5)[0] > SMA(5)[0]" would be based on a secondary instrument like ^DJIA (Dow Jones Industrial Average).

    Is this possible? Tried to look around, but couldn't quite find a post about this kind of a coding. So, any hints appreciated Thank you!

    #2
    MickeyHR, yes that would be possible in a MultiSeries script. You can Add() in another instrument in your script's Initialize() method -



    So lets say you want to add in a 5 minute DJIA index series -

    Add("^DJIA", PeriodType.Minute, 5);

    You can then access this symbol via passing the correct BarsArray to your second SMA statement.

    && SMA(BarsArray[1], 5)[0] > SMA(BarsArray[1], 10)[0]

    You want then to also add in a BarsInProgress check to filter for which bars object OnBarUpdate() call this condition should be evaluated - http://www.ninjatrader.com/support/h...inprogress.htm
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,967 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    4 views
    0 likes
    Last Post rbeckmann05  
    Started by rhyminkevin, Today, 04:58 PM
    4 responses
    55 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Started by iceman2018, Today, 05:07 PM
    0 responses
    6 views
    0 likes
    Last Post iceman2018  
    Started by lightsun47, Today, 03:51 PM
    0 responses
    8 views
    0 likes
    Last Post lightsun47  
    Working...
    X