I am new user of NT, my name is Yusuf. This is my first time when I am posting my issue on this forum. I keep reading the posts on this forum and must say that it is one of the most active forum I have ever come across. I am not a programmer and therefore I need your expertise to help me resolving the issue that I have come across while trying for my first very simple strategy. actually what I am doing is, I am using the strategy wizard to feed the conditions and then learn how it is viewd by clicking the View Code. The following are the main objectives of running this strategy.
Variables Used:
SMA - Default Period 10
EMA - Default Period 30
SL - Stop Loss - Default 4 ticks from entry
Initial Set-Up:
Stop Loss set at 4 ticks from entry
Condition for entry:
If SMA(10) crosses below EMA(30), Enter Short Limit position at price equal to EMA(30)
(I am able to achieve this condition)
Condition for exit:
When atleast 2 bars have completed since entry, check for High of the price crossing above KAMA.
If so, exit at the close price of current bar. (Actually I wanted to exit at current price = Ask Value)
(I am not able to establish this exit condition as I can see all exit are made with the stop loss triggered by 4 ticks)
I would appreciate if someone could help me in and encourage me to have this as my first strategy as after having understood this one, I may be able to try some more and test them as well.
Also if someone could help me in explaining me as how could I write the codes for the following.
Condition: SMA(10) Crossed below EMA(30)
Enter Short only when price retraced back after some time, after atleast 5 bars and high pierced through EMA(30).
Your help and guidance is highly appreciated.
Following is the Code for the Strategy mentioned above in which exit condition is not working
Thanks a lot.
Regards,
Yusuf SHAIKH
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// TESTING
/// </summary>
[Description("TESTING")]
public class TEST1 : Strategy
{
#region Variables
// Wizard generated variables
private int sMA10 = 10; // Default setting for SMA10
private int eMA30 = 30; // Default setting for EMA30
private int sL = 4; // Default setting for SL
// 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(SMA(SMA10));
Add(EMA(EMA30));
Add(KAMA(2, 10, 30));
SetStopLoss("SHORT1", CalculationMode.Ticks, SL, true);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossBelow(SMA(SMA10), EMA(EMA30), 1))
{
EnterShortLimit(1, EMA(EMA30)[0], "SHORT1");
}
// Condition set 2
if (BarsSinceEntry() >= 2
&& CrossAbove(High, KAMA(2, 10, 30), 1))
{
ExitShortStop(Close[0], "SHORT1", "SHORT1");
}
}
Comment