SetStopLoss("EnterLong", CalculationMode.Ticks, stopticks, true);//100 SetStopLoss("EnterShort", CalculationMode.Ticks, stopticksS, true);//85 SetProfitTarget("EnterLong", CalculationMode.Ticks, profittarget);//79 SetProfitTarget("EnterShort",CalculationMode.Ticks, profittargetS);//55 } protected override void OnBarUpdate() { #region Stoploss Modification // Resets the stop loss to the original value when all positions are closed if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss("EnterLong", CalculationMode.Ticks, stopticks, true); } // If a long position is open, allow for stop loss modification else if (Position.MarketPosition == MarketPosition.Long) { if (Close[0] >= Position.AvgPrice + (TickSize*10)) { SetStopLoss("EnterLong", CalculationMode.Price, Close[0] - (TickSize*15), true); } } if (Position.MarketPosition == MarketPosition.Short) { if (Close[0] <= Position.AvgPrice - (TickSize*12)) { SetStopLoss("EnterShort", CalculationMode.Ticks, TickSize*15, true); } }
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
stoploss modification
Collapse
X
-
stoploss modification
I looked over the sample stoploss modification but its for long only, how would u set it up for combination w a short? Should there be a seperate reset if flat for both sides? I tried the below but only one of the stops triggers orders.
Code:Last edited by zachj; 02-10-2014, 03:09 PM.Tags: None
-
I think I got it working. Just to make sure though, should I have seperate code as I have below to reset the Long and then another to reset the Short position? The "fromEntrySignal" directs each accordingly?
Code:if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss("EnterLong", CalculationMode.Ticks, 100, true); } if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss("EnterShort", CalculationMode.Ticks, 85, true); }
Comment
-
Not quite how you're thinking it will work.
Since you are using different fromEntrySignals the StopLoss's that are being called will have their own separate logic for the entries.
If you combined them you would be telling the system that any Entry Signal with those names to use the associated parameters.Cal H.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Cal View PostNot quite how you're thinking it will work.
Since you are using different fromEntrySignals the StopLoss's that are being called will have their own separate logic for the entries.
If you combined them you would be telling the system that any Entry Signal with those names to use the associated parameters.
Comment
-
Zachj,
Code:if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss("EnterLong", CalculationMode.Ticks, 100, true); } if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss("EnterShort", CalculationMode.Ticks, 85, true); }
Code:if(Position.MarketPosition == MarketPosition.Flat) { SetStopLoss("EnterLong", CalculationMode.Ticks, 100, true); SetStopLoss("EnterShort", CalculationMode.Ticks, 85, true); }
Cal H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by geddyisodin, Yesterday, 05:20 AM
|
7 responses
45 views
0 likes
|
Last Post Today, 07:07 AM | ||
Started by gbourque, Today, 06:39 AM
|
2 responses
5 views
0 likes
|
Last Post
by gbourque
Today, 07:05 AM
|
||
Started by cre8able, Yesterday, 07:24 PM
|
1 response
13 views
0 likes
|
Last Post Today, 06:55 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
6 responses
939 views
0 likes
|
Last Post
by Jquiroz1975
Today, 06:51 AM
|
||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
1 response
17 views
0 likes
|
Last Post Today, 06:16 AM |
Comment