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

New to coding, please critique my not compiling code

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

    New to coding, please critique my not compiling code

    New to coding and new to making strategies. In this strategy I would like to enter long when the previous renko bar is green and the three bars before the previous green bar are red. When a bar closes as red I want to exit the trade. I've attached a picture illustrating this. Opposite but same logic for short trades.

    If you could, please tell me why what I did was wrong. This is all I've written in the script editor:

    Code:
            protected override void OnBarUpdate()
            {
    			
    			if (Close[2] < Close[3]) && (Close[3] < Close[4]) && (Close[1] > Close[2]) && (Position.MarketPositon.Flat = true);
    			{
    				EnterLong();
    			}
                            if (Position.MarketPostion.Long = true) && (Close[1] < Close[2]);
    			{
    				ExitLong();
    			}
    			if (Close[2] > Close[3]) && (Close[3] > Close[4]) && (Close[1] < Close[2]) && (Position.MarketPositon.Flat = true);
    			{
    				EnterShort();
    			}
                            if (Position.MarketPosition.Short = true) && (Close[1] > Close[2]);
    			{
    				ExitShort();
    			}
    			return;
    			
            }

    The black boxes indicate what the strategy should recognize as a signal to enter/exit.




    Also here are my errors:

    Last edited by DoctorDirty132; 11-18-2016, 05:02 AM.

    #2
    I've touched up issues I see right away. I haven't tested your logic.


    This could very likely won't run and you'll see a currentbar complaint in the log or output window.

    Search the forum for some currentbar logic.





    [QUOTE=DoctorDirty132;483474]

    Code:
            protected override void OnBarUpdate()
            {
    			
    			if ((Close[2] < Close[3]) && (Close[3] < Close[4]) && (Close[1] > Close[2]) && (Position.MarketPositon.Flat == true))
    			{
    				EnterLong();
    			}
                            if ((Position.MarketPostion.Long == true) && (Close[1] < Close[2]))
    			{
    				ExitLong();
    			}
    			if ((Close[2] > Close[3]) && (Close[3] > Close[4]) && (Close[1] < Close[2]) && (Position.MarketPositon.Flat == true))
    			{
    				EnterShort();
    			}
                            if ((Position.MarketPosition.Short == true) && (Close[1] > Close[2]))
    			{
    				ExitShort();
    			}
    			return;
    			
            }

    Comment


      #3
      Hello DoctorDirty132,

      Thank you for your note.

      In regards to Sledge’s suggestion (Thank you Sledge), you can find a reference example and explanation to the current bar check below. You should use this since your code references previous close values, thus you need to require enough bars on the chart.

      Reference Example: Make sure you have enough bars in the data series you are accessing


      I would highly suggest using the strategy wizard to build the strategy you’re looking for. This will prevent setting up statements like Position.MarketPosition.Flat = true rather than correctly using Position.MarketPosition == MarketPosition.Flat. You are using = which is for assignment rather than == which is checking if equal. You can then click the view code button on the wizard to see how the code is written.

      Also if you’d like to enter after the first close higher than the last bars close after several bars down, you should use bar index of zero. I have set up an example of how you could set this up in the wizard.

      I’ve included a links to our helpguide as well as a youtube video covering Strategy Wizard.

      Youtube: https://www.youtube.com/watch?v=FmBi...D7105&index=10

      Helpguide: http://ninjatrader.com/support/helpG...rd_screens.htm

      Please let us know if you need further assistance.
      Attached Files
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        Thanks!

        Thank you for your help. By building my strategy in strategy builder I was able to figure out the differences in my code. I'm sure I'll be back soon with more questions.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Skifree, Today, 03:41 AM
        1 response
        4 views
        0 likes
        Last Post Skifree
        by Skifree
         
        Started by usazencort, Today, 01:16 AM
        0 responses
        1 view
        0 likes
        Last Post usazencort  
        Started by kaywai, 09-01-2023, 08:44 PM
        5 responses
        603 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        6 responses
        23 views
        0 likes
        Last Post xiinteractive  
        Started by Pattontje, Yesterday, 02:10 PM
        2 responses
        23 views
        0 likes
        Last Post Pattontje  
        Working...
        X