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 llanqui, Today, 03:53 AM
        0 responses
        6 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        10 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        15 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        11 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Yesterday, 07:51 PM
        0 responses
        14 views
        0 likes
        Last Post strategist007  
        Working...
        X