Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problems with mltframe strategy development

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

    Problems with mltframe strategy development

    Hello i make a simple system:


    BUY:
    on 240 m tf :when stochastics 3,9,3.K > stochastics 3,9,3.D
    then on 15m TF when stochastics 3,9,3 crosses above 20 then buy

    SELL:
    on 240 m tf :when stochastics 3,9,3.K < stochastics 3,9,3.D
    then on 15m TF when stochastics 3,9,3 crosses below 80 then sell

    I read online help guide, but my strategy does not work correctly. Can you write me , it is my code right? (check an attach)


    protected override void Initialize()
    {
    SetProfitTarget("", CalculationMode.Ticks, Profit);
    SetStopLoss("", CalculationMode.Ticks, Loss, false);
    Add(PeriodType.Minute, 15);
    Add(PeriodType.Minute, 240);
    Add(Stochastics(3,9,3));


    CalculateOnBarClose = false;

    .
    .
    .
    .
    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 1)
    // Condition set 1
    if (CrossAbove(Stochastics(BarsArray[0],3, 9, 3).K, 20, 1) && Stochastics(BarsArray[1],3,9,3).K[1] > Stochastics(BarsArray[1],3,9,3).D[1]);
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (CrossBelow(Stochastics(BarsArray[0],3, 9, 3).K, 80, 1) && Stochastics(BarsArray[1],3,9,3).K[1] < Stochastics(BarsArray[1],3,9,3).D[1]);
    {
    EnterShort(DefaultQuantity, "");
    }
    }

    in attach is a screenshot


    THANX for help
    Attached Files
    Last edited by dedomraz; 11-18-2008, 07:04 AM. Reason: not important mistake with ()

    #2
    Hello,


    Your BarsInProgress == 1 block should only contain conditions that apply to the first Add()'d timeframe. In your case the 15 minute timeframe.

    BarsInProgress == 2 should only have conditions for the 240 timeframe in your case.

    Note the order that you Add() the new timeframes matters.

    Try something like this:

    protected override void OnBarUpdate()
    {
    //-------------------------------------------------------
    if (BarsInProgress == 1)
    {
    if (CrossAbove(Stochastics(3, 9, 3).K, 20, 1))
    {
    buy_15min = true;
    }
    if (CrossBelow(Stochastics(3, 9, 3).K, 80, 1))
    {
    sell_15min = true;
    }
    } //ends the 15 min TF
    //-----------------------------------------------------------
    if (BarsInProgress == 2)
    {
    if (Stochastics(3,9,3).K[1] > Stochastics(3,9,3).D[1]))
    {
    buy_240min = true;
    }
    if (Stochastics(3,9,3).K[1] < Stochastics(3,9,3).D[1]))
    {
    sell_240min = true;
    }
    }//ends the 240 min TF
    //--------------------------------------------------
    if(BarsInProgress == 0)
    {
    if(buy_15min && buy_240min)
    {
    EnterLong(DefaultQuantity, "");
    }
    if(sell_15min && sell_240min)
    {
    EnterShort(DefaultQuantity, "");
    }
    } //ends the TF you have the strategy attached to
    }//closes OnBarUpdate()

    Alternatively, if you want to use the BarsArray[], you should use [1] and [2], and not [0] and [1].

    This code is untested. Please be aware that you will need to add code to reset the buy and sell bool flags to false somewhere, otherwise this code will not work.
    DenNinjaTrader Customer Service

    Comment


      #3
      OK

      OK man, Thanks much , today evening i will test you idea and tomorrow i will respond.

      One more Thanx!!

      Comment


        #4
        solution

        Hello,

        Sorry for my later response,but i havent time.

        So Ben, you gave me 2 solutions.

        First, with using BarArray works perfect

        Here is a valid code:

        protected override void Initialize()
        {
        Add(Stochastics(3, 9, 3));
        SetProfitTarget("", CalculationMode.Ticks, Profit);
        SetStopLoss("", CalculationMode.Ticks, Loss, false);
        Add(PeriodType.Minute, 240);
        CalculateOnBarClose = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        if (BarsInProgress == 0)

        // Condition set 1
        if (CrossAbove(Stochastics(3, 9, 3).K, 20, 1) && Stochastics(BarsArray[1], 3,9,3).K[0] > Stochastics(BarsArray[1], 3,9,3).D[0])
        {
        EnterLong(DefaultQuantity, "");
        }

        // Condition set 2
        else if (CrossBelow(Stochastics(3, 9, 3).K, 80, 1) && Stochastics(BarsArray[1], 3,9,3).K[0] < Stochastics(BarsArray[1], 3,9,3).D[0])
        {
        EnterShort(DefaultQuantity, "");
        }
        }


        But second solution doesnt work. Compilator tells that everithings( with code) is ok. But stretegy doesnt makey any trade.

        Heres you idea with bool, but not working


        #region Variables
        // Wizard generated variables
        private int profit = 400; // Default setting for Profit
        private int loss = 200; // Default setting for Loss
        bool buy_15min;
        bool sell_15min;
        bool buy_240min;
        bool sell_240min;

        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {

        Add(PeriodType.Minute, 15);
        Add(PeriodType.Minute, 240);
        Add(Stochastics(3, 9, 3));
        Add(Stochastics(3, 9, 3));
        SetProfitTarget("", CalculationMode.Ticks, Profit);
        SetStopLoss("", CalculationMode.Ticks, Loss, false);


        CalculateOnBarClose = false;


        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {



        if (BarsInProgress == 1) //
        {

        if (CrossAbove(Stochastics(3, 9, 3).K, 20, 1))
        {
        bool buy_15min = true;
        }
        if (CrossBelow(Stochastics(3, 9, 3).K, 80, 1))
        {
        bool sell_15min = true;
        }
        }

        if (BarsInProgress == 2)
        {
        if (Stochastics(3,9,3).K[1] > Stochastics(3,9,3).D[1])
        {
        bool buy_240min = true;
        }
        if (Stochastics(3,9,3).K[1] < Stochastics(3,9,3).D[1])
        {
        bool sell_240min = true;
        }
        }

        if (BarsInProgress == 0)
        {

        if (buy_15min && buy_240min)
        {
        EnterLong(DefaultQuantity, "");
        }
        if (sell_15min && sell_240min)
        {
        EnterShort(DefaultQuantity, "");
        }
        }

        }

        System make any trade. I dont now why.

        I have one question. Is possible that indicator on 240 m TF can use from price data from 15 TF to his own calculation?

        Thanks for help!

        Comment


          #5
          Hello,

          In your variables section declare your bool variables like this:

          private bool buy_15min = false;

          In your OnBarUpdate block do NOT use "bool" in this case. Do this:

          buy_15min = true;
          DenNinjaTrader Customer Service

          Comment


            #6
            Thanks, its work perfectly. Can i have last question?
            It is possible: Stochastics from 240m chart calculates his own value from 15m TF price data??


            Working solution:

            #region Variables
            // Wizard generated variables
            private int profit = 400; // Default setting for Profit
            private int loss = 200; // Default setting for Loss
            private bool buy_15min = false;
            private bool sell_15min = false;
            private bool buy_240min = false;
            private bool sell_240min = false;

            // User defined variables (add any user defined variables below)
            #endregion

            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {

            Add(PeriodType.Minute, 240);
            Add(Stochastics(3, 9, 3));
            Add(Stochastics(3, 9, 3));
            SetProfitTarget("", CalculationMode.Ticks, Profit);
            SetStopLoss("", CalculationMode.Ticks, Loss, false);


            CalculateOnBarClose = true;


            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {




            if (BarsInProgress == 1)
            {
            if (Stochastics(3,9,3).K[1] > Stochastics(3,9,3).D[1])
            {
            buy_240min = true;
            }
            else
            {
            buy_240min = false;
            }
            if (Stochastics(3,9,3).K[1] < Stochastics(3,9,3).D[1])
            {
            sell_240min = true;
            }
            else
            {
            sell_240min = false;
            }
            }
            if (BarsInProgress == 0) //
            {

            if (CrossAbove(Stochastics(3, 9, 3).K, 20, 1))
            {
            buy_15min = true;
            }
            else
            {
            buy_15min = false;
            }
            if (CrossBelow(Stochastics(3, 9, 3).K, 80, 1))
            {
            sell_15min = true;
            }
            else
            {
            sell_15min = false;
            }
            }





            if (BarsInProgress == 0)
            {

            if (buy_15min && buy_240min)
            {
            EnterLong(DefaultQuantity, "");
            }
            if (sell_15min && sell_240min)
            {
            EnterShort(DefaultQuantity, "");
            }
            }

            }

            Comment


              #7
              Hello,

              I am sorry, multi-timeframe indicators are not supported. The will be supported with NT version 7, which does not have a release date yet.
              DenNinjaTrader Customer Service

              Comment


                #8
                Thanks for answer. I really appreciate your support. I think , that the Ninja Trader (solution-program-service-price) has great future!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                576 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                334 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                553 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                551 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X