![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Nov 2011
Location: Berlin, Germany
Posts: 46
Thanks: 8
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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...horttrades.htm Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Nov 2011
Location: Berlin, Germany
Posts: 46
Thanks: 8
Thanked 0 times in 0 posts
|
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 } } ] |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,269
Thanks: 193
Thanked 332 times in 287 posts
|
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; } |
|
|
|
|
The following 2 users say thank you to sledge for this post: |
|
|
|
#5 |
|
Member
Join Date: Nov 2011
Location: Berlin, Germany
Posts: 46
Thanks: 8
Thanked 0 times in 0 posts
|
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! |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |