Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multitimeframe coding

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

    Multitimeframe coding

    Hello,

    I have a question regarding multi time-frame coding..

    I will want to look for signals on my longterm timeframe 1440min and enter my trades on a 60min chart with a few rules.

    I have already coded both conditions...

    So the condition of the 1440min chart must be true on (CalculateOnBarClose = false plus the condition on 60min chart with (CalculateOnBarClose = true);

    On the 1440min I will look for this:
    Code:
    if (Close[0] > EMA(EMALongterm)[0]
    && CrossAbove(Stochastics(StoD, StoK, StoSmooth).K, StoOverSold, 1))
    On the 60 min I will look for this:
    Code:
    if (Close[0] > SMA(MAPink)[0]
    && MACDColorUpDown(MACDFast, MACDSlow, 9)[0] > MACDColorUpDown(MACDFast, MACDSlow, 9).Avg[0]
    && Stochastics(StoD, StoK, 3).K[0] > StoOverSold)
    I looked at the help section, but came half way...


    This what I have done:
    Added Add(PeriodType.Minute, 1440); under "Initialize()" in the 60min entry strategy...

    Then I added the following code. (I do not know how to tell the system to take the latest value and not the close of 1440min bar... So I put "LastPrice")...

    Code:
    protected override void OnBarUpdate()
    {			
            if (BarsInProgress == 1)
    	return;
            if ("LastPrice"[0] > EMA(BarsArray[1],250)
                 && Stochastics(BarsArray[1],1, 5, 0) > 20
                && (Close[0] > SMA(BarsArray[0],MAPink)[0]
    			&& MACDColorUpDown(BarsArray[0],MACDFast, MACDSlow, 9)[0] > MACDColorUpDown(BarsArray[0],MACDFast, MACDSlow, 9).Avg[0]
    		&& Stochastics(StoD, StoK, 3).K[0] > StoOverSold))
             	{
                  EnterLong();
                
            	}
    		}
    Anyon who can help me with this?

    #2
    Hello prisonbreaker82,
    You may look into the Closes data series to do it.



    Code:
     if (Closes[0][0] > EMA(BarsArray[1],250)

    Also you can replace BarsArray[1] with Closes[1].
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Joydeep View Post
      Hello prisonbreaker82,
      You may look into the Closes data series to do it.



      Code:
       if (Closes[0][0] > EMA(BarsArray[1],250)

      Also you can replace BarsArray[1] with Closes[1].
      Hi @NinjaTrader_Joydeep,

      Thank you for your quick reply.

      I tried to change according to your instructions. I still get these two errors.

      As I said before, I do not want to compare closing prices, I want to get latest price from the 1440 chart. If this is fulfilled, then I want to verify if the conditions of the 60min chart is fulfilled before going long.

      Thank you!
      Attached Files

      Comment


        #4
        Hello prisonbreaker82,
        You are comparing the previous price of the primary bar with a data series.

        If you want to compare the last price of the secondary series then please use the below code

        Code:
        if (Closes[[B]1][0] [/B]> EMA(Closes[1], 250)[B][0][/B])
        {
           // do something
        }
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Joydeep View Post
          Hello prisonbreaker82,
          You are comparing the previous price of the primary bar with a data series.

          If you want to compare the last price of the secondary series then please use the below code

          Code:
          if (Closes[[B]1][0] [/B]> EMA(Closes[1], 250)[B][0][/B])
          {
             // do something
          }
          Hi @NinjaTrader_Joydeep

          Code:
          if (Closes[1][0] > EMA(Closes[1],250)[0] && Stochastics(Closes[1],1, 5, 0)[0] > 20
          			&& Stochastics(Closes[1],1, 5, 0)[0] < 55
          			&& Closes[0][0] > SMA(Closes[0],MAPink)[0]
          			&& MACDColorUpDown(Closes[0],MACDFast, MACDSlow, 9)[0] > MACDColorUpDown(Closes[0],MACDFast, MACDSlow, 9).Avg[0]
          			&& Stochastics(Closes[0],StoD, StoK, StoSmooth).K[0] > StoOverSold)
          			//CrossAbove(Stochastics(1, 5, 3).D, MyInput0, 1)
                   	{
                        DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0], Color.Lime);
                  	}
          		}
          Now it works. Only two things

          It looks I only get arrows up after the daily bar (1440min) has closed, I would like to enter earlier if possible. As well I would like to only show arrows when the Stochastic is crossing above 20 on that day. How do I do that?

          Thank you for an excellent support!

          Comment


            #6
            Hello prisonbreaker82,
            On historical bar the NinjaScript code is evaluated on the end of the bar only.
            To assist you further may I know
            • Are you witnessing the scenario on historical bar or real time bar
            • What calculate on bar close you have set?
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Joydeep View Post
              Hello prisonbreaker82,
              On historical bar the NinjaScript code is evaluated on the end of the bar only.
              To assist you further may I know
              • Are you witnessing the scenario on historical bar or real time bar
              • What calculate on bar close you have set?
              Hi @NinjaTrader_Joydeep

              It looks like the 60min are reading the EMA 50 and EMA250 from its own input serie (60min) and not the 1440 min EMA50 & EMA250 EMA... How do I change this?

              code snippet from AbovetheGreenLine60min.cs
              Code:
              protected override void OnBarUpdate()
                      {			
              			if (BarsInProgress == 1)
              				return;
                      if (Closes[1][0] > EMA(Closes[1],250)[0]
              			&& Closes[1][0] < EMA(Closes[1],50)[0]
              			&& Stochastics(Closes[1],1, 5, 0)[0] > 20
              			&& Closes[0][0] > SMA(Closes[0],MAPink)[0]
              			&& MACDColorUpDown(Closes[0],MACDFast, MACDSlow, 9)[0] > MACDColorUpDown(Closes[0],MACDFast, MACDSlow, 9).Avg[0]
              			&& Stochastics(Closes[0],StoD, StoK, StoSmooth).K[0] > StoOverSold)
                       	{
                            DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0], Color.Lime);
                      	}
              		}
              I have also attached the strategies. One is just for visual on the daily time frame (1440min)
              Attached Files

              Comment


                #8
                Hello prisonbreaker82,
                You have plotted the indicators on a daily chart and not on a 60 minutes chart. What values you are getting if you try applying the indicators on a 60 minute chart.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Joydeep View Post
                  Hello prisonbreaker82,
                  You have plotted the indicators on a daily chart and not on a 60 minutes chart. What values you are getting if you try applying the indicators on a 60 minute chart.
                  Hi @NinjaTrader_Joydeep,

                  Looks like it works now.
                  Attached Files
                  Last edited by prisonbreaker82; 12-26-2012, 09:13 AM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  656 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  371 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  109 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  574 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  579 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X