![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jul 2009
Location: San Feliciano - Perugia- Italy
Posts: 153
Thanks: 0
Thanked 2 times in 2 posts
|
hi,
The Code entry with a crossing of two SMA , with a stoploss of 4% becomes 2% if the volatility is low. With the 1° target , sell (1 / 2 ) position and the remaining managed TrailingStop (based on a channel MAX / MIN 0.25 * ATR). The Code with F5 is OK, but when i test in 10 years, you see only n.1 trade for stock. ![]() The Code: #region Variables private bool be1 = false; private bool be2 = false; #endregion #region Positions private void GoLong() { SetStopLoss("StopLoss 4% LongBuy",CalculationMode.Percent,0.04,false); EnterLong(500, "LongBuy"); } private void GoShort() { SetStopLoss("StopLoss 4% ShortSell",CalculationMode.Percent,0.04,false); EnterShort(500, "ShortSell"); } #endregion #region OrderRouting private void ManagerOrder () { if (Position.MarketPosition == MarketPosition.Long) { if (Be1 && Close[0] > Position.AvgPrice && ATR(14)[0] > EMA(ATR(14), 14)[0])// High Volatility SetStopLoss("StopLoss 4% LongBuy",CalculationMode.Percent,0.04,false); int pippo = 1; if( Be2 && Close[0] > Position.AvgPrice && ATR(14)[0] < EMA(ATR(14), 14)[0])// Low Volatility SetStopLoss("StopLoss 2% LongBuy",CalculationMode.Percent,0.02,false); int pluto = 1; if( pippo == 1 && High[0] >= Position.AvgPrice + ATR (14)[0] && ATR(14)[0] > EMA(ATR(14), 14)[0] )// High Volatility ExitLong(250, "Exit Long 1/2 Position", "LongBuy High Volatility"); SetStopLoss("StopLoss High Volatility",CalculationMode.Price,Position.AvgPric e ,false); SetTrailStop("StopTrailing High Volatility",CalculationMode.Price,MIN(Low, 10)[1] - (ATR(14)[0] * 0.35),false); if( pluto == 1 && High[0] >= Position.AvgPrice + ATR (14)[0] && ATR(14)[0] < EMA(ATR(14), 14)[0]) // Low Volatility ExitLong(250, "Exit Long 1/2 Position", "LongBuy Low Volatility"); SetStopLoss("StopLoss Low Volatility",CalculationMode.Price,Position.AvgPric e ,false); SetTrailStop("StopTrailing Low Volatility",CalculationMode.Price,MIN(Low, 10)[1] - (ATR(14)[0] * 0.25),false); } if (Position.MarketPosition == MarketPosition.Short)....................... protected override void OnBarUpdate() { ManagerOrder (); if (Position.MarketPosition != MarketPosition.Flat) return; if (CrossAbove(SMA(14),SMA(20),1) { GoLong(); } if(CrossBelow(SMA(14),SMA(20),1) { GoShort(); } why not enter the stop? What is wrong? Ciao. Italy
|
|
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can you tell me what I have wrong on this? | drmax | NinjaScript File Sharing Discussion | 5 | 05-13-2010 12:28 PM |
| What did I do wrong? | ckait | Miscellaneous Support | 7 | 03-21-2008 12:43 PM |
| PnL #s wrong (6.5.0.7) | SteveB | Historical NinjaTrader 6.5 Beta Threads | 4 | 03-05-2008 08:37 AM |
| What's wrong with this? | fifty2aces | Indicator Development | 3 | 01-16-2008 07:50 PM |
| Forex trading - wrong reporting, wrong Close action, connecting | jcervinka | Miscellaneous Support | 2 | 08-30-2007 09:42 AM |