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

Pull Back Logic Possible?

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

    #16
    Ok I think I am getting close.

    So far I have the right pullback candle formation in tact as the prints are showing correctly.

    However, I am now having trouble with creating logic to only EnterLong()


    How do I create logic to make sure that from the holdValue candle to the candle entry have all had their lows greater than the middle bollinger band?

    if from the holdValue candle low to the candle that triggers the entry have all lows greater than the middle bollinger band and the High[0] is greater than the high of holdValue than it will trigger long.

    **As long as all the candle lows in between the holdvalue and entry candle are above the mid bb.

    I provided a few examples of how to phrase what I need.

    Here is my code now:


    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 5)
    return;

    if ((High[4] < High[3])
    && (Low[4] > midbbBull.Middle[4])
    && (Low[3] > midbbBull.Middle[3])
    && (Low[2] > midbbBull.Middle[2])
    && (Low[1] > midbbBull.Middle[1])
    && (High[3] > High[2])
    && (High[3] > High[1]))// pseudo condition, replace with your condition
    {
    holdValue = High[3]; //store the close when the condition was true
    holdBarNumber = CurrentBar; // store the current bar number when the condition was true
    }

    if (holdValue != 0 && holdBarNumber != 0) // check if we have values for the variables
    {
    Print("Close price at last condition was " + holdValue);
    }

    if (High[0] > holdValue)
    {
    EnterLong();
    }

    if (Low[0] < SMA5[0])
    {
    ExitLong();
    }

    Comment


      #17
      Hello dorony,

      Thank you for your response.

      Based on your description that code should do as you wish.

      Please let me know if you have any questions.

      Comment


        #18
        Hey thanks!

        It's not because I need the condition to also say that all bars from holdValue until trigger must have candle lows greater than the middle bollinger band.

        Right now it only has the first four candles with that condition and thats just to confirm a pullback with holding its high value. After the pullback confirms I need it to continue to make sure all candle lows are greater than the middle bollinger band, otherwise holdvalue needs to reset

        Comment


          #19
          Hello dorony,

          Thank you for your response.

          You could add a condition that checks if (Low[0] < midbbBull.Middle[0]) and if so then restart the condition checking. Below is an example that sets the holValue to 0 and checks for that 0 value to act as a switch.
          Code:
          [B]if (holdValue == 0[/B]
          && (High[4] < High[3])
          && (Low[4] > midbbBull.Middle[4])
          && (Low[3] > midbbBull.Middle[3])
          && (Low[2] > midbbBull.Middle[2])
          && (Low[1] > midbbBull.Middle[1])
          && (High[3] > High[2])
          && (High[3] > High[1]))// pseudo condition, replace with your condition
          {
          holdValue = High[3]; //store the close when the condition was true
          }
          
          [B]if (holdValue != 0
          && Low[0] < midbbBull.Middle[0])
          holdValue = 0;[/B]

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Rapine Heihei, Yesterday, 07:51 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by kaywai, Today, 06:26 AM
          1 response
          6 views
          0 likes
          Last Post kaywai
          by kaywai
           
          Started by ct, 05-07-2023, 12:31 PM
          6 responses
          205 views
          0 likes
          Last Post wisconsinpat  
          Started by kevinenergy, 02-17-2023, 12:42 PM
          118 responses
          2,780 views
          1 like
          Last Post kevinenergy  
          Started by briansaul, Today, 05:31 AM
          0 responses
          10 views
          0 likes
          Last Post briansaul  
          Working...
          X