NexusFi: Find Your Edge


Home Menu

 





BarsSinceEntryExecution isn't working.


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one alecsaccount with 29 posts (0 thanks)
    2. looks_two rleplae with 20 posts (19 thanks)
    3. looks_3 gisot with 3 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 15,929 views
    2. thumb_up 19 thanks given
    3. group 3 followers
    1. forum 52 posts
    2. attach_file 11 attachments




 
Search this Thread

BarsSinceEntryExecution isn't working.

  #1 (permalink)
 alecsaccount 
San Diego, California
 
Experience: Beginner
Platform: NinjaTrader 8
Trading: Emini ES, EUR/USD
Posts: 65 since Dec 2016
Thanks Given: 229
Thanks Received: 13

I want my strategy to exit when a long SMA crosses below a short SMA, and it's been less than 14 bars since entry.. So I used the strategy builder to add a set of conditions;

BarsSinceEntryExecution() < 14
SMA(X)[0] < SMA(Y)[0]

And now the summary is blank and there are no trades on the chart. There should be plenty of trades where X crossed below Y within 14 bars after entry, and even if there weren't, why would that change the results? What's wrong with what I did?

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
Quant vue
Trading Reviews and Vendors
Cheap historycal L1 data for stocks
Stocks and ETFs
MC PL editor upgrade
MultiCharts
 
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


I think it would be good if you add some Print ("info....");
in your strategy, then you can follow and also Print the exact value that is returned ..

If it's -1, as per the manual, it means no entry is found
Which value does it return

Would probably also be helpful if you posted larger part of the code,
including how you constructed your if

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 alecsaccount 
San Diego, California
 
Experience: Beginner
Platform: NinjaTrader 8
Trading: Emini ES, EUR/USD
Posts: 65 since Dec 2016
Thanks Given: 229
Thanks Received: 13


rleplae View Post
I think it would be good if you add some Print ("info....");
in your strategy, then you can follow and also Print the exact value that is returned ..

If it's -1, as per the manual, it means no entry is found
Which value does it return

Would probably also be helpful if you posted larger part of the code,
including how you constructed your if

Sorry I missed this, it's weird. I checked my app 3 times that day and once the next day, and this thread didn't have any responses. :\

I don't know much about coding. I just made this in the strategy builder. Nothing happens when I click Run, unless I delete set 3. If I delete set 3 and compile, I get results.. I don't understand what could be causing this. Am I an idiot, and just using the indicator wrong?

update: so it still doesn't give results when I run it on high order fill resolution (1 tick), but it does give results on standard order fill resolution. this is useless to me, but I hope it helps you solve this problem. thanks so much for taking a look at this.

#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion

//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class Long : Strategy
{
private SMA SMA1;
private SMA SMA2;
private SMA SMA3;
private SMA SMA4;

protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "Long";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
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 = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
SMA1 = SMA(30);
SMA2 = SMA(10);
SMA3 = SMA(60);
SMA4 = SMA(20);
}
}

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

// Set 1
if ((Times[0][0].TimeOfDay >= new TimeSpan(6, 30, 0))
&& (Times[0][0].TimeOfDay < new TimeSpan(14, 30, 0))
&& (Position.MarketPosition == MarketPosition.Flat)
&& (SMA1[0] < SMA2[0]))
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
// Set 2
if ((Position.MarketPosition == MarketPosition.Long)
&& (SMA3[0] > SMA4[0]))
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
}
// Set 3
if ((SMA1[0] > SMA2[0])
&& (BarsSinceEntryExecution() <= 15))
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
}

}
}
}

#region Wizard settings, neither change nor remove

Started this thread Reply With Quote
  #5 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

If you open the output window and run it, does any error message appear ?

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 alecsaccount 
San Diego, California
 
Experience: Beginner
Platform: NinjaTrader 8
Trading: Emini ES, EUR/USD
Posts: 65 since Dec 2016
Thanks Given: 229
Thanks Received: 13


rleplae View Post
If you open the output window and run it, does any error message appear ?

This is probably a very stupid question, but how do I open the output window?

wait, I found it.

Strategy 'Long': Error on calling 'OnBarUpdate' method on bar 14: Strategy 'Long/-1': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceEntryExecution() method in the context of a multi-time frame and instrument strategy.

Started this thread Reply With Quote
  #7 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


alecsaccount View Post
This is probably a very stupid question, but how do I open the output window?

NinjaTrader -> tools -> output window

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #8 (permalink)
 alecsaccount 
San Diego, California
 
Experience: Beginner
Platform: NinjaTrader 8
Trading: Emini ES, EUR/USD
Posts: 65 since Dec 2016
Thanks Given: 229
Thanks Received: 13


rleplae View Post
NinjaTrader -> tools -> output window

Strategy 'Long': Error on calling 'OnBarUpdate' method on bar 14: Strategy 'Long/-1': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceEntryExecution() method in the context of a multi-time frame and instrument strategy.

edit; I didn't see anything called 'BarsInProgress' on the list. Did I miss it?

Started this thread Reply With Quote
  #9 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

If you have multiple time frames loaded on the chart, you need to select the timeframe you want this to work on

 
Code
 // Check which Bars object is calling the OnBarUpdate() method
    if (BarsInProgress == 0)
    {
        // A value of zero represents the primary Bars which is the ES 09-14
        // 1 minute chart.
        // Do something within the context of the 1 minute Bars here
    }
    else if (BarsInProgress == 1)
    {
        // A value of 1 represents the secondary 5 minute bars added in the Initialize()
        // Do something within the context of the 5 minute Bars
    }

Quoting 
BarsSinceEntryExecution()
BarsSinceEntryExecution(string signalName)



The following method signature should be used when working with multi-time frame and instrument strategies:



BarsSinceEntryExecution(int barsInProgressIndex, string signalName, int entryExecutionsAgo)

you have probably more than one instrument or dataseries loaded
if possible stick to one

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #10 (permalink)
 alecsaccount 
San Diego, California
 
Experience: Beginner
Platform: NinjaTrader 8
Trading: Emini ES, EUR/USD
Posts: 65 since Dec 2016
Thanks Given: 229
Thanks Received: 13



rleplae View Post
If you have multiple time frames loaded on the chart, you need to select the timeframe you want this to work on

 
Code
 // Check which Bars object is calling the OnBarUpdate() method
    if (BarsInProgress == 0)
    {
        // A value of zero represents the primary Bars which is the ES 09-14
        // 1 minute chart.
        // Do something within the context of the 1 minute Bars here
    }
    else if (BarsInProgress == 1)
    {
        // A value of 1 represents the secondary 5 minute bars added in the Initialize()
        // Do something within the context of the 5 minute Bars
    }


you have probably more than one instrument or dataseries loaded
if possible stick to one

Again, I'm not writing this with the ninjascript editor; I'm using the strategy builder because I have no experience coding whatsoever. So what you just wrote means very little to me.

I don't understand. I've only been running one time frame, one instrument, one data series, as far as I know.

Backtest type: Standard

Strategy: Long

Instrument: ES 12-16

Price based on: Last

Type: Minute

Value: 15

Start date: 01/01/2016

End date: 12/31/2016

Trading hours: <Use instrument settings>

Break at EOD: true

Include commission: false

Maximum bars lookback: Infinite

Bars required to trade: 20

Entries per direction: 1

Entry handling: All entries

Exit on session close: false

Set order quantity: Strategy

Time in force: GTC

Started this thread Reply With Quote




Last Updated on December 21, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts