NexusFi: Find Your Edge


Home Menu

 





Programming issue


Discussion in NinjaTrader

Updated
    1. trending_up 1,288 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Programming issue

  #1 (permalink)
 crazygarnett 
Stuttgart+Germany
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES
Posts: 2 since Jun 2012
Thanks Given: 0
Thanks Received: 0

Hi

I was wondering if someone can help me with Ninja code. I am new in the programming and trying to create my first strategy and have following issue. I want to set as Trailing Stop and exit condition, respectively "Chandelier Stop" but it does not react at all. What is wrong with this code? Would appreciate any help.

#region Variables
// Wizard generated variables
private double multi = 1.75; // ATR Multiplier
private int period = 1; // ATR Period
private double ch_Mulit = 3; // Chandelier Multiplier
private int ch_Period = 10; // Chandelier Period
private int stop_Loss = 25; // Initial Stop Loss
// 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()
{
Add(Bollinger(2, 20));
Add(Bollinger(2, 20));
Add(ATR(Period));
Add(Bollinger(2, 20));
Add(Bollinger(2, 20));
Add(ATR(Period));
SetStopLoss("", CalculationMode.Ticks, Stop_Loss, false);

CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (Bollinger(2, 20).Upper[0] - Bollinger(2, 20).Lower[0]
< Multi * ATR(Period)[0]
&& CrossAbove(Close, Bollinger(2, 20).Upper, 1))
{
EnterLong(DefaultQuantity, "");
}

// Condition set 2
if (Bollinger(2, 20).Upper[0] - Bollinger(2, 20).Lower[0]
< Multi * ATR(Period)[0]
&& CrossBelow(Close, Bollinger(2, 20).Lower, 1))
{
EnterShort(DefaultQuantity, "");
}

// Condition set 3
if (CrossBelow(Close, ChandelierStop(Ch_Period, Multi).ChandelierLo, 1))
{
ExitLong("", "");
}

// Condition set 4
if (CrossAbove(Close, ChandelierStop(Ch_Period, Multi).ChandelierHi, 1))
{
ExitShort("", "");
}
}

#region Properties
[Description("ATR Multiplier for Entry Signal")]
[GridCategory("Parameters")]
public double Multi
{
get { return multi; }
set { multi = Math.Max(1, value); }
}

[Description("ATR Period for Entry Signal")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}

[Description("Chandelier Mulitplier for Trailing Stop")]
[GridCategory("Parameters")]
public double Ch_Mulit
{
get { return ch_Mulit; }
set { ch_Mulit = Math.Max(1, value); }
}

[Description("Chandelier Period for Trailing Stop")]
[GridCategory("Parameters")]
public int Ch_Period
{
get { return ch_Period; }
set { ch_Period = Math.Max(1, value); }
}

[Description("Initial Stop Loss")]
[GridCategory("Parameters")]
public int Stop_Loss
{
get { return stop_Loss; }
set { stop_Loss = Math.Max(1, value); }
}
#endregion
}
}

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trend Direction Force Index (TDFI)
Platforms and Indicators
What broker to use for trading palladium futures
Commodities
Cheap historycal L1 data for stocks
Stocks and ETFs
How to apply profiles
Traders Hideout
About a successful futures trader who didnt know anythin …
Psychology and Money Management
 
  #2 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

First, in Initialize(), you only need these two:
 
Code
                            
Add(Bollinger(220));
Add(ATR(Period)); 
no need to add more "Add()" .

To check what's wrong with your exit condition, you may add some Print():
 
Code
                            
Print("Stop: "+ChandelierStop(Ch_PeriodMulti).ChandelierLo1));
Print(
"Stop: "+ChandelierStop(Ch_PeriodMulti).ChandelierHi1)); 
in the OnBarUpdate().
Then using Market Replay data feed, you'll quickly see what's wrong.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
 crazygarnett 
Stuttgart+Germany
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES
Posts: 2 since Jun 2012
Thanks Given: 0
Thanks Received: 0


Hi sam028

Thank you for your reply and your help.

Started this thread Reply With Quote




Last Updated on December 31, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts