Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Consecutive Bars
Collapse
X
-
Hello bgump55,
Welcome to the NinjaTrader forums!
Print(string.Format("{0} | IsFirstTickOfBar: {1} && Close[0]: {2} > Open[0]: [3] && Close[1]: {4} > Open[1]: {5}", Time[0], IsFirstTickOfBar, Close[0], Open[0], Close[1], Open[1]));
if (IsFirstTickOfBar == true && Close[0] > Open[0] && Close[1] > Open[1])Chelsea B.NinjaTrader Customer Service
-
Follow up. I would like to set stop and profit once I enter trade using the code below. The SetStopLoss and SetProfitTarget in the State.Configure section don't seem to be working at all. Is there a way to say if ticks = -8 exit or if ticks = 16 exit?
bool market_open = ToTime(Time[0]) > 080000 && ToTime(Time[0]) < 133000;
bool tradeOpen = false;
double Bar1len = Close[0] - Open[0];
// double influenceBar = High[4] - (Open[2]+3);
if (market_open && IsFirstTickOfBar == true && Close[0] < Open[0] && Close[1] < Open[1] && Close[2] > Open[2] && Bar1len < -1.25)
EnterShort();
tradeOpen = true;
Comment
-
So that doesn't seem to work. It enters the trade but closes it only at End of Day. It makes one trade a day. Here is the whole code:
namespace NinjaTrader.NinjaScript.Strategies
{
public class Test2Unlocked : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "Test2Unlocked";
Calculate = Calculate.OnBarClose;
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)
{
SetStopLoss(@"8", CalculationMode.Ticks, 0, false);
SetProfitTarget(@"16", CalculationMode.Ticks, 0);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
bool market_open = ToTime(Time[0]) > 080000 && ToTime(Time[0]) < 133000;
bool tradeOpen = false;
double Bar1len = Close[0] - Open[0];
if (market_open && IsFirstTickOfBar == true && Close[0] < Open[0] && Close[1] < Open[1] && Close[2] > Open[2] && Bar1len < -1.25)
EnterShort();
tradeOpen = true;
}
}
}
Comment
-
Hello bgump55,
SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool isSimulatedStop)
You have the fromEntrySignal named "8" but there is not entry order with the name "8". The fromEntrySignal attaches the stop loss to a specific entry. Your entry has no signalName so this should be an empty string.
You have the number of ticks set to 0. The distance in ticks has be 1 or greater. If you supply a 0, no stop will be submitted.
Have you tried the code I suggested to you in post # 5?Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by JoMoon2024, Today, 06:56 AM
|
0 responses
6 views
0 likes
|
Last Post
by JoMoon2024
Today, 06:56 AM
|
||
Started by Haiasi, 04-25-2024, 06:53 PM
|
2 responses
17 views
0 likes
|
Last Post
by Massinisa
Today, 05:32 AM
|
||
Started by Creamers, Today, 05:32 AM
|
0 responses
5 views
0 likes
|
Last Post
by Creamers
Today, 05:32 AM
|
||
Net Change
by Segwin
Started by Segwin, 05-07-2018, 02:15 PM
|
12 responses
1,786 views
0 likes
|
Last Post
by Leafcutter
Today, 05:30 AM
|
||
Started by poplagelu, Today, 05:00 AM
|
0 responses
3 views
0 likes
|
Last Post
by poplagelu
Today, 05:00 AM
|
Comment