![]() |
|
|||||||
| Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jun 2009
Posts: 735
Thanks: 19
Thanked 8 times in 8 posts
|
Hello,
I´m using stoploss with Donchian and I want to ask when the stoploss moves and changes his value? Can SetTrailStop be used for variable like Donchian? I remember in another thread there was the information that SetTrailStop doesn´t work with Mode.Price. So what do I have to code for having the stoploss each bar the actual value of Donchian? Thanks Tony
Last edited by tonynt; 07-26-2011 at 06:52 AM.
Reason: typing error
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Correct Tony, you can't use SetTrailStop then - you would call SetStopLoss again in your OnBarUpdate() if you would like to change the stop loss price, so basically each bar update as your Donchian value changes then.
http://www.ninjatrader.com/support/f...ead.php?t=3222
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jun 2009
Posts: 735
Thanks: 19
Thanked 8 times in 8 posts
|
Thanks Bertrand,
but it doesn´t change each bar!. It changes only when the if condition is filled (here the 90 ticks) - referring to the samplepricemodification. This is my coding - I think it should be correct as done same as in the sample. if (BarsInProgress !=0) return; stop1=DonchianChannel(3).Upper[0]+5*TickSize; stop2=DonchianChannel(5).Upper[0]+5*TickSize; stop3=DonchianChannel(6).Upper[0]+5*TickSize; if(Position.MarketPosition == MarketPosition.Flat) { SetStopLoss("SG1", CalculationMode.Price, stop1, false); SetStopLoss("SG2", CalculationMode.Price, stop1, false); SetStopLoss("SG3", CalculationMode.Price, stop1, false); if (Position.MarketPosition == MarketPosition.Short && Close[0] < Position.AvgPrice - 90 * TickSize) { SetStopLoss("SG1", CalculationMode.Price, stop1, false); SetStopLoss("SG2", CalculationMode.Price, stop2, false); SetStopLoss("SG3", CalculationMode.Price, stop3, false); } Why does stop move only with the if condition and not from the beginning each bar? I´m in the direction of the trade maybe 80 ticks and Donchians moves with my bars but the initial stoploss stays same value. Thanks Tony |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
Tony, the stop is only moving with the if conditions because you've placed it in the if statement code block.
It will also not move until the trade is 90 ticks in profit. Please try simplifying your strategy to one position and one moving stop loss and once you get that figured out you can add the additional positions and stops.
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jun 2009
Posts: 735
Thanks: 19
Thanked 8 times in 8 posts
|
Austin,
thank you for your reply. You are right of course with the way to debug. But the "stop1" is also in the "if flat" statement. No? There´s no other difference in the both statements as if 90 ticks then change the donchian values for 2nd and 3rd entry. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
If there is no position, then there is no stop loss able to be changed. Setting the stop loss when flat is just for resetting the stop losses, it won't assign a stop loss to your positions.
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jun 2009
Posts: 735
Thanks: 19
Thanked 8 times in 8 posts
|
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
Not a problem, Tony. Let us know what you get figured out.
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jun 2009
Posts: 735
Thanks: 19
Thanked 8 times in 8 posts
|
Austin, referring to you information I have changed now to the following coding but this does´t work
if (BarsInProgress !=0) return; stop1=DonchianChannel(3).Upper[0]+5*TickSize; stop2=DonchianChannel(5).Upper[0]+5*TickSize; stop3=DonchianChannel(6).Upper[0]+5*TickSize; if(Position.MarketPosition == MarketPosition.Flat) { SetStopLoss("SG1", CalculationMode.Price, stop1, false); SetStopLoss("SG2", CalculationMode.Price, stop1, false); SetStopLoss("SG3", CalculationMode.Price, stop1, false); } if (Position.MarketPosition == MarketPosition.Short && Close[0] < Position.AvgPrice - 30 * TickSize && Close[0] > Position.AvgPrice - 90 * TickSize) { SetStopLoss("SG1", CalculationMode.Price, stop1, false); SetStopLoss("SG2", CalculationMode.Price, stop1, false); SetStopLoss("SG3", CalculationMode.Price, stop1, false); } if (Position.MarketPosition == MarketPosition.Short && Close[0] < Position.AvgPrice - 90 * TickSize) { SetStopLoss("SG1", CalculationMode.Price, stop2, false); SetStopLoss("SG2", CalculationMode.Price, stop2, false); SetStopLoss("SG3", CalculationMode.Price, stop3, false); } How can I change to have a variable in the stoploss untill a certain price and then changing to another variable from this certain price? Thanks |
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Hi Tony, you could for example add some boolean flags / user variables to your code to control the flow of the statements used better. A related sample script could be used here - http://www.ninjatrader.com/support/f...ad.php?t=15417
Think of the this functionality like switches that would have two values (true / false) to control which action is taken and in your case then which stop value / calculation is used at which time in the trade.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Jun 2009
Posts: 735
Thanks: 19
Thanked 8 times in 8 posts
|
Thank you for your reply. I tried to do so but it doesn´t work as stoploss always jumps back to first condtion that is true also with condtion 2 and 3. What am I doing wrong? Thank you
if(Position.MarketPosition == MarketPosition.Flat) {SetStopLoss("SG1", CalculationMode.Ticks, 70, false); Variable1 = 0;} if (Position. MarketPosition==MarketPosition.Short && Close[0]<Position.AvgPrice - 60*TickSize) {Variable1 = 1;} if (Variable1 == 1) {SetStopLoss("SG1", CalculationMode.Price, stop1,false);} if (Position. MarketPosition==MarketPosition.Short && Close[0]<Position.AvgPrice - 90*TickSize) {Variable1 = 2;} if (Variable1 == 2) {SetStopLoss("SG1", CalculationMode.Price, stop2,false);} if (Position. MarketPosition==MarketPosition.Short && Close[0]<Position.AvgPrice - 150*TickSize) {Variable1 = 3;} if (Variable1 == 3) {SetStopLoss("SG1", CalculationMode.Price, stop3,false);} |
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Tony, you would also need a check what your variable state is here in the first condition, so it would not always evaluate to true and force changes in your stoploss but only if your variable is reading a certain state where you would like this to to triggered again.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Jun 2009
Posts: 735
Thanks: 19
Thanked 8 times in 8 posts
|
????????????
|
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Tony, by your reply, I was unfortunately not sure which part was unclear to you, but I hope the attached strategy can help shed some more light on the topic.
Good luck,
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Jun 2009
Posts: 735
Thanks: 19
Thanked 8 times in 8 posts
|
Thank you!
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| stoploss | tonynt | Automated Trading | 5 | 08-08-2011 03:15 AM |
| double to dataseries | neb1998 | Automated Trading | 1 | 01-17-2011 11:38 PM |
| stoploss | mballagan | Strategy Development | 1 | 11-19-2009 10:15 AM |
| Double into int | Gepetto | Automated Trading | 5 | 11-18-2009 11:16 AM |
| Double moving average ,double time frame | Mauro60 | Indicator Development | 3 | 01-23-2007 02:11 AM |