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

Order rejected

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

    Order rejected





    if (Position.MarketPosition!=MarketPosition.Flat && BarsSinceEntryExecution() > 4)
    {
    ExitLong();
    ExitShort();
    }
    if (LucaCongestionBox().SPlot[0] == 1)
    {
    EnterLong();
    SetStopLoss(CalculationMode.Price, Low[1]);

    }
    else if (LucaCongestionBox().SPlot[0] == -1)
    {
    EnterShort();
    SetStopLoss(CalculationMode.Price, High[1]);

    }

    i don't understand what is the problem

    #2
    Hello esignal,

    Thank you for your note.

    Without the full code I’m unable to test on our end.

    The issue likely is related High[1], which is the high of the last bar, being lower or too close to the last price. I would suggest,

    1) Working your stops further from the current price, at least 3 ticks from current price.

    2) Adding a check to make sure the stop price is valid, for example, an if statement making sure your buy stop price is above the ask price, for example,

    Code:
    if(High[1] < GetCurrentAsk())
    {
    SetStopLoss(CalculationMode.Price, High[1]);
    }
    3) Adding print statements to confirm you are submitting your stops at valid levels. I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:

    Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


    I’ve provided a link covering debugging which you may find helpful.
    Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      you write :


      if(High[1] < GetCurrentAsk())
      {
      SetStopLoss(CalculationMode.Price, High[1]);
      }
      ok i understand.....
      i want this:

      if(High[1] < GetCurrentAsk())
      {
      SetStopLoss(CalculationMode.Price, High[1]);
      }
      else StopLossNExtCandle; =====> how i do it?
      StopLossNextCandle how i code it? thank

      Comment


        #4
        Hello Esignal,

        You could try under your else statement, saving the current bar to a variable, adding 1, then on the next bar checking if the current bar is equal to that value, if so, submit a stop loss.

        So create a global variable,

        Code:
        private double xCurrentBar;
        Then your else statement,

        Code:
        else
        {
        xCurrentBar = CurrentBar+1;
        }
        Then add another if statement to your code,

        Code:
        if(xCurrentBar == CurrentBar)
        {
        SetStopLoss(CalculationMode.Price, High[1]);}
        }
        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          🙁..i dont uderstand your code

          how do i code it if i want to cover position next candle ?
          Last edited by esignal; 03-21-2017, 05:08 PM.

          Comment


            #6
            Hello esignal,

            Saving the current bar to a variable and adding one, would then make the if statement,

            Code:
            if(xCurrentBar == CurrentBar)
            true on the next bar. I would suggest adding print statements to the code I provided to understand the logic. For example,
            Code:
            Print(CurrentBar.ToString());
            Print(xCurrentBar.ToString());
            I’ve provided a link to a youtube video which covers an example of using prints to understand behavior: https://www.youtube.com/watch?v=K8v_...tu.be&t=48m45s

            Regarding how to convert the code I provided you to exit your position on the next bar rather than set a stop loss, you would want to use ExitLong/ExitShort methods for which are covered in the following section of our helpguide.




            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mmenigma, Today, 02:22 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by frankthearm, Today, 09:08 AM
            9 responses
            35 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by NRITV, Today, 01:15 PM
            2 responses
            9 views
            0 likes
            Last Post NRITV
            by NRITV
             
            Started by maybeimnotrader, Yesterday, 05:46 PM
            5 responses
            26 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by quantismo, Yesterday, 05:13 PM
            2 responses
            21 views
            0 likes
            Last Post quantismo  
            Working...
            X