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

  • NinjaTrader_AlanP
    replied
    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.

    Leave a comment:


  • esignal
    replied
    🙁..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.

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    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.

    Leave a comment:


  • esignal
    replied
    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

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    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.

    Leave a comment:


  • esignal
    started a topic Order rejected

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by rdtdale, Yesterday, 01:02 PM
2 responses
15 views
0 likes
Last Post rdtdale
by rdtdale
 
Started by TradeSaber, Today, 07:18 AM
0 responses
7 views
0 likes
Last Post TradeSaber  
Started by PaulMohn, Today, 05:00 AM
0 responses
10 views
0 likes
Last Post PaulMohn  
Started by ZenCortexAuCost, Today, 04:24 AM
0 responses
6 views
0 likes
Last Post ZenCortexAuCost  
Started by ZenCortexAuCost, Today, 04:22 AM
0 responses
3 views
0 likes
Last Post ZenCortexAuCost  
Working...
X