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

Code form Strategy Builder is wrong?

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

    Code form Strategy Builder is wrong?

    Hello

    Why code made by Strategy Builder is does`n works?
    Code:
        public class smacross1 : 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                                        = "smacross1";
                    Calculate                                    = Calculate.OnPriceChange;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = false;
                    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;
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Day, 1);
                }
                else if (State == State.DataLoaded)
                {                
                    SMA1                = SMA(Closes[1], 2);
                    SMA2                = SMA(Opens[1], 2);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0) 
                    return;
    
                if (CurrentBars[0] < 1)
                return;
    
                 // Set 1
                if (CrossAbove(SMA1, SMA2, 0))
                {
                    Draw.Diamond(this, @"smacross1 Diamond_1", false, 0, GetCurrentAsk(0), Brushes.Red);
                }
    
                 // Set 2
                if (CrossBelow(SMA1, SMA2, 0))
                {
                    Draw.Diamond(this, @"smacross1 Diamond_1", false, 0, GetCurrentAsk(0), Brushes.Yellow);
                }
    
            }
        }
    I don`t see any Diamonds on Chart when SMAs are cross. Why???

    #2
    Hello sergey_z,
    Thanks for your post.

    I tested on my end and I never saw a situation where these conditions became true. I actually got an error on the logs tab until I modified the code myself.

    This is also raw code and could have potentially been modified. Can you please attach the .cs file here so we can see what you have done in the Builder.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      There is a file from Builder
      Attached Files

      Comment


        #4
        sergey_z,

        I do see the diamonds drawn on my chart when I run this strategy from my chart. You can check this on your end by running the strategy on your chart>>right-click inside chart>>Drawing Tools>>Drawing Objects...

        You can check the anchor of each diamond to see where on the chart it is drawn.

        Is it your intent to draw this diamond on each occurrence or just the most recent?
        Josh G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Started by guillembm, Yesterday, 11:25 AM
        2 responses
        9 views
        0 likes
        Last Post guillembm  
        Started by junkone, 04-21-2024, 07:17 AM
        9 responses
        70 views
        0 likes
        Last Post jeronymite  
        Started by mgco4you, Yesterday, 09:46 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X