![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Apr 2008
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
|
After wrestling with the reference sample, I was able to come up with this, and I don't understand why it isn't working. Whenever I backtest it, it simply scales out everything at the set profit target, instead of scaling out half and letting the second half scale with the trailing stop.
Code:
public class jhk : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// 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()
{
EntriesPerDirection = 1;
EntryHandling = EntryHandling.UniqueEntries;
SetStopLoss(CalculationMode.Ticks, 10, false);
SetProfitTarget("Long1a", CalculationMode.Ticks, 20);
SetProfitTarget("Short1a", CalculationMode.Ticks, 20);
SetTrailStop(CalculationMode.Ticks, 8);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(SMA(6), SMA(10), 1)
{
EnterLong(1,"Long1a");
EnterLong(1, "Long1b");
DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
}
// Condition set 2
if (CrossBelow(SMA(6), SMA(10), 1)
{
EnterShort(1, "Short1a");
EnterShort(1, "Short1b");
DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Red);
}
|
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
I suggest debugging your code as per here: http://www.ninjatrader-support.com/v...ead.php?t=3418
Also: TraceOrders coudl be of value too. Please check out the docs.
Dierk
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| NTMARKETPOSITION = Trouble / Bug | BIGRED | Automated Trading | 24 | 09-15-2008 11:03 PM |
| Trouble when connecting to IB | JohnG | Historical NinjaTrader 6.5 Beta Threads | 8 | 03-18-2008 10:04 AM |
| strategy trouble | volguy | Strategy Development | 1 | 02-21-2008 02:02 AM |
| Patystem trouble. | Bunker | Connecting | 2 | 10-02-2006 06:47 AM |
| trouble connecting to eSignal | eah | Installation and Licensing | 2 | 03-08-2006 08:51 AM |