Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit Strategy in Initialize()

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

    Exit Strategy in Initialize()

    Is there a way for me to make a Strategy terminate?

    I would like to be able to build into my code a bunch of checking logic that if not satisfied will terminate the script.

    Is this possible?

    #2
    imported post

    The suggested method is checking for the condition to stop your strategy from processing and return out of the OnBarUdpate() method.

    if (StopStrategyFromRunningCondition == true)
    return;


    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      I should add, this should be called from OnBarUpdate() not Initialize(), I am unsure of implications of it being called there.
      RayNinjaTrader Customer Service

      Comment


        #4
        imported post

        Thanks Ray,

        I have been trying to set alerts with no luck, nothing happens:

        Alert(
        "string", Priority.Low,"Position Reported as Flat","C:\\Documents and Settings\\Trader\\My Documents\\Finance\\alert wavs\\alarm2.wav",5,Color.Beige,Color.AliceBlue);

        The double \\ were necessary as the compiler keeps saying @unknown escape sequence@ which makes sense...

        Maybe the Log is better than the Alert window...


        Comment


          #5
          imported post

          Try this:

          Alert("string", Priority.Low,"Position Reported as Flat",@"C:\Documents and Settings\Trader\My Documents\Finance\alert wavs\alarm2.wav",5,Color.Beige,Color.AliceBlue);
          RayNinjaTrader Customer Service

          Comment


            #6
            imported post

            Also, I changed my post below, development corrected me and suggested not to set Running = false.

            What is suggested is leaving the strategy running but returning out of OnBarUpdate().

            So,

            if (TerminateStrategyCondition == true)
            return;


            Ray
            RayNinjaTrader Customer Service

            Comment


              #7
              imported post

              Still no good.

              Am using this code with private bool Init = true; declared in variables :



              protectedoverridevoid OnBarUpdate()

              {

              if (Init){

              Alert(
              "string", Priority.Low,"Position Reported as Flat",@"C:\Documents and Settings\Trader\My Documents\Finance\alert wavs\alarm2.wav",5,Color.Beige,Color.AliceBlue);



              Log(Instrument +
              " reported FLAT", LogLevel.Information);

              Init =
              false;

              }

              }

              Comment


                #8
                imported post

                Ah yes the empty return... and the Log write works, only the Alert doesn't

                Comment


                  #9
                  imported post

                  For clarification,

                  - The alert will not compile?
                  - The alert does not generate an alert?

                  If the latter, alerts only trigger on real-time data, not historical.

                  Ray
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    imported post

                    Compiles and runs fine:

                    Chart is real time with live data

                    the condition Init is true under all conditions and should trigger OnBarUpdate.


                    The alert window remains empty

                    Comment


                      #11
                      imported post

                      By the looks of your code sample, it should trigger only once on the first bar and not after that since you are setting Init= false.

                      If you create a new strategy an in the OnBarUpdate() include the following line, you will see alerts generated.

                      Alert(
                      "string", Priority.Low, "Position is reported as flat", @"C:\Program Files\NinjaTrader 6\Sounds\Alert1.wav", 5, Color.Black, Color.Yellow);

                      Ray
                      RayNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Segwin, 05-07-2018, 02:15 PM
                      14 responses
                      1,789 views
                      0 likes
                      Last Post aligator  
                      Started by Jimmyk, 01-26-2018, 05:19 AM
                      6 responses
                      837 views
                      0 likes
                      Last Post emuns
                      by emuns
                       
                      Started by jxs_xrj, 01-12-2020, 09:49 AM
                      6 responses
                      3,294 views
                      1 like
                      Last Post jgualdronc  
                      Started by Touch-Ups, Today, 10:36 AM
                      0 responses
                      13 views
                      0 likes
                      Last Post Touch-Ups  
                      Started by geddyisodin, 04-25-2024, 05:20 AM
                      11 responses
                      63 views
                      0 likes
                      Last Post halgo_boulder  
                      Working...
                      X