NinjaTrader Support Forum  

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

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 06-16-2012, 11:26 AM   #1
Deogenes
Member
 
Join Date: Nov 2011
Location: Berlin, Germany
Posts: 46
Thanks: 8
Thanked 0 times in 0 posts
Default bool longTradeOk / What´s wrong here?

Hi,
the only thing i want to do is to avoid a new Trade after realizied 8 Ticks profit, in the same direction.
Maybe, it sounds a little bit funny:but i want only to take some profit at the turning points and then wait for another turnarond and so on.

Can somebody help me to realize this plan.

Thanks for supporting me.
Attached Files
File Type: cs AAA.cs (2.1 KB, 3 views)
Deogenes is offline  
Reply With Quote
Old 06-16-2012, 11:47 AM   #2
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello Deogenes,
You can compare the total long trades and total short trades taken by the strategy and then place the trades accordingly. A rough idea will be like
Code:
if (this.Performance.LongTrades.Count >= this.Performance.ShortTrades.Count)
{
	//take short trade only
}
else if (this.Performance.LongTrades.Count < this.Performance.ShortTrades.Count)
{
	//take long trade only
}
http://www.ninjatrader.com/support/h...longtrades.htm
http://www.ninjatrader.com/support/h...horttrades.htm

Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 06-16-2012, 12:58 PM   #3
Deogenes
Member
 
Join Date: Nov 2011
Location: Berlin, Germany
Posts: 46
Thanks: 8
Thanked 0 times in 0 posts
Default

Hello Joydeep, thank you for support

your idea sonds absolutely logical and it is the nearest i´ve ever read. But even i do a lot of things wrong, look at that: Can you help me out?

[ private bool LongTrades = true;
private bool ShortTrades = true;
private int target = 8 ;

// User defined variables (add any user defined variables below)
#endregion

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
//SetProfitTarget("buy", CalculationMode.Ticks, 8);
//SetProfitTarget("sell", CalculationMode.Ticks, 8);

CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (this.Performance.LongTrades.Count < this.Performance.ShortTrades.Count)
{
If( Close[0] > SuperTrend(10, 0.5, true).UpTrend[0]);
EnterLong(DefaultQuantity, "buy");
SetProfitTarget("buy", CalculationMode.Ticks, 8);
LongTrades = true;
ShortTrades = false;
}
else if(this.Performance.LongTrades.Count>=this.Perform ance.ShortTrades.Count)
{
If (Close[0] < SuperTrend(10, 0.5, true).DownTrend[0]);

EnterShort(DefaultQuantity, "sell");
SetProfitTarget("sell", CalculationMode.Ticks, 8);
LongTrades = false;
ShortTrades = true;

}

#region Properties
#endregion
}
}
]
Deogenes is offline  
Reply With Quote
Old 06-16-2012, 01:34 PM   #4
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,269
Thanks: 193
Thanked 332 times in 287 posts
Default

protected override void OnBarUpdate()
{
// Condition set 1
if (longTradeOk && Close[0] > SuperTrend(10, 0.5, true).UpTrend[0])
{
EnterLong(DefaultQuantity, "buy");
SetProfitTarget("buy", CalculationMode.Ticks, 8);
longTradeOk = false;
shortTradeOk = true;
}
else if(shortTradeOk && Close[0] < SuperTrend(10, 0.5, true).DownTrend[0])
{ EnterShort(DefaultQuantity, "sell");
SetProfitTarget("sell", CalculationMode.Ticks, 8);
longTradeOk = true;
shortTradeOk = false;
}
sledge is offline  
Reply With Quote
The following 2 users say thank you to sledge for this post:
Old 06-16-2012, 02:13 PM   #5
Deogenes
Member
 
Join Date: Nov 2011
Location: Berlin, Germany
Posts: 46
Thanks: 8
Thanked 0 times in 0 posts
Default

Great, sledge !!

I´ am so happy that this thing lately works like i wanted.
Thank you very much. I would offer you a glass of wine - if i could.
Thanks!
Deogenes is offline  
Reply With Quote
Reply

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
Unrealized profit display wrong in market analyzer, entry wrong in chart trader adamus Market Analyzer 3 06-17-2011 10:56 AM
In a quandry with bool?[] Sleeping Troll General Programming 2 09-15-2010 09:18 PM
String and Bool geotabs Strategy Development 3 10-26-2009 12:42 PM
Bool Flags?? rightcoast Strategy Development 3 07-13-2009 01:12 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:23 PM.