// This strategy enters a trade when the bid/ask imbalances are stacked in a certain way and exits when the imbalances change or a certain profit target is reached
// Include the necessary NinjaScript libraries
using System;
using System.Collections.Generic;
using System.Linq;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.NinjaScript;
using NinjaTrader.Strategy;
// Declare the strategy class and inherit from the Strategy base class
public class Footprint_Stacking_Imbalances_Strategy : Strategy
{
// Set the input parameters for the strategy
private int stackingThreshold = 3;
private int profitTarget = 10;
// Declare variables to track the bid and ask imbalances
private int bidImbalance = 0;
private int askImbalance = 0;
// Override the Initialize method to set up the strategy
protected override void Initialize()
{
// Set the default order type to market order
DefaultOrderType = OrderType.Market;
// Set the entry and exit types for the strategy
EntryHandling = EntryHandling.UniqueEntries;
ExitHandling = ExitHandling.UseDefault;
}
// Override the OnBarUpdate method to specify the strategy's logic
protected override void OnBarUpdate()
{
// Check if the current bar is the first bar
if (CurrentBars[0] == 0)
{
// If it is, initialize the bid and ask imbalances to 0
bidImbalance = 0;
askImbalance = 0;
}
// Check if the bid imbalance is greater than or equal to the stacking threshold
if (bidImbalance >= stackingThreshold)
{
// If it is, enter a long position
EnterLong();
}
// Check if the ask imbalance is greater than or equal to the stacking threshold
if (askImbalance >= stackingThreshold)
{
// If it is, enter a short position
EnterShort();
}
// Check if the trade has reached the profit target
if (Position.ProfitCurrency >= profitTarget)
{
// If it has, exit the trade
ExitLong();
ExitShort();
}
// Reset the bid and ask imbalances to 0 at the end of each bar
bidImbalance = 0;
askImbalance = 0;
}
// Override the OnOrderUpdate method to track the bid and ask imbalances
protected override void OnOrderUpdate(IOrder order)
{
// Check if the order is a buy or sell order
if (order.OrderAction == OrderAction.Buy)
{
// If it is a buy order, increment the bid imbalance
bidImbalance++;
}
else if (order.OrderAction == OrderAction.Sell)
{
// If it is a sell order, increment the ask imbalance
askImbalance++;
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Ninjascript Error
Collapse
X
-
Ninjascript Error
So I created the following strategy and it won't compile because there is an error LINE 87. How can I solve it?
Code:Tags: None
-
-
zakarianada Same error, but different line (88 vs 87) and only one of them now, not two. This means the same error is still there and you've only fixed one of the two occurrences of it. This remaining error is because there needs to be (yet another) closing brace (i.e. "}"), after the one in line 88 to close the Strategy class declaration "public class Footprint_..." opening brace.
Thanks.
Comment
-
It has been resolved but other errors appeared.. I don't think I can do it after all. Thank you for ur responseOriginally posted by jeronymite View Postzakarianada Same error, but different line (88 vs 87) and only one of them now, not two. This means the same error is still there and you've only fixed one of the two occurrences of it. This remaining error is because there needs to be (yet another) closing brace (i.e. "}"), after the one in line 88 to close the Strategy class declaration "public class Footprint_..." opening brace.
Thanks.
Comment
-
Hello zakarianada,
Thanks for your post.
"It has been resolved but other errors appeared.. I don't think I can do it after all. Thank you for ur response"
I am happy to hear you were able to resolve the compile error mentioned in your initial post.
What exactly do the other compile errors you mentioned state?
If possible, please share a screenshot of the compile errors left so that I may provide further direction on resolving them.
I look forward to assisting further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
53 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
70 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment