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

Two phase entry management

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

    Two phase entry management

    Hi,
    I use somewhat envelope system with bollinger bands and am now puzzled how to programm this:

    phase 1
    when two bands cross upward or downward I want the system to wait for a buy or sell market signal
    phase 2:
    then turn to tick data checking them with moving average being calculated from tick data realtime and then entering for market price when tick price equals (or is half pip from MA).

    more detailed description:

    I want the bands to be calculated from close prices (to be sure bands crossed), when the system after certain bar close price finds out the signal is there (bands crossed the good way signalling we should wait for good entry price) then I want the script to be watching tick data (not from close prices) and comparing them with SMA (6), and when script sees market tick data are half pip from MA6 then enter the good direction (there should be one more trend checking filter here calculated from close prices) at market price.

    Please advice me how to handle first the signal from close prices (if they cross and bar is not closed, I am not interested, it is a no signal for me) and then when it happens how to start checking the tick data entering then for the price of moving average (being calculated from the tick data realtime during a bar being drawn).
    with correct direction.
    Thank you very much in advance!
    N.

    #2
    nicknamed,

    You want to run with CalculateOnBarClose = false to allow for processing every single incoming tick in real-time. The parts that you just want the close price for you want to use if (FirstTickOfBar).

    The first tick of a bar indicates the close of the previous bar so it is the exact same event. From there you want to back reference the correct bar.

    Code:
    if (FirstTickOfBar)
    {
         Print(Close[1].ToString());
    }
    Note the [1] index referencing the just closed bar instead of the just opened bar.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh, thank you for a prompt reply, but could you please explain more in detail? my english is so so and I am rather a beginning programmer with nice ideas I saw working on charts, so I do not understand wholly what to do when. Thank you very much for a more detailed explanation, possibly with examples for the stupid one

      Comment


        #4
        Run your script with CalculateOnBarClose = false. Then anything want calculated based on the close of a bar use the snippet I provided above. Anything you want processed on a tick by tick basis just leave it outside of that if-statement.

        You set CalculateOnBarClose in the Initialize() method. The if-statement goes into OnBarUpdate() method.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh , I know how to work with tick data, but my problem is in the "waiting" for second signal.
          1.signal only marks potential trade and its direction, but then I have to wait for 2. signal (the price equals moving average), which maybe will come after 5 bars. And my problem is how i can write this waiting. I mean Can I save this 1.signal result into any variable?
          Something like this:

          bool firstSignal = false
          if(CrossAbove(SMA(6),SMA(60))
          {
          firstSignal = true;
          }

          if(Price[0] >= SMA(6) && firstSignal == true)
          {
          EnterLong();
          }

          Has Ninja Script any support for this "waiting" on second signal?
          ---
          I have there now the condition of he 5 bars, but it makes silly things like five time opening and closing a trade within 5 bars.

          this is only a proxy that is going to be deleted since it does not work and will be replaced by the trend checking filter (again, I don't know how to do it since that one should be calculated on bar close).

          Thank you very much!

          Comment


            #6
            nicknamed,

            You do exactly what you have outlined except you need to move the bool firstSignal = false line into Variables section of your code as a private.

            private bool firstSignal = false;

            This is required so you don't keep overwriting it with false on every single bar update.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by timmbbo, Today, 08:59 AM
            1 response
            2 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by KennyK, 05-29-2017, 02:02 AM
            2 responses
            1,280 views
            0 likes
            Last Post marcus2300  
            Started by fernandobr, Today, 09:11 AM
            0 responses
            2 views
            0 likes
            Last Post fernandobr  
            Started by itrader46, Today, 09:04 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by bmartz, 03-12-2024, 06:12 AM
            5 responses
            33 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Working...
            X