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

Sma cross strategy

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

    Sma cross strategy

    HELLO,
    i have very less knowledge of coding so plese forgive my small silly questions....
    i have build a strategy for sma cross without any trading parameters, because i just want arrows to show on my chart when crossover is done of sma. but i am unable to see thos arrows on my chart. i will post the code and startegy here if some one can help me.
    thanks



    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class SMAcross : Strategy
    {
    private SMA SMA1;
    private SMA SMA2;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "SMAcross";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    PeriodFast = 20;
    PeriodSlow = 210;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    SMA1 = SMA(Close, Convert.ToInt32(PeriodFast));
    SMA2 = SMA(Close, Convert.ToInt32(PeriodSlow));
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (CrossAbove(SMA1, SMA2, 1))
    {
    Draw.ArrowUp(this, @"SMAcross Arrow up_1", false, 0, 0, Brushes.Lime);
    }

    // Set 2
    if (CrossBelow(SMA1, SMA2, 1))
    {
    Draw.ArrowDown(this, @"SMAcross Arrow down_1", false, 0, 0, Brushes.Red);
    }

    }
    Attached Files

    #2
    Hello hir04068,

    It appears the drawing objects are being drawn at a price of 0 at the bottom of the scale and the auto scale is false.

    May I confirm you have scrolled the price scale to 0 and looked for the drawing objects at the bottom of the scale?

    Is the strategy enabled?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      hello,
      yes I see 2 arrows at 0 levels, how to make it on price candle

      Comment


        #4
        Hello hir04068,

        The y is the price value. Set this to the price you would like.

        Below is a link to the help guide on Draw.ArrowUp().


        Draw.ArrowUp(NinjaScriptBase owner, string tag, bool isAutoScale, int barsAgo, double y, Brush brush)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello hir04068,

          The y is the price value. Set this to the price you would like.

          Below is a link to the help guide on Draw.ArrowUp().


          Draw.ArrowUp(NinjaScriptBase owner, string tag, bool isAutoScale, int barsAgo, double y, Brush brush)
          Hey, thanks a lot for the info....
          can you help me more with this.....
          it only show the last buy and sell signal..... how can I have more historical signal arrow's on the chart?

          Comment


            #6
            Hello hir04068,

            Use unique tag names.

            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              all looks good now,
              thanks a ton.....
              just 1 lat quetion i have... can we turn this strategy in a indicator?

              Comment


                #8
                I am getting this message when I try to open strategy builder now...
                Attached Files

                Comment


                  #9
                  hir04068,

                  Please follow the instructions below to see where the errors are coming from after compiling the indicator. This will allow you to debug the indicator/strategy or remove it from your PC. If you are wondering why you receive an error when compiling only one indicator, it is because NinjaTrader always compiles all indicators and strategies - not just one. This is done to give you the highest runtime performance possible.
                  • Open NinjaTrader
                  • From the Control Center select the New menu--> select NinjaScript Editor
                  • Double click on the Indicators folder--> then double click on any of the indicators
                  • Once the indicator code is in view right click in the window and select Compile to compile all NinjaScript objects
                  • At the bottom of the NinjaScript Editor window, a new section will appear where you can find the error locations
                  • You can exclude the file referenced in the editor by double clicking on the appropriate object type on the right of the NinjaScript Editor window. This will expand the object type folder. You can then select the file with a left click--> right click on the object--> then select Open to begin debugging the file, Exclude From Compilation, or Remove to delete the file.
                  If you are unsure as to what the error is indicating, please take a screenshot of the NinjaScript File column and Error column fully visible (not to be confused with the Code column)

                  To send a screenshot with Windows 7 or newer I would recommend using Window's, Snipping Tool. Click here for instructions

                  Alternatively to take a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Click here for detailed instruction

                  We have also collected more comprehensive steps for resolving NinjaScript programming errors in this tip in our Help Guide:
                  Josh G.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_JoshG View Post
                    hir04068,

                    Please follow the instructions below to see where the errors are coming from after compiling the indicator. This will allow you to debug the indicator/strategy or remove it from your PC. If you are wondering why you receive an error when compiling only one indicator, it is because NinjaTrader always compiles all indicators and strategies - not just one. This is done to give you the highest runtime performance possible.
                    • Open NinjaTrader
                    • From the Control Center select the New menu--> select NinjaScript Editor
                    • Double click on the Indicators folder--> then double click on any of the indicators
                    • Once the indicator code is in view right click in the window and select Compile to compile all NinjaScript objects
                    • At the bottom of the NinjaScript Editor window, a new section will appear where you can find the error locations
                    • You can exclude the file referenced in the editor by double clicking on the appropriate object type on the right of the NinjaScript Editor window. This will expand the object type folder. You can then select the file with a left click--> right click on the object--> then select Open to begin debugging the file, Exclude From Compilation, or Remove to delete the file.
                    If you are unsure as to what the error is indicating, please take a screenshot of the NinjaScript File column and Error column fully visible (not to be confused with the Code column)

                    To send a screenshot with Windows 7 or newer I would recommend using Window's, Snipping Tool. Click here for instructions

                    Alternatively to take a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Click here for detailed instruction

                    We have also collected more comprehensive steps for resolving NinjaScript programming errors in this tip in our Help Guide:
                    thanks a ton...
                    problem is solved
                    just 1 lat question I have... can we turn this strategy in an indicator?

                    Comment


                      #11
                      hello,
                      instead of just arrow when sma cross can I fill the zone between them? if yes can you help me with that? thanks

                      Comment


                        #12
                        Hello hir04068,

                        Create a new indicator.
                        Then copy the custom variables and inputs and logic in OnBarUpdate() from the strategy to the indicator.

                        The Draw.Region() draws a region between two plots.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChelseaB View Post
                          Hello hir04068,

                          Create a new indicator.
                          Then copy the custom variables and inputs and logic in OnBarUpdate() from the strategy to the indicator.

                          The Draw.Region() draws a region between two plots.
                          https://ninjatrader.com/support/help...raw_region.htm
                          hello,
                          i am geting this error while doing copy and paste... i think i am missing something...
                          Attached Files

                          Comment


                            #14
                            Hello hir04068,

                            The inputs you are showing do not appear to be within the scope of the class.. These appear to be within the scope of the Indicators namespace...

                            What is the object these variables are declared in?


                            May I confirm that you created a new empty script using the NinjaScript Editor?

                            Did you copy only the variables to the new script and paste those in the same scope as from the original script?

                            The NinjaScript Editor 401 course demonstrates copying code from one script to another.

                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              thanks a ton for all your support......
                              I post my sma cross indicator here so if anyone in future needs it can use it...
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by funk10101, Today, 12:02 AM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by GLFX005, Today, 03:23 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by nandhumca, Yesterday, 03:41 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by The_Sec, Yesterday, 03:37 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by vecnopus, Today, 06:15 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post vecnopus  
                              Working...
                              X