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

Combine Strategies

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

    Combine Strategies

    What is wrong? This strategy gives no signals. Thanks for your help.






    int Variable0=0;
    int Variable1=0;
    int Variable2=0;
    int Variable3=0;
    int Variable4=0;
    int Variable5=0;
    int Variable6=0;
    int Variable7=0;
    int Variable8=0;
    int Variable9=0;


    ///<summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    ///</summary>
    protectedoverridevoid Initialize()
    {
    CalculateOnBarClose = true;
    }

    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Add a 30 minute Bars object to the strategy
    Add(PeriodType.Minute, 30); // BarsArray[1]

    // Add a 45 minute Bars object to the strategy
    Add(PeriodType.Minute, 45); // BarsArray[2]

    // Add a 60 minute bar object to the strategy
    Add(PeriodType.Minute, 60); // BarsArray[3]

    // Condition set 1
    if (SMA(BarsArray[3],RSI(6, 0).Avg, 3)> SMA(BarsArray[3],RSI(6, 0).Avg, 8))
    {
    Variable0 = 1;
    }

    // Condition set 2
    if (SMA(BarsArray[3],RSI(6, 0).Avg, 3)< SMA(BarsArray[3],RSI(6, 0).Avg, 8))
    {
    Variable0 = -1;
    }

    // Condition set 3
    if (SMA(BarsArray[2],RSI(10, 0).Avg, 4)> SMA(BarsArray[2],RSI(10, 0).Avg, 10))
    {
    Variable1 = 1;
    }

    // Condition set 4
    if (SMA(BarsArray[2],RSI(10, 0).Avg, 4)< SMA(BarsArray[2],RSI(10, 0).Avg, 10))
    {
    Variable1 = -1;
    }


    Variable9=(Variable1+Variable2+Variable3+Variable4 );

    if(Variable9>1)
    {
    EnterLong(1, "DO-LONG");
    }

    if(Variable9<-1)
    {
    EnterShort(1, "DO-SHORT");
    }
    }




    #2
    Hello gp18089,

    Welcome to the NinjaTrader Support Forums!

    To start you would want to move the Add() method into the Intialize since it can only be called inside Intialize. You will receive an error in the Log tab when calling Add() in OnBarUpdate(). See the following link to our Help Guide for more information about Multi-Time Frame and Instruments.

    http://www.ninjatrader.com/support/helpGuides/nt7/index.html?multi_time_frame__instruments.htm

    Another thing that I see as well is that you are passing 3 arguments into the SMA when it will only handle either 1 or 2 arguments. With the two arguments parameters being that first is a Data Series which BarsArray is, but the second has to be a "int" or integer and the RSI().Avg is going to be a Data Series. Although you can use the brackets [] to return a double, you would not be able to directly pass it to the SMA in a double state.

    http://www.ninjatrader.com/support/h...simple_sma.htm

    If you are trying to check the value of the number of bars ago the value is you would want to use the brackets [] option for example:

    Code:
    if (SMA(BarsArray[3],14)[3] > SMA(BarsArray[3],14)[8])
    Here is a link to our forum that goes over how to use brackets that you may read.
    http://www.ninjatrader.com/support/f...ad.php?t=19346

    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thank you. I try to use barsinprogress instread bars array but i have another problem. I can see my strategy at edit script but not at strategy analyzer. Any ideas?

      Comment


        #4
        Hello gp18089,

        Can you confirm that your code can compile by right clicking inside the NinjaScript editor and select Compile?


        Happy to be of further assistance.
        JCNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sdauteuil, 09-23-2021, 10:16 AM
        7 responses
        1,247 views
        0 likes
        Last Post marcus2300  
        Started by sofortune, 05-18-2024, 11:48 AM
        2 responses
        32 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by Zach55, 02-19-2024, 07:22 PM
        2 responses
        66 views
        0 likes
        Last Post lbadisa1  
        Started by JGriff5646, Yesterday, 05:47 PM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by AlphaOptions, 06-18-2013, 08:24 AM
        9 responses
        2,203 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X