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

Bars Since Exit Execution

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

    Bars Since Exit Execution

    I just added the barssinceexitexecution logic to my strategy but now no trades are being taken when back testing. I've been playing around with it for a few hours and can't seem to figure out the logic issue. The strategy executed lots of trades before adding the barssinceexitexecution logic.

    Here is my code:
    Code:
     Calculate = Calculate.OnBarClose;
    EntriesPerDirection=1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = false;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 1;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    Lot1 = 4;
    MinTickAway = 1;
    Profit=3;
    SL=650;
    TA=10;
    Bars=5;
    }
    else if (State == State.Configure)
    {
    
    AddDataSeries(BarsPeriodType.Minute, 120);
    //AddDataSeries(BarsPeriodType.Tick, 1);
    AddChartIndicator(AV());
    }
    }
    
    private double line=0;
    private double entry1_price=0;
    
    
    
    protected override void OnBarUpdate()
    {
    /*
    if (State==State.Realtime && Position.MarketPosition==MarketPosition.Flat)
    {
    EnterLong(Lot1,"Entry1");
    SetStopLoss("Entry1",CalculationMode.Ticks,100,tru e);
    SetProfitTarget("Entry1",CalculationMode.Ticks,100 ,true);
    
    
    
    }
    
    return;
    */
    
    if (Profit==1)
    line=AV().Av1[0];
    else if (Profit==2)
    line=AV().Av2[0];
    else if (Profit==3)
    line=AV().Av3[0];
    else if (Profit==4)
    line=AV().Av4[0];
    else if (Profit==5)
    line=AV().Av5[0];
    
    
    
    if (Position.MarketPosition==MarketPosition.Flat && BarsInProgress==0)
    {
    
    //ENTRY 1
    
    if ((BarsSinceExitExecution("Stop loss") > Bars || BarsSinceExitExecution("Stop loss") == -1) &&
    Close[0]+MinTickAway*TickSize<line)
    {
    //Print("The time and line are " + Time[0] + line);
    SetStopLoss("Entry1",CalculationMode.Ticks,SL,fals e);
    SetProfitTarget("Entry1",CalculationMode.Ticks,TA, false);
    EnterLong(Lot1,"Entry1");

    #2
    Hello mlprice12,

    You will want to use debugging prints to confirm the order submission methods are being reached and to also check the conditions controlling those order submission methods to see if they are allowing the condition to become true and why.

    The first step will be to reproduce the symptoms so you can add debugging prints for testing.

    After the issue is reproduced, you will want to add debugging prints to confirm that the logic in question is being reached and allowing the actions to be taken.

    I.E.

    Code:
    if (Close[0] > Open[0])
    {
        Print("Condition became true");
        ...
    }
    If the logic is not allowing the actions to be taken, the conditions controlling those actions will need to be debugged so you can observe how they evaluate and see why they are not allowing the actions to be taken.

    I.E.

    Code:
    Print("Close: " + Close[0] + " Open: " + Open[0]);
    if (Close[0] > Open[0])
    {
        ...
    }
    The above print will tell you what the Close and Open values are and can tell you why the condition below has/has not become true. You may take a similar approach to check if your condition is becoming true, and if it is not becoming true, you will know why.

    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim,

      The link you sent is directing me to page not found

      Comment


        #4
        Hello mlprice12,

        Could you try clearing your browser cache and refreshing the page? If you still cannot reach this page, can you share a screenshot showing the browser window, the URL and the page?

        Attaching a Screenshot

        To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

        Click here for instructions

        Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

        Click here for detailed instruction
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,602 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        12 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X