if (CurrentBar == 0)
{
// do something;
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Reference a custom value
Collapse
X
-
yes, which goes back to what we were talking about early in the thread.
you only want to call the SetProfitTarget in 2 different cases.
1. When you first enter.
2. If the Swing value changes your target point.
you have to code this if you don't want it to be calculated each new bar; i agree, you don't
Comment
-
hi josh thanks for tuning in.
hmmm.. maybe I should use another approach then swing indicator for this?
Unfortunately I still cant get this to work. In my other trading software it's so easy to realize this:
I am really confused with all the scale in and scale out routines necessary to do this.Code://HILO SWING HiHi = Highest(High, 10); LoLo = Lowest(Low, 10); //First Exit Target If Marketpositionlong and CurrentContracts=4 then Exitlong ("TakeProfit") 2 Contracts at (Entryprice+(Entryprice-LoLo)) Limit; If MarketpositionShort and CurrentContracts=4 then Cover ("TakeProfit") 2 Contracts at (Entryprice-(Hihi-Entryprice)) Limit;
Is there no other possibility??
Comment
-
Phaseshifter,
Maybe this reference sample will help you. http://www.ninjatrader-support2.com/...ead.php?t=3751Josh P.NinjaTrader Customer Service
Comment
-
yeah this might help.
I now have it this way:
The problem now is variable "TarDis" seems to be always=0.Code:#region Variables // Wizard generated variables private int Swingbars = 5; // Default setting for MyInput0 // User defined variables (add any user defined variables below) private double TarDis; protected override void Initialize() { CalculateOnBarClose = true; EntriesPerDirection = 1; EntryHandling = EntryHandling.UniqueEntries; SetProfitTarget("Long1", CalculationMode.Ticks, TarDis); SetProfitTarget("Short1", CalculationMode.Ticks, TarDis); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // ENTER LONG #1 if (Close[0] > Open[0]) { EnterLongStop(2, High[0] + 1 * TickSize, "Long1"); EnterLongStop(2, High[0] + 1 * TickSize, "Long2"); } // ENTER SHORT #1 if (Close[0] < Close[0]) { EnterShortStop(2, Low[0] -1 * TickSize, "Short1"); EnterShortStop(2, Low[0] -1 * TickSize, "Short2"); } // PROFIT TARGET LONG if (Position.MarketPosition == MarketPosition.Long) { TarDis=((Position.AvgPrice-(Swing(Swingbars).SwingLow[0]))/TickSize); } // PROFIT TARGET SHORT if (Position.MarketPosition == MarketPosition.Short) { TarDis=(((Swing(Swingbars).SwingHigh[0])-Position.AvgPrice)/TickSize); }
Position Target Profit is immediately reached and it exits.
Where is my problem in calucating the Profit Distance?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment