Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Beginner Advice Needed
Collapse
X
-
Hello hifreq,
You can use SetStopLoss at any time including in an if statement.
Once the stop loss has been set with SetStopLoss, you will not be able to remove the stop loss, however, you can modify the price at which it is sitting.
If you are only wanting to exit the trade when particular conditions are true (and not after the conditions were true but no longer are), it may be better to an exit order.
-
A little off topic here. But how do I write a Stoploss with an if statement. meaning i only want it to trigger or be true "if" a condition is met?
does it matter where in the code i insert the code for a stoploss
Leave a comment:
-
Hello,
What instrument are you trading on and if you switch to the points mode for the account performance report by selected it in the drop down menu to the right of the generate button does it show now?
If not toggle between the orders tab and the account performance tab to refresh it and try generate again.
-Brett
Leave a comment:
-
Now a paid Ninja customer whooohooo, quick question, when I do Market Replay and enter treades even while I stay connected to market replay when I pick the Replay account and the instrument I traded on it does not generate anything, keep showing just 0.00's , no report. Please advise how I can fix this
Leave a comment:
-
PSwarts,
Yes that should do the trick. If you run into further problem please let me know what output you are getting that is not expected so we know where to isolate.
-Brett
Leave a comment:
-
How do I set my stoploss to be (x)ticks below the lowest low of last three bars,when I make the changes as shown it does not work
SetStopLoss("Entry3", CalculationMode.Price, MIN(Low, 3)[0], true);
changed to
SetStopLoss("Entry3", CalculationMode.Price, MIN(Low, 3)[0]-20, true);
I presume it has to do with Price vs Ticks but does not know how to fix it
Oh think I found it: is this the correct way?:
SetStopLoss("Entry3", CalculationMode.Price, MIN(Low, 3)[0]-20 * TickSize, true);
Last edited by pswarts; 12-13-2011, 03:14 AM.
Leave a comment:
-
I believe that ExitOnClose = true; is the default. If you do not have any ExitOnClose statement, then you will be closed at exit.Originally posted by pswarts View PostThe strategy as discussed above when backtesting , give me frequent Exit on Close orders with (to me ) random distances from the entry orders at times, at other times the orders execute properly ,but I have no ExitLong or any other Exit for that matter in my code at all. Please advise on what the problem may be. Tnx
On the attached image the 2nd stoploss was at low of last three bars which is correct, the first order with an ExitOnClose makes no sense. I can attach more images if you need to demonstrate
Leave a comment:
-
pswarts, do you intend to hold positions overnight with this strategy? Then simply add ExitOnClose = false; to your Initialize() section and recompile - and those NT end of session exits should be disabled.
Leave a comment:
-
con'd
// Once 2st Profittarget attained, set stop loss to trail by Low of (x)bars
elseif (High[0] > Position.AvgPrice + ((2*Profitfactor) * (ATR(20)[0]))
&&MIN(Low ,3)[0] > Position.AvgPrice)
{
SetStopLoss("Entry3", CalculationMode.Price, MIN(Low, 3)[0], true);
}
}
// Entry Conditions
if (EMA(Ema)[0] > EMA(Ema)[1]
&& SMA(Sma)[0] > SMA(Sma)[1]
&& EMA(Ema)[0] > SMA(Sma)[0]
&& Close[0] > Open[0]
&& Position.MarketPosition == MarketPosition.Flat)
{
EnterLong(100, "Entry1");
EnterLong(100, "Entry2");
EnterLong(100, "Entry3");
}
}
Leave a comment:
-
cont'd
// Once 1st Profittarget attained, set stop loss to breakeven
if (High[0] >= Position.AvgPrice + ((1*Profitfactor) * (ATR(20)[0]))
&&High[0] <= Position.AvgPrice + ((2*Profitfactor) * (ATR(20)[0]))
&&Close[0] > Position.AvgPrice )
{
SetStopLoss("Entry2", CalculationMode.Price, Position.AvgPrice, true);
SetStopLoss("Entry3", CalculationMode.Price, Position.AvgPrice, true);
}
Leave a comment:
-
code cont'd
// If a long position is open, allow for stop loss and target modification
elseif (Position.MarketPosition == MarketPosition.Long)
{
SetProfitTarget("Entry1", CalculationMode.Price, Position.AvgPrice+((1*Profitfactor) * (ATR(20)[0])));
SetProfitTarget("Entry2", CalculationMode.Price, Position.AvgPrice+((2*Profitfactor) * (ATR(20)[0])));
SetStopLoss("Entry1", CalculationMode.Price, MIN(Low, 3)[0], true);
SetStopLoss("Entry2", CalculationMode.Price, MIN(Low, 3)[0], true);
SetStopLoss("Entry3", CalculationMode.Price, MIN(Low, 3)[0], true);
Leave a comment:
-
My current code as follows
protectedoverridevoid OnBarUpdate()
{
// Resets the stop loss and Targets to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss("Entry1", CalculationMode.Ticks, Stopfactor*3000, false);
SetStopLoss("Entry2", CalculationMode.Ticks, Stopfactor*3000, false);
SetStopLoss("Entry3", CalculationMode.Ticks, Stopfactor*3000, false);
SetProfitTarget("Entry1", CalculationMode.Ticks, 3000);
SetProfitTarget("Entry2", CalculationMode.Ticks, 3000);
}
Leave a comment:
-
The strategy as discussed above when backtesting , give me frequent Exit on Close orders with (to me ) random distances from the entry orders at times, at other times the orders execute properly ,but I have no ExitLong or any other Exit for that matter in my code at all. Please advise on what the problem may be. Tnx
On the attached image the 2nd stoploss was at low of last three bars which is correct, the first order with an ExitOnClose makes no sense. I can attach more images if you need to demonstrateAttached FilesLast edited by pswarts; 12-08-2011, 02:34 AM.
Leave a comment:
-
Pretty much. Remember to reset your SetProfitTarget() when you go flat.Originally posted by pswarts View PostJust to confirm: I'm to add the following between my Initialize and OnBarUpdate ?
protected override void Initialize ()
SetProfitTarget("Entry1", CalculationMode.Ticks, 200);
SetProfitTarget("Entry2", CalculationMode.Ticks, 200);
protected override void OnStartUp ()
SetProfitTarget("Entry1", CalculationMode.Price, (1*Profitfactor) * (ATR(20)[0]));
SetProfitTarget("Entry2", CalculationMode.Price, (2*Profitfactor) * (ATR(20)[0]));
protected override void OnBarUpdate ()
asbefore........
Leave a comment:
-
Just to confirm: I'm to add the following between my Initialize and OnBarUpdate ?
protected override void Initialize ()
SetProfitTarget("Entry1", CalculationMode.Ticks, 200);
SetProfitTarget("Entry2", CalculationMode.Ticks, 200);
protected override void OnStartUp ()
SetProfitTarget("Entry1", CalculationMode.Price, (1*Profitfactor) * (ATR(20)[0]));
SetProfitTarget("Entry2", CalculationMode.Price, (2*Profitfactor) * (ATR(20)[0]));
protected override void OnBarUpdate ()
asbefore........
Leave a comment:
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by SalmaTrader, 07-07-2026, 10:26 PM
|
0 responses
103 views
0 likes
|
Last Post
by SalmaTrader
07-07-2026, 10:26 PM
|
||
|
Started by CarlTrading, 07-05-2026, 01:16 PM
|
0 responses
62 views
0 likes
|
Last Post
by CarlTrading
07-05-2026, 01:16 PM
|
||
|
Started by CaptainJack, 06-17-2026, 10:32 AM
|
0 responses
28 views
0 likes
|
Last Post
by CaptainJack
06-17-2026, 10:32 AM
|
||
|
Started by kinfxhk, 06-17-2026, 04:15 AM
|
0 responses
36 views
0 likes
|
Last Post
by kinfxhk
06-17-2026, 04:15 AM
|
||
|
Started by kinfxhk, 06-17-2026, 04:06 AM
|
0 responses
40 views
0 likes
|
Last Post
by kinfxhk
06-17-2026, 04:06 AM
|

Leave a comment: