Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

My First Strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    My First Strategy

    Hi Everyone...
    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");
    }
    }

    #2
    Welcome! Your approach is a good way to start to learn to program. Josh will repsond later tonight on your post.
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks...

      Thanks Ray, I will wait for Josh expertise and reply eagerly...
      Regards,
      Yusuf SHAIKH

      Comment


        #4
        Hi Yusuf,

        Your exit condition seems right. I would suggest you try temporarily removing your stop loss to see if your condition is ever hit. Also, I suggest you rename the Exit order's string name to something slightly different then the entry name. This will allow you to more easily understand what order is actually triggered by their names.

        For SMA(10) Crossed below EMA(30):
        Code:
        if (CrossBelow(SMA(10), EMA(30), 1))
             // Do something;
        You will need to further define what you mean by "retrace back". In order to program it you need to quantify what qualifies as a retrace back. Say if you wanted the price to be 5 consecutive lower bars you can do that simply by looping through checking Close[0] through Close[4] against each other.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh...

          Hi Josh,
          Thanks for your reply. Let me try out by removing Stop Loss and revert back to you as what happens.
          Regards,
          Yusuf SHAIKH

          Comment


            #6
            Thanks---

            Hi Josh,
            Thanks for your kind advice. The query worked fine once I removed the SetStopLoss() condition. I know how the loop works now, atleast the basic now. I will start putting my ideas to test certain strategies and see the outcome. I will revert back in case I get stucked in between.

            Regards,
            Yusuf SHAIKH

            Comment


              #7
              Great. Good luck with your strategy.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Got Stucked again...

                Hi Josh,

                I am just trying to refine my Strategy Entry Point by eliminating a set of entries that do not confirm to my trading objectives. So I separately tried a different set of conditions to see the results individually and then I though I will merge it with my basic strategy thus giving a more powerful result hopefully. I will give you the details in the following lines.

                Objective:
                Test for Zero Line Rejection of Woodies CCI

                Variables:
                Upper Bound of Woodies CCI - WE1
                Lower Bound of Woodies CCI - WE2

                Condition:
                If ALL of the following are TRUE
                1) Woodies CCI (1 bar ago) < WE1 (I have set this to 40)
                2) Woodies CCI (1 bar ago) > WE2 (I have set this to -5)
                3) Woodies CCI (2 bars ago) < Woodies CCI (1 bar ago)
                4) Woodies CCI (0 bar ago) < Woodies CCI (1 bar ago)

                Action:
                OpenShort Position
                Signal Name - SHORT1

                So basically I am trying to hunt a reversal of Woodies CCI from closer to Zero Line as can be seen from the attached chart.

                The Blue arrow heads indicates 2 instances that I wanted this Strategy to capture and that was actually the main aim of this strategy. I am afraid of not being sure why I was not able to achieve it. I am also attaching the Exported Strategy for your kind perusal. I am sure your expertise will help me achieving my goal.

                Thanks in advance to help me learning the process.
                Best regards,
                Yusuf SHAIKH
                Attached Files

                Comment


                  #9
                  Hi,

                  Unfortunately due to bandwidth reasons we cannot help on a per script basis. If you have specific programming issues we can help. Thanks for understanding.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Josh...

                    Hi Josh,
                    Attaching only the Condition Codes to check if I am right in what I am aiming at. Maybe you may help now by referring to my previous post to give an idea as what I wanted out of this Test. Thanks in advance.
                    Best regards,
                    Yusuf SHAIKH


                    // Condition set 1
                    if (WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2).ChopZone[1] > WE2
                    && WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2).ChopZone[1] < WE1
                    && WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2).ChopZone[2] < WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2).ChopZone[1]
                    && WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2).ChopZone[0] < WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2).ChopZone[1])
                    {
                    EnterShort(DefaultQuantity, "SHORT1");
                    }

                    Comment


                      #11
                      That should be correct. The problem you are facing should be in the Control Center logs. Please check the logs for an error when you run the indicator. Then check out this tip about how to fix it: http://www.ninjatrader-support.com/v...ead.php?t=3170
                      Josh P.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by ct, 05-07-2023, 12:31 PM
                      6 responses
                      202 views
                      0 likes
                      Last Post wisconsinpat  
                      Started by kaywai, Today, 06:26 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post kaywai
                      by kaywai
                       
                      Started by kevinenergy, 02-17-2023, 12:42 PM
                      118 responses
                      2,778 views
                      1 like
                      Last Post kevinenergy  
                      Started by briansaul, Today, 05:31 AM
                      0 responses
                      9 views
                      0 likes
                      Last Post briansaul  
                      Started by traderqz, Yesterday, 12:06 AM
                      11 responses
                      28 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Working...
                      X