Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is it Possible to Trade Using The Bar After The Current Bar

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

    Is it Possible to Trade Using The Bar After The Current Bar

    Hi Guys

    I am trying to code a strategy that goes like this:
    If current bar has this characteristic
    and
    The next bar after current bar closes above the current bar
    then
    Go long limit at median of the bar zero (current bar)

    Although I can get results doing this using the Strategy Analyzer but I am thinking that in a real situation this won't be possible because the program can't handle going back to current bar median price and place a limit order at that price. I suspect this because in the Analyzer the entry is on the next bar after the current bar when it should have waited to see that bar closes above the current bar before placing the trade. Can you give me some guideline on how I can resolve this situation. Thank you.

    #2
    Originally posted by bijan View Post
    Hi Guys

    I am trying to code a strategy that goes like this:
    If current bar has this characteristic
    and
    The next bar after current bar closes above the current bar
    then
    Go long limit at median of the bar zero (current bar)

    Although I can get results doing this using the Strategy Analyzer but I am thinking that in a real situation this won't be possible because the program can't handle going back to current bar median price and place a limit order at that price. I suspect this because in the Analyzer the entry is on the next bar after the current bar when it should have waited to see that bar closes above the current bar before placing the trade. Can you give me some guideline on how I can resolve this situation. Thank you.
    Code:
    if (tradeTriggered && Close[0] > Close[1]) EnterLongLimit(Median[1]);
    IOW, you do not know the future, so adjust your thinking to see how the past bars behaved relative to the current bar, and reference the bars in the past.

    Comment


      #3
      What do I need to put in place of: tradeTriggered? In the code you suggested.
      Last edited by bijan; 12-22-2013, 11:57 PM.

      Comment


        #4
        Originally posted by bijan View Post
        What do I need to put in place of: tradeTriggered? In the code you suggested.
        Your original question was stated as:
        Code:
        I am trying to code a strategy that goes like this:
        If current bar has this characteristic
        and
        The next bar after current bar closes above the current bar
        then
        Go long limit at median of the bar zero (current bar)
        So tradeTriggered is a bool set at the time that "current bar has this characteristic". In the flow of data, and the program
        Code:
        if ("current bar has this characteristic") tradeTriggered = true;
        comes first in the code.

        The alternative, if this is strictly a 2-bar pattern, would be to code it as:
        Code:
        if ("previous bar has this characteristic" && Close[0] > Close[1]) EnterLongLimit(Median[1]);
        Last edited by koganam; 12-23-2013, 10:24 AM.

        Comment


          #5
          Hi Bijan,

          Thank you for posting and thanks to Koganam for providing a solution.

          Koganams' solution will work for what you are trying to achieve.

          Defining the CurrentBar characteristics will allow you to have that defined condition to place that trade.

          Let us know if we can be of further assistance.
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Thank you or your replies.
            I put under: protected override void OnBarUpdate ( ) the following:
            if ("Bar [1] condition "
            && Close [1] < Open [1]
            && Close [0] > High [1])
            EnterLongLimit (Median [1] + 0.5);

            It gives me error code: CS0019

            Comment


              #7
              Originally posted by bijan View Post
              Thank you or your replies.
              I put under: protected override void OnBarUpdate ( ) the following:
              if ("Bar [1] condition "
              && Close [1] < Open [1]
              && Close [0] > High [1])
              EnterLongLimit (Median [1] + 0.5);

              It gives me error code: CS0019
              "Bar [1] condition " is a meaningless string to the compiler. You must put the actual mathematical condition that bar[1] should be satisfying. That is a good part of the reason why I initially coded it as a separate bool.

              You posited it as a nebulous statement, I presume to hide the actual condition. That condition, that you were hiding in your description, is the condition that should be placed where you posited it.

              Comment


                #8
                Yes I put the word condition as substitute for the actual mathematical formula, and yes to hide the actual formula. The error code CS0019 is actually for the other line that starts with &&. The error description states: Operator '&&' cannot be applied to operand of the type 'string' and 'bool'

                I assume since the line containing the condition did not generate an error makes it is probably correct.

                Comment


                  #9
                  Originally posted by bijan View Post
                  Yes I put the word condition as substitute for the actual mathematical formula, and yes to hide the actual formula. The error code CS0019 is actually for the other line that starts with &&. The error description states: Operator '&&' cannot be applied to operand of the type 'string' and 'bool'

                  I assume since the line containing the condition did not generate an error makes it is probably correct.
                  That is what I meant. Your "Bar [1] condition " must evaluate to a bool, not a string.

                  That a prior statement is valid is not really relevant in this case. Only the type of data that you have in the specific statement is important. Relationships of the closes are either true or false, hence boolean. So must be your "Bar [1] condition ". The compiler sees whatever you have put there as invalid (a string, in this case).

                  Comment


                    #10
                    OK. I get what you are wrote but I do not know how to resolve the issue after giving it some thought. From what you say I take it that a bool statements have to be either == or =!, true of false. But if I use == or ==! between the Bar[1] and its condition then the meaning would not be correct. I am trying to say something like: If a characteristic of Bar [1] is less than such. For example if : Bar [1] high is less than EMA (20). To be able to say this I can not use if Bar [1] is either true or false. And I guess if I don't use == or =! then I can not use a relationship of bar closes for the second line of code because that is bool and bool and string can not be mixed. So I think I know what you wrote but I do not know how to resolve it.

                    By the way it is a 2 bar pattern.

                    It would be helpful if you could give me the code for something like: If Bar [1] < EMA (20)
                    But in a way that it would be bool and not string. I can probably then modify it or get some idea of how to code what I am trying to code. Thanks.

                    Comment


                      #11
                      Originally posted by bijan View Post
                      I am trying to say something like: If a characteristic of Bar [1] is less than such. For example if : Bar [1] high is less than EMA (20). ...

                      It would be helpful if you could give me the code for something like: If Bar [1] < EMA (20)
                      But in a way that it would be bool and not string. I can probably then modify it or get some idea of how to code what I am trying to code. Thanks.
                      You almost have it right.

                      "Bar [1] high is less than EMA (20)" would be coded as:
                      Code:
                      High[1] < EMA(20)[0]

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      649 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      370 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
                      573 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      576 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X