SI
SI
discoversearch

We've detected that you're using an ad content blocking browser plug-in or feature. Ads provide a critical source of revenue to the continued operation of Silicon Investor.  We ask that you disable ad blocking while on Silicon Investor in the best interests of our community.  If you are not using an ad blocker but are still receiving this message, make sure your browser's tracking protection is set to the 'standard' level.
Microcap & Penny Stocks : MY THREAD -- Ignore unavailable to you. Want to Upgrade?


To: Qone0 who wrote (140)4/16/2025 2:10:21 PM
From: Qone0  Read Replies (1) | Respond to of 143
 
#region Using declarations
using System;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Cbi;
using NinjaTrader.NinjaScript.Strategies;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class AdvancedESFuturesStrategy : Strategy
{
private EMA emaShort; // Short-term EMA (e.g., 9 EMA)
private SMA smaLong; // Long-term SMA (e.g., 50 SMA)
private RSI rsi; // Relative Strength Index
private VWAP vwap; // Volume Weighted Average Price
private double priorDayHigh;
private double priorDayLow;
private double priorDayClose;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Advanced day trading strategy for ES futures.";
Name = "AdvancedESFuturesStrategy";
Calculate = Calculate.OnEachTick;
IsUnmanaged = false;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = true;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 1;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelCloseIgnoreRejects;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsInstantiatedOnEachOptimizationIteration = true;
MinBarsRequired = 20;
DaysToLookBack = 3;
// Strategy Parameters
SetStopLoss(CalculationMode.Ticks, 12); // Stop loss in ticks
SetProfitTarget(CalculationMode.Ticks, 24); // Profit target in ticks
}
else if (State == State.Configure)
{
emaShort = EMA(9);
smaLong = SMA(50);
rsi = RSI(14, 3);
vwap = VWAP();
}
else if (State == State.DataLoaded)
{
priorDayHigh = Highs[1][0];
priorDayLow = Lows[1][0];
priorDayClose = Closes[1][0];
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < MinBarsRequired)
return;
// Check if market is trending or ranging
bool isTrending = emaShort[0] > smaLong[0] && Math.Abs(emaShort[0] - smaLong[0]) > TickSize * 10;
// Trend-following entry logic
if (isTrending && rsi[0] < 70 && CrossAbove(emaShort, smaLong, 1))
{
EnterLong("TrendFollowLong");
}
else if (isTrending && rsi[0] > 30 && CrossBelow(emaShort, smaLong, 1))
{
EnterShort("TrendFollowShort");
}
// Range-bound entry logic
if (!isTrending && Close[0] > priorDayLow && Close[0] < priorDayHigh)
{
if (rsi[0] > 70)
{
EnterShort("RangeBoundShort");
}
else if (rsi[0] < 30)
{
EnterLong("RangeBoundLong");
}
}
// Exit conditions
if (Position.MarketPosition == MarketPosition.Long && Close[0] >= vwap[0])
{
ExitLong("VWAPExitLong");
}
else if (Position.MarketPosition == MarketPosition.Short && Close[0] <= vwap[0])
{
ExitShort("VWAPExitShort");
}
}
}
}