Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy submits orders in replay and realtime not in analyzer
Collapse
X
-
Tags: None
-
Hello Sleeping Troll,
Can you please check if the requested historical data is available. Please click the Chart-tab and check if all requested historical data is reflected.
Is this a 3rd party or custom created strategy?
The Strategy Analyzer will only calculate your strategy conditions at the close of price bars (Calculate on bar close = True). Could this be related?JasonNinjaTrader Customer Service
-
I created the strategy, I can run it on replay and it works just fine, however in backtesting I get no trades. Chart shows data but no trades.
Yeah, calculate on bar close would do it! Wow, that is rather important to my strategy, can I use 1 tick bars?Last edited by Sleeping Troll; 05-18-2010, 06:59 AM.
Comment
-
-
Still, no joy! tried with 1 minute bars, same result.
Code:protected override void Initialize() { CalculateOnBarClose = true; TimeInForce = Cbi.TimeInForce.Gtc; SeekType = null; Indication = null; OrderPending = null; EntriesPerDirection = 2; EntryHandling = EntryHandling.AllEntries; TraceOrders = true; EntryPriceLong = 0; EntryPriceShort = 0; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (Historical)return; if (Bars.FirstBarOfSession) { BlackFlag = false; Market = "New Session"; return; } if (FirstTickOfBar)Process = true; if (Process == false)return; if (Time[0] > new DateTime(2010,10,13,00,00,00,00,00))return; Upper = Fibs().CurrentChannelUpper; Lower = Fibs().CurrentChannelLower; if (Upper - Lower < (Span * TickSize) && Market != "Thin") { period = 14; Fast = 12; Slow = 26; Smooth = 9; numStdDev = 1; Market = "Thin"; } if (Upper - Lower >= (Span * TickSize) && Market != "Normal") { period = 14; Fast = 6; Slow = 13; Smooth = 9; numStdDev = 1; Market = "Normal"; } if (Upper - Lower > (4 * Span * TickSize) && Market != "Fat") { period = 14; Fast = 26; Slow = 60; Smooth = 9; numStdDev = 1; Market = "Fat"; } if (Performance.AllTrades.Count > 0 && Performance.AllTrades.TradesPerformance.GrossProfit + Performance.AllTrades.TradesPerformance.GrossLoss <= -flag) { period = 14; Fast = 36; Slow = 89; Smooth = 9; numStdDev = 1; BlackFlag = true; } Status = MACDBBLines(period,Fast,Slow,Smooth,numStdDev).Status; Confirm = MACDBBLines(period,Fast,Slow,Smooth,numStdDev).Confirm; Avg = MACDBBLines(period,Fast,Slow,Smooth,numStdDev).Avg; if (Math.Abs(Trend().TrendSlopeShort)< .005) { return; } #region Seek Type if (Position.MarketPosition == MarketPosition.Flat && OrderPending == null) { if (Market == "Thin") { if (Status == true && Avg > 0 && Input[0] > Fibs().O[1] && Lower > TickSize) { SeekType = true; EntryPriceLong = Lower; } else SeekType = null; if (Status == false && Avg < 0 && Input[0] < Fibs().O[1] && Upper > TickSize) { SeekType = false; EntryPriceShort = Upper; } } if (Market != "Thin" && Math.Abs(Trend().TrendSlopeShort) < Math.Abs(Trend().TrendSlopeLong)) { if (Trend().TrendSlopeLong > 0 && SeekType != true && Status == true) { SeekType = true; } else SeekType = null; if (Trend().TrendSlopeLong < 0 && SeekType != false && Status == false) { SeekType = false; EntryPriceShort = Upper - (Entry * TickSize); } } } #endregion #region Entry Triggers if (Market == "Thin" && Position.MarketPosition == MarketPosition.Flat && OrderPending == null && SeekType == true) { return; EntryPriceLong = Lower; StopLong = Lower - (Hide * TickSize); SetStopLoss(CalculationMode.Price,StopLong); SetProfitTarget("LongBank",CalculationMode.Price,EntryPriceLong + (Bank * TickSize)); LongBank = EnterLongLimit(0,true,1 + orderQuantity,EntryPriceLong,"LongBank"); LongRunner = EnterLongLimit(0,true,orderQuantity,EntryPriceLong,"LongRunner"); OrderPending = true; } if (Market == "Normal" && Position.MarketPosition == MarketPosition.Flat && OrderPending == null && SeekType == true) { EntryPriceLong = Lower + (Entry * TickSize); StopLong = Lower - (Hide * TickSize); Cancel = Upper; SetStopLoss(CalculationMode.Price,StopLong); SetProfitTarget("LongBank",CalculationMode.Price,EntryPriceLong + (Bank * TickSize)); LongBank = EnterLongLimit(0,true,1 + orderQuantity,EntryPriceLong,"LongBank"); LongRunner = EnterLongLimit(0,true,orderQuantity,EntryPriceLong,"LongRunner"); OrderPending = true; } if (Market == "Fat" && Position.MarketPosition == MarketPosition.Flat && OrderPending == null && SeekType == true && Input[0] > Lower + (Hide * TickSize) && Input[0] < Upper - (Hide * TickSize)) { EntryPriceLong = Lower + (Entry * TickSize); StopLong = Lower - (Hide * TickSize); Cancel = Upper - (Hide * TickSize); SetStopLoss(CalculationMode.Price,StopLong); SetProfitTarget("LongBank",CalculationMode.Price,EntryPriceLong + (Bank * TickSize)); LongBank = EnterLongLimit(0,true,1 + orderQuantity,EntryPriceLong,"LongBank"); LongRunner = EnterLongLimit(0,true,orderQuantity,EntryPriceLong,"LongRunner"); OrderPending = true; } if (Market == "Thin" && Position.MarketPosition == MarketPosition.Flat && OrderPending == null && SeekType == false) { return; EntryPriceShort = Upper; StopShort = Upper + (Hide * TickSize); SetStopLoss(CalculationMode.Price,StopShort); SetProfitTarget("ShortBank",CalculationMode.Price,EntryPriceShort - (Bank * TickSize)); ShortBank = EnterShortLimit(0,true,1 + orderQuantity,EntryPriceShort,"ShortBank"); ShortRunner = EnterShortLimit(0,true,orderQuantity,EntryPriceShort,"ShortRunner"); OrderPending = false; } if (Market == "Normal" && Position.MarketPosition == MarketPosition.Flat && OrderPending == null && SeekType == true) { EntryPriceShort = Upper - (Entry * TickSize); StopShort = Upper + (Hide * TickSize); Cancel = Lower; SetStopLoss(CalculationMode.Price,StopShort); SetProfitTarget("ShortBank",CalculationMode.Price,EntryPriceShort - (Bank * TickSize)); ShortBank = EnterShortLimit(0,true,1 + orderQuantity,EntryPriceShort,"ShortBank"); ShortRunner = EnterShortLimit(0,true,orderQuantity,EntryPriceShort,"ShortRunner"); OrderPending = false; } if (Market == "Fat" && Position.MarketPosition == MarketPosition.Flat && OrderPending == null && SeekType == false && Input[0] > Lower + (Hide * TickSize) && Input[0] < Upper - (Hide * TickSize)) { EntryPriceShort = Upper - (Entry * TickSize); StopShort = Upper + (Hide * TickSize); Cancel = Lower + (Hide * TickSize); SetStopLoss(CalculationMode.Price,StopShort); SetProfitTarget("ShortBank",CalculationMode.Price,EntryPriceShort - (Bank * TickSize)); ShortBank = EnterShortLimit(0,true,1 + orderQuantity,EntryPriceShort,"ShortBank"); ShortRunner = EnterShortLimit(0,true,orderQuantity,EntryPriceShort,"ShortRunner"); OrderPending = false; } #endregion #region Order Maintenance if (Market != "Thin" && Position.MarketPosition == MarketPosition.Flat && LongRunner != null && Input[0] >= Cancel && OrderPending == true) { CancelOrder(LongRunner); Print ("Long Cancel due to new fib approached"); if (LongBank != null) { CancelOrder(LongBank); Process = false; } OrderPending = null; } if (Market != "Thin" && Position.MarketPosition == MarketPosition.Flat && ShortRunner != null && Input[0] <= Cancel && OrderPending == false) { CancelOrder(ShortRunner); Print ("Short Cancel due to new fib approached"); if (ShortBank != null) { CancelOrder(ShortBank); Process = false; } OrderPending = null; } if (Position.MarketPosition == MarketPosition.Flat && LongRunner != null && Status == false && OrderPending == true) { CancelOrder(LongRunner); Print ("Long Cancel due to Status failed"); if (LongBank != null) { CancelOrder(LongBank); Process = false; } OrderPending = null; } if (Position.MarketPosition == MarketPosition.Flat && ShortRunner != null && Status == true && OrderPending == false) { CancelOrder(ShortRunner); Print ("Short Cancel due to Status failed"); if (ShortBank != null) { CancelOrder(ShortBank); Process = false; } OrderPending = null; } if(Market != "Fat" && Position.MarketPosition == MarketPosition.Long && StopLong < Lower - (Hide * TickSize)) { StopLong = Lower - (Hide * TickSize); SetStopLoss(CalculationMode.Price,StopLong); } if(Market == "Fat" && Input[0] > EntryPriceLong + (Hide * TickSize) && Position.MarketPosition == MarketPosition.Long) { StopLong = EntryPriceLong; SetStopLoss(CalculationMode.Price,StopLong); EntryPriceLong = EntryPriceLong + (Hide * TickSize); } if(Market != "Fat" && Position.MarketPosition == MarketPosition.Short && StopShort >= Upper + (Hide * TickSize)) { StopShort = Upper + (Hide * TickSize); SetStopLoss(CalculationMode.Price,StopShort); } if(Market == "Fat" && Input[0] < EntryPriceShort - (Hide * TickSize) && Position.MarketPosition == MarketPosition.Short) { StopShort = EntryPriceShort; SetStopLoss(CalculationMode.Price,StopShort); EntryPriceShort = EntryPriceShort - (Hide * TickSize); } if (BlackFlag == false && Position.MarketPosition == MarketPosition.Flat && Performance.AllTrades.Count > 0 && Performance.AllTrades[Performance.AllTrades.Count - 1].ProfitPoints > 0 && orderSet != true) { orderQuantity++; orderSet = true; } if (Position.MarketPosition == MarketPosition.Flat && Performance.AllTrades.Count > 1 && Performance.AllTrades[Performance.AllTrades.Count - 1].ProfitPoints <= 0) { orderQuantity = 1; orderSet = false; } #endregion } protected override void OnOrderUpdate(IOrder order) { if (LongRunner != null && LongRunner.Token == order.Token) { if (LongRunner.OrderState == OrderState.Filled) { OrderPending = null; //orderSet = false; } } if (ShortRunner != null && ShortRunner.Token == order.Token) { if (ShortRunner.OrderState == OrderState.Filled) { OrderPending = null; //orderSet = false; } } }
Last edited by Sleeping Troll; 05-18-2010, 07:48 AM.
Comment
-
What happens if you exclude?
if (Historical)return;
I am not a programmer and not very familiar with code. However I believe this statement will cause the strategy not to be calculated on historical data.
When backtesting in the Strategy Analyzer, the strategy will be calculated on historical data only.JasonNinjaTrader Customer Service
Comment
-
-
I have stripped my strategy down to the point where I really don't expect success, and still no backtest... I have to ask, why calculate on bar close?
Comment
-
Unfortunately, I am not sure if I follow your inquiry.
The Strategy Analyzer will only calculate conditions at the end of the bar (Calculate on bar close = True) - this is by design.
I suggest to debug your strategy to check why it does not trigger orders in the Strategy Analyzer. You can find general debug information at the link below.
JasonNinjaTrader Customer Service
Comment
-
-
This is a conservative approach based on limited information. The only 4 data points known to you are Open, High, Low, Close. There's no way to tell if either the low or high came first. If you're accessing Close then this happens at the same time as the next bar open. NinjaTrader does not allow you to "peak" into the future with the backtesting engine.Ryan M.NinjaTrader Customer Service
Comment
-
-
Yes, another approach is needed if you want to add another series. Everything is still considered CalculateOnBarClose = true.
For help implementing this, please see our reference sample on backtesting NinjaScript strategies with an intrabar granularityRyan M.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by bortz, 11-06-2023, 08:04 AM
|
47 responses
1,603 views
0 likes
|
Last Post
by aligator
Today, 07:22 PM
|
||
Started by jaybedreamin, Today, 05:56 PM
|
0 responses
8 views
0 likes
|
Last Post
by jaybedreamin
Today, 05:56 PM
|
||
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
4 views
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
12 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
Comment