Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Logic with closing above currentHigh from Current Day OHL

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

    Logic with closing above currentHigh from Current Day OHL

    HI can you please help me write it correctly. I wrote it this way but it doesnt open trades.
    I want if bar closes above currentLow - I enter buy. I would greatly appriciate it


    currentHigh = CurrentDayOHL().CurrentHigh[0];
    currentLow = CurrentDayOHL().CurrentLow[0];​

    private double currentHigh;
    private double currentLow;​

    and my logic goes here but it doesnt open trades

    else if (CandyCane
    && (Close[0] > Open[0] && Low[0] < Open[0]) // current bar bullish
    && Low[0] < Low[1] // and low of signal bar is lower then previous bar
    && Low[0] < currentLow && Close[0] > currentLow // siganl bar closes above low
    )
    {
    entryOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, TradeSize, 0, 0, "", "CC");

    return;
    }​

    Also if on the doc page it says Note: Only use this indicator on intraday series, can I still back test it or it can be tested with replay?
    https://ninjatrader.com/es/support/h...nt_day_ohl.htm

    I think i am getting this error in output if i change line to [1] -> currentHigh = CurrentDayOHL().CurrentHigh[1];
    Error on calling 'OnStateChange' method: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    Also this error if I i leave it as in the code
    Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
    Last edited by tkaboris; 02-08-2023, 06:36 PM.

    #2
    Condition: Low[0] < currentLow is never met, so a trade will never open

    Comment


      #3
      Originally posted by KonstantinosNT View Post
      Condition: Low[0] < currentLow is never met, so a trade will never open

      Hmm, I defined current Low in currentLow = CurrentDayOHL().CurrentLow[0];​
      and dont understand why Low[0] < currentLow is not met

      Comment


        #4
        Hello tkaboris,

        Thanks for your post.

        The Current Day OHL indicator should be used on intraday series. This means the indicator should be used on a series such as a Second or Minute series.

        This indicator could be used when backtesting in the Strategy Analyzer or on the Playback connection with Market Replay data.

        If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

        To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.

        https://ninjatrader.com/support/foru...121#post791121

        " You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

        This error message indicates that you are trying to access a BarsAgo value that is not valid. A more simple example using one series would be on bar 5 you check for 6 BarsAgo. There are not yet 6 bars so the CurrentBar minus 6 would be a negative number or a non-existent bar.

        A CurrentBar check could be used in your script's logic to ensure that a certain number of bars have processed before the script begins calculation.

        See the help guide documentation below for more information.
        CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
        CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
        Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

        "Error on calling 'OnStateChange' method: Object reference not set to an instance of an object."

        The error is advising that something you are accessing has not been created at the time you are accessing it. Ensure that your variable is created before trying to use it in your code. You should debug the script by reducing code and adding prints to find the exact line of code returning null.​

        Let us know if we may assist further.​​
        Last edited by NinjaTrader_BrandonH; 02-09-2023, 08:51 AM.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Irukandji, Today, 04:58 AM
        0 responses
        0 views
        0 likes
        Last Post Irukandji  
        Started by fitspressoburnfat, Today, 04:25 AM
        0 responses
        2 views
        0 likes
        Last Post fitspressoburnfat  
        Started by Skifree, Today, 03:41 AM
        1 response
        4 views
        0 likes
        Last Post Skifree
        by Skifree
         
        Started by usazencort, Today, 01:16 AM
        0 responses
        1 view
        0 likes
        Last Post usazencort  
        Started by kaywai, 09-01-2023, 08:44 PM
        5 responses
        604 views
        0 likes
        Last Post NinjaTrader_Jason  
        Working...
        X