Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Buy if ask > high[1]

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

    Buy if ask > high[1]

    Hi everyone,

    I am trying to build a strategy that would buy if the W%R indicator goes from under to above -80 on a 5min bar.
    But it must buy only if the ask price is above the last bar high. But it didn't work, it still buy at the open of the new bar and not at the high of last bar

    here is the code:

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (WilliamsR(14)[0] > -80
    && WilliamsR(14)[1] < -80
    && GetCurrentAsk() > High[1])
    {
    EnterLong(1000, "");

    Thank you in advance.

    #2
    Originally posted by Chris128 View Post
    Hi everyone,

    But it must buy only if the ask price is above the last bar high. But it didn't work, it still buy at the open of the new bar and not at the high of last bar



    Thank you in advance.
    Is your CalculateOnBarClose True or False?

    Try false if true.

    Comment


      #3
      hi sledge,

      Yes, I already try it on false but it doesn't work.

      Comment


        #4
        Where are you testing this? Market replay? Strategy analyzer?

        Comment


          #5
          You should open the output window from control center, and put these Print statements in your code to debug.

          You should see what is going on, if GCA is 0/blank, if WillamsR is above -80/below -80, etc.

          If you are seeing "Entering Long" you know you made it inside.


          Code:
          protected override void OnBarUpdate()
          {
          [B]Print ( "WR[0]= "+ WilliamsR(14)[0] + " WR[1]= "+ WilliamsR(14)[1] + " GCA=" + GetCurrentAsk() + " High[1]=" + High[1] );[/B]
          // Condition set 1
          if (WilliamsR(14)[0] > -80
          && WilliamsR(14)[1] < -80
          && GetCurrentAsk() > High[1])  
          {
          [B]Print ( "Entering Long" );[/B]
          EnterLong(1000, "");

          Comment


            #6
            I use the strategy analyzer.

            Here an example of what I get on the output window:

            WR[0]= -63.7681159420289 WR[1]= -85.5072463768103 GCA=108.94 High[1]=108.93
            Entering Long

            Comment


              #7
              Interesting. I have no idea at this point, other than looking in the log files or output window for error messages.

              Comment


                #8
                Hello,

                Have you tried using Trace Orders or checked the log to see if the order is being ignored or other?



                TraceOrders would print to the Tools -> Output window if the order is being ignored, this is a good test if the condition happened but the order did not.

                I look forward to being of further assistance .

                Comment


                  #9
                  Hi Jesse,

                  Here is an example of what I get when I use the trace order:

                  Output:
                  [/I]WR[0]= -81.5286624203818 WR[1]= -81.5286624203818 GCA=110.61 High[1]=110.62
                  08.09.2015 13:35:00 Entered internal PlaceOrder() method at 08.09.2015 13:35:00: BarsInProgress=0 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                  08.09.2015 13:35:00 Ignored PlaceOrder() method: Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
                  WR[0]= -74.5222929936303 WR[1]= -81.5286624203818 GCA=110.72 High[1]=110.68
                  Entering Long
                  End of output.

                  Would it be possible for you to share with me an strategy that would simply buy when the Williams%R goes above -80 and when the last price is above the high of the last 5min candle ?
                  Because something must be wrong in my code.

                  Thank you in advance.
                  Last edited by Chris128; 09-11-2015, 01:41 AM.

                  Comment


                    #10
                    Hello Chris128,

                    It looks like your logic is simply trying to exit a non-existant long position based on the TraceOrders output you have provided, so your EnterLong does not seem to be working. Are there any buy orders that you can find in your TraceOrders output?

                    Here is a simple sample that will enter long when the WilliamsR, with a period of 14, crosses above -80 and when the last price is above the high of the last bar:
                    Code:
                    if (CrossAbove(WilliamsR(14), -80, 1) && Close[0] > High[1])
                    {
                         EnterLong();
                    }
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      Would the output window also work for debugging when testing a strategy against historical data ?

                      Comment


                        #12
                        Hello Pvtrade,

                        Thank you for your inquiry and welcome to the NinjaTrader Support Forum!

                        Yes, the output window will work for debugging when testing a strategy against historical data as well.

                        Please, let us know if we may be of further assistance.
                        Zachary G.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        646 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        367 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        107 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        569 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        573 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X