NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 06-18-2010, 07:10 AM   #1
Italy
Senior Member
 
Join Date: Jul 2009
Location: San Feliciano - Perugia- Italy
Posts: 153
Thanks: 0
Thanked 2 times in 2 posts
Default What's wrong?

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.
Risk management, such as writing the code is not implemented.
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
Italy is offline  
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 12:18 PM.