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

CrosssAbove Syntax

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

    CrosssAbove Syntax

    This should be a pretty easy one.

    At the bottom of the post is the help content for CrossAbove or CrossBelow. I am using it to create dynamic Stop Losses that update based on a few parameters.

    Using the first Syntax listed below, the following should work:

    Syntax

    CrossAbove(IDataSeries series1, double value, int lookBackPeriod)

    or in my case, here is a toy version of my code:

    double stopPrice2 = 75.00
    CrossAbove(Closes[2][0], stopPrice2, 10)


    This syntax generates the following errors:

    The best overloaded method match for 'NinjaTrader.Strategy.StrategyBase.CrossAbove(doub le, NinjaTrader.Data.IDataSeries, int)' has some invalid arguments


    Argument '2': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries'
    Any thoughts here?

    Regards,

    Andrew

    Help Content:


    PHP Code:
    Method Return Value

    This method returns true 
    if a cross above condition occuredotherwisefalse.


    Syntax
    CrossAbove
    (IDataSeries series1double valueint lookBackPeriod)
    CrossAbove(IDataSeries series1IDataSeries series2int lookBackPeriod)
     

    Parameters

    lookBackPeriod
     Number of bars back to check the cross above condition
     
    series1 
    series2
     Any DataSeries type object such 
    as an indicatorCloseHighLowetc...
     
    value
     Any double value
     

     

     

    Examples

    // Go short if CCI crossed above 250 within the last bar
    if (CrossAbove(CCI(14), 2501))
        
    EnterShort();

     

    // Go long if 10 EMA crosses above 20 EMA within the last bar
    if (CrossAbove(EMA(10), EMA(20), 1))
        
    EnterLong();

     

    // Go long we have an up bar and the 10 EMA crosses above 20 EMA within the last 5 bars
    if (Close[0] > Open[0] && CrossAbove(EMA(10), EMA(20), 5))
        
    EnterLong(); 

    #2
    Hello Andrew,
    Closes[2][0] will return a double and not a data series. Please try using the below code and see if you are able to compile the code.

    Code:
    CrossAbove(Closes[2], stopPrice2, 10)
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Of course. I dont even have to check.

      I feel silly.

      TY again Joydeep.

      Regards,

      Andrew

      Edit: And yes, of course it worked

      Comment


        #4
        Originally posted by alabell View Post
        This should be a pretty easy one.

        At the bottom of the post is the help content for CrossAbove or CrossBelow. I am using it to create dynamic Stop Losses that update based on a few parameters.

        Using the first Syntax listed below, the following should work:

        Syntax

        CrossAbove(IDataSeries series1, double value, int lookBackPeriod)

        or in my case, here is a toy version of my code:

        double stopPrice2 = 75.00
        CrossAbove(Closes[2][0], stopPrice2, 10)



        This syntax generates the following errors:



        Any thoughts here?

        Regards,

        Andrew

        Help Content:


        PHP Code:
        Method Return Value
         
        This method returns true 
        if a cross above condition occuredotherwisefalse.
         
         
        Syntax
        CrossAbove
        (IDataSeries series1double valueint lookBackPeriod)
        CrossAbove(IDataSeries series1IDataSeries series2int lookBackPeriod)
         
         
        Parameters
         
        lookBackPeriod
         Number of bars back to check the cross above condition
         
        series1 
        series2
         Any DataSeries type object such 
        as an indicatorCloseHighLowetc...
         
        value
         Any double value
         
         
         
         
         
         
        Examples
         
        // Go short if CCI crossed above 250 within the last bar
        if (CrossAbove(CCI(14), 2501))
            
        EnterShort();
         
         
         
        // Go long if 10 EMA crosses above 20 EMA within the last bar
        if (CrossAbove(EMA(10), EMA(20), 1))
            
        EnterLong();
         
         
         
        // Go long we have an up bar and the 10 EMA crosses above 20 EMA within the last 5 bars
        if (Close[0] > Open[0] && CrossAbove(EMA(10), EMA(20), 5))
            
        EnterLong(); 
        Closes[2][0] is a double: the DataSeries is Closes[2]

        Comment


          #5
          Ty too Koganam, any thoughts on the other "project"?

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by andrewtrades, Today, 04:57 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          3 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X