Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current bar close is above / below its open

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

    Current bar close is above / below its open

    Hello,

    How do I create a cell condition to show current bar close is above its open. And same for reverse - current bar close is below its open?

    Appreciate your help

    #2
    Hello TraderYoda,

    Thank you for writing in.

    You would be unable to do this with cell conditions; instead, you would need to make an indicator that will output a value. Then, based on this value, you can create a cell condition.

    Here is some simple code below on how this can be accomplished with the indicator:
    Code:
    protected override void OnBarUpdate()
    {
         // if the close is greater than the open, set the plot to 1
         if (Close[0] > Open[0])
              Value.Set(1);
         // if the close is less than the open, set the plot to -1
         if (Close[0] < Open[0])
              Value.Set(-1);
         // if the close equals the open, set the plot to 0
         else
              Value.Set(0);
    }
    The indicator outputs a 1 if the close is greater than the open, a -1 if the close is less than the open, and a 0 if the close is equal to the open.

    You'll want to add an indicator column and select this indicator. Then, create your alert conditions based on the plotted number.

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

    Comment


      #3
      Originally posted by NinjaTrader_ZacharyG View Post
      Hello TraderYoda,

      Thank you for writing in.

      You would be unable to do this with cell conditions; instead, you would need to make an indicator that will output a value. Then, based on this value, you can create a cell condition.

      Here is some simple code below on how this can be accomplished with the indicator:
      Code:
      protected override void OnBarUpdate()
      {
           // if the close is greater than the open, set the plot to 1
           if (Close[0] > Open[0])
                Value.Set(1);
           // if the close is less than the open, set the plot to -1
           if (Close[0] < Open[0])
                Value.Set(-1);
           // if the close equals the open, set the plot to 0
           else
                Value.Set(0);
      }
      The indicator outputs a 1 if the close is greater than the open, a -1 if the close is less than the open, and a 0 if the close is equal to the open.

      You'll want to add an indicator column and select this indicator. Then, create your alert conditions based on the plotted number.

      Please, let us know if we may be of further assistance.
      Hello. Thank you for helping with the code. I tried copying your code into notepad and renaming the file extension to .cs

      I then copied the .cs file into ninjatrader indicator folder and then used ninjatrader editor to compile it as I have done with other .cs indicator files but in this case it did not work?

      How do I create an indicator file using the code your kindly provided?

      Appreciate your help

      Traderyoda

      Comment


        #4
        Hello TraderYoda,

        The code suggested by NinjaTrader_ZacharyG is not a complete script.

        Start by creating a script (and include a plot):
        Tools -> New NinjaScript -> Indicator...

        Once created and the Finish button is clicked, the script will open in the NinjaScript Editor.
        Copy the suggested code into the OnBarUpdate() method of the indicator.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by habeebft, Today, 07:27 AM
        0 responses
        4 views
        0 likes
        Last Post habeebft  
        Started by Tim-c, Today, 03:54 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by rocketman7, Today, 01:00 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by wzgy0920, 04-23-2024, 09:53 PM
        3 responses
        76 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by JonesJoker, 04-22-2024, 12:23 PM
        9 responses
        46 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X