Announcement

Collapse
No announcement yet.

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 PWillard, Today, 12:56 AM
        0 responses
        1 view
        0 likes
        Last Post PWillard  
        Started by WidenThur, Today, 12:48 AM
        0 responses
        1 view
        0 likes
        Last Post WidenThur  
        Started by devidbelly, Today, 12:39 AM
        0 responses
        2 views
        0 likes
        Last Post devidbelly  
        Started by anderson, Yesterday, 11:06 PM
        0 responses
        1 view
        0 likes
        Last Post anderson  
        Started by eseorafva, Yesterday, 10:43 PM
        0 responses
        0 views
        0 likes
        Last Post eseorafva  
        Working...
        X