Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
double / triple breakeven in the builder and a final takeprofit
Collapse
X
-
double / triple breakeven in the builder and a final takeprofit
hi, I am not a programmer and I would like if possible some suggestions on how to set up a double / triple breakeven in the builder and a final takeprofit starting from your example in which we have a single breakeven. thank you so muchTags: None
-
Hello matrix74,
Welcome to the NinjaTrader forums!
While I am not able to write the code on your behalf, I can answer any questions you may have if you are getting stuck.
Are you wanting to have multiple entry orders and each has different logic for when the stop is moved the entry price?
Are you wanting custom trailing logic to move a single stop multiple times?
I have an example of custom trailing logic which I am linking below.
Chelsea B.NinjaTrader Customer Service
-
361/5000
I cannot understand where I am wrong, my idea is to move the initial stop when the market is in my favor by 5 ticks (stop at +1) and when it reaches 9 ticks the stop should move to +4. I had also added the canons stop and profit, but so the strategy does not work. Can you suggest where I'm wrong? thank you so much
public class BreakEvenBuilderExample : Strategy
{
private double StopPrice;
private double TriggerPrice;
private int TriggerState;
private double TriggerPrice1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"";
Name = "BreakEvenBuilderExample";
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;
BreakEvenTrigger = 5;
InitialStopDistance = -10;
BreakEvenTrigger9 = 9;
MoveTicks1BE = 1;
MoveTicks2BE = 4;
TakeProfit = 15;
StopLoss = 14;
StopPrice = 0;
TriggerPrice = 0;
TriggerState = 0;
TriggerPrice1 = 0;
}
else if (State == State.Configure)
{
SetProfitTarget("", CalculationMode.Ticks, TakeProfit);
SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
// Set 1
if ((TriggerState >= 3)
&& (Position.MarketPosition == MarketPosition.Flat))
{
TriggerState = 0;
}
if (CurrentBars[0] < 1)
return;
// Set 2
if ((TriggerState == 1)
&& (Position.MarketPosition == MarketPosition.Long))
{
TriggerState = 2;
StopPrice = (Position.AveragePrice + (InitialStopDistance * TickSize)) ;
TriggerPrice = (Position.AveragePrice + (BreakEvenTrigger * TickSize)) ;
}
// Set 3
if (Position.MarketPosition == MarketPosition.Flat)
{
TriggerState = 1;
EnterLong(Convert.ToInt32(DefaultQuantity), @"entry");
}
// Set 4
if ((TriggerState == 2)
&& (Close[0] >= TriggerPrice))
{
TriggerState = 3;
StopPrice = (Position.AveragePrice + (MoveTicks1BE * TickSize)) ;
Draw.Diamond(this, @"BreakEvenBuilderExample Diamond_1", true, 0, (High[0] + (2 * TickSize)) , Brushes.DarkCyan);
}
// Set 5
if (TriggerState >= 3)
{
ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), StopPrice, @"exit", @"entry");
}
// Set 6
if ((TriggerState == 3)
&& (Close[0] >= TriggerPrice1))
{
TriggerState = 4;
StopPrice = (Position.AveragePrice + (MoveTicks2BE * TickSize)) ;
Draw.Diamond(this, @"BreakEvenBuilderExample Diamond_1", true, 0, (High[0] + (2 * TickSize)) , Brushes.DarkCyan);
}
}
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
69 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
42 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
24 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
27 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
54 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment