Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

change of high of a day setup conditon

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

    change of high of a day setup conditon

    Hello,
    I am trying to automated my strategy, but I ca not deal with one problem.
    MY strategy works with highs/lows of a day (or current session).
    Lets say I am interested in high of a day since morning till 15:30...Lets say I still respect that value (high of a day till 15:30) even price moved above it for example at 15:45, new high is not important until some specific conditions has not changed (some other indicator value)

    As soon as specific conditions are changed (in my case - change of slope of EMA), it is a signal to setup new high of a day (current highest price since 15:30)...

    Is there any chance to set it up ?

    Example:

    1.If price > "high of a day till 15:30" = Buy signal

    2.If some indicators conditions has changed = setup "new high of a day" (highest price since 15:30)

    3. If price > "new high of a day" = buy signal...

    I know it is a simple description but I hope you will understand what I am looking for. I am sending a picture which better describe what I mean. Thank you for your help...
    Attached Files

    #2
    Hello Tomass,

    The CurrentDayOHL().CurrentHigh[0] would return the current high of today's session.

    If you are looking for the highest value between two specific bars and not the high of the day, you would need to use the MAX() method to do this.

    First you will need to find start and end bar.
    The MAX() method allows for a bars ago value. This will be the number of bars ago that you want to start looking for a high value.
    The MAX() also uses a period. This is the number of bars (from the start point) that will be checked.
    So to check a range, you specify the starting point and how many bars to move forward.

    Then use the MAX(High, numberOfBarsToCheck)[CurrentBar - startBarNumber]
    http://ninjatrader.com/support/helpG...aximum_max.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,
      thank you for your answer, but "bars ago" is not what I am looking for, because I am using renko charts and can not predict how many bars it will take. I am looking for high and low between time 00:00 and 15:30.

      Anyway, I did a research and I found exact indicator which does the job. It plots 2 lines which are high and low of current session (from 00:00 till 15:30). On picture you can see it works even if price go above (new high of a day is made, but there is still line with highest high till 15:30).

      Unfortunately I have got another problem, when I try to use this indicator to make my strategy.

      With Wizard I try to make simple strategy : if Open (0)>= "highest high from 00:00 till 15:30" = Enter Long

      Unfortunately do not know how to setup this indicator it writes me there is a mistake.

      I think the best thing will be to send you this indicator and please if you can try it yourself - just to make easy strategy in wizard : if current open>= highest high from 00:00 till 15:30 ="Enter long"...
      As soon as you set up these conditions in Wizard, and click on finish it will write you some error and strategy can not be finished. Will be glad for any help please .
      I am sending you this indicator, photo of graph where you can see this high and low of a session and photo of strategy wizard how I setup a condition...Also with photo of error it wrote me at the end... Thank you
      Attached Files

      Comment


        #4
        Hello Tomass,

        You will still need a bars ago value using MAX().

        To find out the bar number of a bar by the time, use Bars.GetBar(DateTime barTime)



        The indicator you have posted places a Color input in the Parameters section. This causes the Strategy Wizard to break.
        You can still use the indicator by coding by hand, but you would not be able to compile using the Strategy Wizard.
        (The VolumeZones indicator included with NinjaTrader 7 has the same issue)

        Changing the category to something other than Parameters will allow the Strategy Wizard to compile as the input will be hidden from the Wizard.
        Change [GridCategory("Parameters")] to [Category("Visual")] in the indicator and the indicator will then be usable in the Strategy Wizard.
        (The HeikenAshi indicator has an example of this)

        This is no longer an issue with NinjaTrader 8 (currently in Release Candidate 1) as the Strategy Wizard is able to work with Brush inputs.
        Last edited by NinjaTrader_ChelseaB; 09-08-2016, 09:27 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          thank you for youn answer. I made my indicator working, however, I am still struggling with condition of change of high. Sorry I am new with ninjascript and maybe missing some easy point. How can I find startbar?

          In fact, I have 3 conditions written:

          1. "If open> high till 15:30 -> buy"(that is what I want until some indicator change does not appear)

          if (Open[0] >= HiLoOfTimeRange_WithTargetNT7(8, 0, 15, 30, 0, 0).TheHigh[0]
          && EMA (100)[0] > EMA(200)[0]
          && Open[0] > EMA(100)[0]
          && ToTime(Time[0]) >= ToTime(15, 30, 0)
          && ToTime(Time[0]) <= ToTime(21, 30, 0))
          {
          EnterLong(DefaultQuantity, "high breakout");
          }

          2. "indicator change". If that condition appears, it will trigger a change.

          if (EMA (100)[0] > EMA(200)[0]
          && (EMA(100)[0] == emaslopes2(5, 15, 30, 100).EMAslopedown[0]
          || EMA(100)[0] == emaslopes2(5, 15, 30, 100).EMAdown[0])
          && ToTime(Time[0]) >= ToTime(15, 30, 0)
          && ToTime(Time[0]) <= ToTime(21, 30, 0))


          3. new conditions: "if open> high of a day ->buy"

          if (Open[0] >= BTH_OHLbyDay(0).CurrentHigh[1]
          && EMA (100)[0] > EMA(200)[0]
          && Open[0] > EMA(100)[0]
          && ToTime(Time[0]) >= ToTime(15, 30, 0)
          && ToTime(Time[0]) <= ToTime(21, 30, 0))
          {
          EnterLong(DefaultQuantity, "superlong");
          }

          I just do not know, how to put it together now. All I want is that condition 1 works till change as described (condition 2). And as soon as this change appear, strategy works only on condition 3.

          Will be very glad for any advice please, I am nw to ninjascript and trying my best to understand it.

          Thank you very much. Tomas

          Comment


            #6
            Hi Tomass,

            To find the highest high between two abitrary times, you will need to use Bars.GetBar() to get the bars ago value of the start bar. Use Bars.GetBar() to get the bars ago value for the end bar. Use the difference of these two bars ago values to find the period (number of bars we are looking for the high in). And set the barsAgo value for where the MAX() method will start looking backward from to the barsAgo value for the end bar.

            An example of finding the high between 8:00 AM and 4:00 PM:

            With the use of variables:
            Code:
            DateTime startTime	= new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 8, 0, 0);
            DateTime endTime	= new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 0, 0);
            int startBarNumber	= Bars.GetBar(startTime);
            int startBarsAgo	= CurrentBar - Bars.GetBar(startTime);
            int endBarNumber	= Bars.GetBar(endTime);
            // either take the bar ending at the end time, or if the time is before the end time use the current bar
            int endBarsAgo		= Math.Max(0, CurrentBar - Bars.GetBar(endTime));
            
            // if the time is before the start bar or the start bar is not in the historical data then don't calculate on this bar
            if (startBarsAgo < 0 || Time[startBarsAgo] != startTime)
            	return;
            
            Print(string.Format("{0} | start bar number: {1} | end bar number: {2}", Time[0], Bars.GetBar(startTime), Bars.GetBar(endTime) ));
            Print(string.Format("{0} | CurrentBar: {1} | start bars ago: {2} | end bars ago: {3} | startBarsAgo - endBarsAgo: {4}", Time[0], CurrentBar, (CurrentBar - Bars.GetBar(startTime)), Math.Max(0, CurrentBar - Bars.GetBar(endTime)), (startBarsAgo - endBarsAgo) ));
            Print(string.Format("{0} | HighestHigh: {1}", Time[0], MAX(High, (startBarsAgo - endBarsAgo))[endBarsAgo] ));
            Without the use of variables:
            Code:
            if (CurrentBar - Bars.GetBar(startTime) < 0 || Time[CurrentBar - Bars.GetBar(startTime)] != new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 8, 0, 0))
            	return;
            
            Print(string.Format("{0} | HighestHigh: {1}", Time[0], MAX(High, ((CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 8, 0, 0))) - Math.Max(0, CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 0, 0)))))[Math.Max(0, CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 0, 0)))] ));
            Last edited by NinjaTrader_ChelseaB; 09-12-2016, 10:18 AM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello,
              thank you, but I am afraid it is not the answer for my last problem. I am not looking for a way how to find high and low in specific time range.

              I can do it already with indicator HiLoOfTimeRange_WithTargetNT7 and it works very well in strategy.
              please maybe read my last comment, where I described it also with codes.

              I have 3 conditions setup:
              Situation 1: it is my working strategy (which is based on "high of a day till 15:30) and it works

              Situation 2: it is a situation (change of emaslope indicator). if this occurs during my trading session, I need to change "high of a day till 15:30 to "high of a day")

              Situation 3: same as situation 1 (but there is a change in code, now entries are based on high of a day, not "high of a day till 15:30")...

              I am not looking for a way how to find high or low of a day, I can do that. I am looking for this: Strategy works on situation 1. If situation 2 appears - strategy works on situation 3...


              I have a code for situation 1, I have a code for this situation 2 and I have a code for situation3, I just do not know how to stick it together (all with codes in my previous coment).

              Lets sy I need a start bar not based on time range as you advice, but based on indicator change). Maybe use of function countif?

              Comment


                #8
                Hello Tomass,

                When you mention "I am still struggling with condition of change of high" can you clarify what you are trying to do?

                When you mention "How can I find startbar?", can you clarify what starting bar you are looking for?

                If you want to detect when a value changes, create a variable to store the current value. Then a new bar, compare this variable with the new value.

                private double savedHigh = 0;

                if (savedHigh != CurrentBarOHL().CurrentHigh[0])
                {
                Print("value changed");
                savedHigh = CurrentBarOHL().CurrentHigh[0];
                }

                This code will check that the savedHigh value is equal to the current high. If it is not, a print will appear alerting that the high has changed and then will set the savedHigh to the new high value.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  thanks for your time an patience.

                  Maybe picture will help.on photo you can see setup for my strategy.

                  I have a strategy which works with 3 indicators.
                  One shows me high/low till 15:30
                  Second shows me high/low of a day.
                  third shows me EMA slope (green, grey, red)

                  Situation 1:
                  if ema slope is green-> if open> "high till 15:30 "= buy signal

                  Situation 2:if ema slope turns red -> since that time if open > high of a day = buy signal.

                  If EMA slope is green whole day, my entries are based on "high till 15:30" whole day.. But if Ema slope turns red (at least once, no matter if it turns back to green again) - since that moment entries only: if open > "current high of day" = buy signal(no high till 15:30 anymore...

                  my problem is that I do not know how to code that change. Basically - if indicator EMA slope turns red, I need to replace order (if open> "high till 15:30 "= buy signal) by order (if open > "current high of day"= buy signal).

                  Hope it makes some sence what I am trying to code. Will be glad for any advice and thank you a lot, it is hard to describe it so sorry for misunderstandings.
                  Attached Files

                  Comment


                    #10
                    Hello Tomass,

                    The EMA indicator that is supplied with NinjaTrader does not change colors based on the slope.

                    Are you asking how to detect if the slope of the EMA has a negative value?

                    if (Slope(EMA(14), 1, 0) < 0)
                    {
                    // execute code
                    }

                    Slope(IDataSeries series, int startBarsAgo, int endBarsAgo)


                    This condition will trigger if the slope of the EMA(14) from the previous bar to the current bar has a negative value.


                    Use a variable such as a bool that is changed from false to true when this condition is true. Then if the bool is true, this means as some point the EMA(14) had a negative slope between two bars.

                    You can also contact one of our professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by GussJ, 03-04-2020, 03:11 PM
                    16 responses
                    3,279 views
                    0 likes
                    Last Post Leafcutter  
                    Started by WHICKED, Today, 12:45 PM
                    2 responses
                    19 views
                    0 likes
                    Last Post WHICKED
                    by WHICKED
                     
                    Started by Tim-c, Today, 02:10 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by Taddypole, Today, 02:47 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post Taddypole  
                    Started by chbruno, 04-24-2024, 04:10 PM
                    4 responses
                    51 views
                    0 likes
                    Last Post chbruno
                    by chbruno
                     
                    Working...
                    X