• 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

Mro with boolean does not work

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

    Mro with boolean does not work

    Hey guys,

    below you will find my code. Please ignore my comments

    protected override void OnBarUpdate()
    {
    /* Only need to sync DataSeries objects once. We couldn't do this sync in the Initialize() method because we
    cannot access the BarsArray property there. */
    if (diff == null && BarsInProgress == 1)
    {
    /* Syncs another DataSeries object to the secondary bar object.
    We use an arbitrary indicator overloaded with an IDataSeries input to achieve the sync.
    The indicator can be any indicator. The DataSeries will be synced to whatever the
    BarsArray[] is provided.*/
    diff = new DataSeries(SMA(BarsArray[1], 50));
    }
    //checks we have enough bars to calculate
    if(CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired)
    return;
    double marker = 0;
    //double marker2 = 0;
    double stop = 0;
    if (BarsInProgress == 0)
    {





    if (CurrentBar < 2)
    return;
    double Open12 = Opens[1][2];
    double Close12 = Closes[1][2];
    double Open11 = Opens[1][1];
    double Close11 = Closes[1][1];
    double Open10 = Opens[1][0];
    double Close10 = Closes[1][0];
    double Open00 = Opens[0][0];
    double Close00 = Closes[0][0];
    double Low10 = Lows[1][0];
    double Low11 = Lows[1][1];




    if (Open12 > Close12 && Open11 < Close11 && Open10 < Close10 && (ToDay(Time[0]) != ToDay(Time[1])))
    //&& Close00 <= Open00 && Close00 >= Open00)
    {
    marker = marker + 1;
    }

    int dummybarsago = 0;
    int barcounting = 0;
    /*if (ToDay(Time[0]) != ToDay(Time[1]))
    {
    dummybarsago = dummybarsago +1;
    }*/
    bool dummymarker = false;
    if (marker == 1)
    {
    dummymarker = true;

    }

    //int barsAgo = MRO(delegate {return Close[0] > Open[0];}, 1, 9);
    int barsAgo = MRO(delegate {return dummymarker == true;}, 1, 9);

    /*double marker2 = dummybarsago;
    double dummystop = Lows[1][dummybarsago];
    double Open00 = Opens[0][0];
    if ( dummystop > Open00)
    {
    stop = stop + 1;
    }*/
    Marker2.Set(barsAgo);
    /*int dummybarsago = 1;
    if (ToDay(Time[0]) != ToDay(Time[1]))
    {
    dummybarsago = dummybarsago +1;
    }
    double marker2 = dummybarsago;
    double dummystop = Lows[1][dummybarsago];
    double Open00 = Opens[0][0];
    if ( dummystop > Open00)
    {
    stop = stop + 1;
    }
    Marker2.Set(marker2);
    */
    Marker.Set(marker);
    Stop.Set(stop);

    }

    My problem is simple if I add the line //int barsAgo = MRO(delegate {return Close[0] > Open[0];}, 1, 9); (right now its in the comment section) the variable int barsAgo counts the bars to the events perfectly. But if I'm using the boolean variable like:

    int barsAgo = MRO(delegate {return dummymarker == true;}, 1, 9);

    it just does not work. A value of -1 is plotted even if the variable dummymarke is true....

    Any suggestion from you guys?

    Being very grateful for your help,

    Best wishes,

    Andrew

    #2
    Hi Andrew,

    So that I may run this code and look to see the state of dummymarker in the last 9 bars, may I have an export of the script so that it is complete with variables declared?

    To export your script do the following:
    1. Click File -> Utilities -> Export NinjaScript
    2. Enter a unique name for the file in the value for 'File name:'
    3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
    4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


    Below is a link to the help guide on Exporting NinjaScripts.
    http://www.ninjatrader.com/support/h...nt7/export.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hey guys,

      my problem is a little bit more sophisticated so I will start from scratch again. What I need is the following:

      When my condition of entry is fullfilled store the price of the low of one day ago.

      So far so good; an if statement and Low[1] would seal the deal.

      The problem now with using Low[1] is that I don't want the variable to be updated anymore once it is set, no matter how many bars are to come in this trade. In other words: At the following day the stored value should not change to the Low of yesterday but still keep the value of day before yesterday. Put differently, the variable should store the Low value of a day before the specific date of entry.

      So I tried to script a workaround by counting back the bars until my entry condition holds true, going back the these bars +1 to access the Low[x] value of the day before entry.

      Isn't there just and easier and more efficient way to do that than my workaround?

      Really being grateful for your suggestions!

      Andrew

      Comment


        #4
        Hello andrew-aut1,

        Thank you for your response.

        So the variable only needs to update once when you are flat and before the entry is placed? Once this value is updated it should not update again until you are flat? Is this correct?
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Exactly. Is this doable? preferable with an indicator rather than in a strategy?

          Best wishes,

          Andrew

          Comment


            #6
            Andrew, generally the variable will only update if your condition triggers to do so - so if you want to work in an indicator you would need to mimic probably the trade exit logic to be able to say, as long as this trade progresses > I don't want the condition to retrigger and update my tracking variable. What exit conditions for the trade do you use?
            BertrandNinjaTrader Customer Service

            Comment


              #7
              I use a profit target.

              Best wishes.

              Andrew

              Comment


                #8
                Hi andrew-aut1,

                Just to clarify, you have a variable that is a double called marker. When a profit target fills, at that moment you would like to set the variable marker to the the value of yesterday's low. Is this correct?

                In this case, declare the double in the #region Variables so that it is not reset on each bar.

                private double marker = 0;

                Then in OnExecution() have a condition that sets the variable:

                Code:
                protected override void OnExecution(IExecution execution)
                {
                if (execution.Name == "Profit target")
                {
                marker = Low[1];
                }
                }
                This will only set the variable when the profit target fills.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hey

                  No. I want to enter when my double var condition is fulfilled (that works) and want to Exit the trade when Price falls below the Low of the day before I did enter. (Has nothing to do with the Profit target!) Since a trade can last over some days und the variable updates every day the Statement Low[1] does not work since then after the first update it would not use the Low before the day of my entry anymore, but just the last occured.

                  Being very grateful

                  Andrew

                  Comment


                    #10
                    Hello andrew-aut1,

                    You will want a condition to check if you are flat and update with that Low value until you are in a position.

                    Example -
                    if(Position.MarketPosition == MarketPosition.Flat && BarsInProgress == 1)
                    {
                    marker = Low[1];
                    }

                    This will only get called when a new day has begun and you are not in a position. If you are in a position from over night this will not get called.
                    Cal H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by EF Hutton, Today, 01:19 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post EF Hutton  
                    Started by Mykro, Today, 01:10 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post Mykro
                    by Mykro
                     
                    Started by Velhinho, Today, 12:30 PM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by EF Hutton, Today, 12:36 PM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Melissa  
                    Started by TraderIqbal, Today, 11:17 AM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_PatrickG  
                    Working...
                    X