• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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().
        https://ninjatrader.com/support/help...aw_arrowup.htm

        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().
          https://ninjatrader.com/support/help...aw_arrowup.htm

          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.

            https://ninjatrader.com/support/foru...630#post838630
            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:
                  JoshNinjaTrader 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.
                        https://ninjatrader.com/support/help...raw_region.htm
                        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.
                            https://youtu.be/BA0W4ECyVdc
                            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 razeus, Today, 12:00 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by kitwit, Today, 09:47 AM
                              5 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Started by guidoisot, Today, 11:17 AM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_PatrickG  
                              Started by razeus, Today, 10:11 AM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Started by tonynt, Today, 10:18 AM
                              5 responses
                              16 views
                              0 likes
                              Last Post tonynt
                              by tonynt
                               
                              Working...
                              X