Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

3 TimeFrames strategy (1mn, 5mn, 1 day) code check demand

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

    3 TimeFrames strategy (1mn, 5mn, 1 day) code check demand

    Hello, friends

    I am trying to build a multi-TimeFrames strategy : the 3 timeframes I work on are :
    - 1 minute,
    - 5 minutes
    - 1 day

    The code here below pretend to allow the orders to be taken only if the actual 1 minute bar bid is < first 5 minutes bar higher price of the present market session (Day) * a variabble (5 in this sample) :


    protected override void Initialize()
    {
    Add(PeriodType.Minute,1);
    Add(PeriodType.Minute,5);
    Add(PeriodType.Day,1);
    }


    protected override void OnBarUpdate()
    {
    if(BarsInProgress!=0){return;}
    if(GetCurrentBid(0)>Highs[1][Bars.BarsSinceSession]*5)
    {
    Entershort();
    }
    else
    {
    return;
    }
    }

    Can anybody tell me if this code is correct ?

    Thanks a lot in advance.

    #2
    Hi hypsis,

    Some things to keep in mind here -

    1. GetCurrentBid would only give you the bid value in realtime, in backtesting this will just be replaced by the Close price.

    2. Bars.BarsSinceSession will give you the # of bars in a session, however this will work in called BarsInProgress context, so here you are in primary bars context only (but work with Highs[1] > which is the 5 minute).

    3. You also check for the bid value being greater, while in your description you say smaller.

    Best would be printing the condition contents on your exact chart / trade scenario to see when they would trigger, so you can adjust / finetune as needed.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post

      1. GetCurrentBid would only give you the bid value in realtime, in backtesting this will just be replaced by the Close price.
      ok, i understand that

      2. Bars.BarsSinceSession will give you the # of bars in a session, however this will work in called BarsInProgress context, so here you are in primary bars context only (but work with Highs[1] > which is the 5 minute).
      here i don't understood your purpose : Highs[1][Bars.BarsSinceSession] give it to me the high value of the first 5 minutes bar of the session in a multitimeframe strategy where i declare in Initialize() in this order. ?

      Add(PeriodType.Minute,1);
      Add(PeriodType.Minute,5);
      Add(PeriodType.Day,1);

      i just want to wait an evolution (or close in backtest) of current one minute bar and compare it with the high of the first 5 minutes bar of the session.

      there is probably something i miss.


      3. You also check for the bid value being greater, while in your description you say smaller.
      here, it's just an error of tip in the sample. obviously i mean <

      thanks

      Comment


        #4
        hypsis, I would then just work from the BarsInProgress of your 5 minute series, as then the BarsSinceSession would report based on that series and you can use directly in your Highs[x][x] call as needed, for example consider this snippet giving you the value for reference you seek -

        if(BarsInProgress == 1)
        DrawDot("tag" + CurrentBar, true, 0, Highs[1][Bars.BarsSinceSession], Color.Red);
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          hypsis, I would then just work from the BarsInProgress of your 5 minute series, as then the BarsSinceSession would report based on that series and you can use directly in your Highs[x][x] call as needed, for example consider this snippet giving you the value for reference you seek -

          if(BarsInProgress == 1)
          DrawDot("tag" + CurrentBar, true, 0, Highs[1][Bars.BarsSinceSession], Color.Red);
          bertrand,

          i'm sorry, but it seems that you just rephrase my first question, or/and i don't understand your answer.

          so it's my turn to rephrase !

          "for each close (in live situation or backtest) of the current 1 minute bar, i'll want to compare it with the highest of the first 5 minutes bar of the current session".

          is this part of code is correct ??

          in Initialize()

          Add(PeriodType.Minute,1);
          Add(PeriodType.Minute,5);

          in OnBarUpdate()

          if(BarsInProgress==0) // one minute index
          {
          if(Closes[0][1]>Highs[1][Bars.BarsSinceSession])
          {
          do something;
          }
          else
          {
          do another thing;
          }
          }

          auxiliary issue : Close[0] or Closes[x][0] exists ??

          regards and thanks for your patience

          Comment


            #6
            hypsis, I had just provided you the best way to approach your issue by working directly in the needed BarsInProgress.

            For your new code snippet, BarsInProgress zero would not be guaranteed to be the 1 minute series...unless you explicitly load up a 1 minute chart...that would always be your primary series from the chart > not the first added series, that would be at BarsInProgress == 1.

            The use of Highs and Closes is correct. Closes[0][0] would be equalling Close[0].
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              For your new code snippet, BarsInProgress zero would not be guaranteed to be the 1 minute series...unless you explicitly load up a 1 minute chart...that would always be your primary series from the chart > not the first added series, that would be at BarsInProgress == 1.
              hi

              i'm lost. i load my strategy in the strategy tab, and in i choose the 1 minute timeframe.
              in this case :

              in Initialize()

              Add(PeriodType.Minute,1); is my primary serie (index 0)
              Add(PeriodType.Minute,5); is my secondary serie (index 1)

              and for example

              Add(PeriodType.Day,1); is my third serie (index 2)
              Add(PeriodType.Day,30); is my fourth serie (index 3)

              is it correct ??

              thanks.

              Comment


                #8
                No, that would not be correct, you need to shift by one - as the primary would be always coming from the UI (what you selected from the chart, strategies tab as series).

                Add(PeriodType.Minute,1); is my primary added serie (index 1)
                Add(PeriodType.Minute,5); is my secondary added serie (index 2)
                Add(PeriodType.Day,1); is my third added serie (index 3)
                Add(PeriodType.Day,30); is my fourth added serie (index 4)
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  et bin voila une jolie reponse !!

                  merci bertand !!

                  thanks a lot.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bortz, 11-06-2023, 08:04 AM
                  47 responses
                  1,603 views
                  0 likes
                  Last Post aligator  
                  Started by jaybedreamin, Today, 05:56 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post jaybedreamin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  18 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post Javierw.ok  
                  Working...
                  X