Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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;
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?
Can you help answer these questions from other members on NexusFi?
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
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.
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?
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.