Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Combinatorial Data-Sets

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

    Combinatorial Data-Sets

    Hello,

    I am working on a strategy the combines several different indicators. The values of these indicators had been separately optimized for specific market conditions, generating distinct data-sets.
    I need a combinatorial programming solution in order to call each data-set when triggered.
    Currently, my solution looks as follows:


    // --------------

    protected override void OnBarUpdate()
    {
    if (CurrentBar < BarsRequired) return;

    if (ToTime(Time[0]) >= ToTime(t1, 00, 0) && ToTime(Time[0]) <= ToTime(t2, 00, 0))
    {p1 = true; p2 = true; p3 = true; // bool flags


    if (p1)
    {ds1 = 1; // data-set 1
    if (ds1 == 1)
    {x = 6; y = 4; z = 2; a = -2; b = 6; c = -4;
    {
    if (Indicator 1 <= x
    && Indicator 2 <= y
    && Indicator 3 <= z
    && Indicator 4 <= a
    && Indicator 5 <= b)
    {w1 = 1; // int flag
    }}}}

    if (p2)
    {ds2 = 1; // data-set 2
    if (ds2 == 1)
    {x = 1; y = 5; z = 9; a = -1; b = 0; c = -12;
    {
    if (Indicator 1 <= x
    && Indicator 2 <= y
    && Indicator 3 <= z
    && Indicator 4 <= a
    && Indicator 5 <= b)
    {w2 = 1; // int flag
    }}}}

    if (p3)
    {ds3 = 1; // data-set 3
    if (ds3 == 1)
    {x = 4; y = 0; z = 11; a = 8; b = -2; c = 3;
    {
    if (Indicator 1 <= x
    && Indicator 2 <= y
    && Indicator 3 <= z
    && Indicator 4 <= a
    && Indicator 5 <= b)
    {w3 = 1; // int flag
    }}}}
    }

    if (w1 + w2 + w3 >= 1)
    {signalBar1 = CurrentBar; cond1 = true;
    w1 = 0; w2 = 0; w3 = 0;
    }

    if (cond1 && CurrentBar == signalBar1 // bool flags
    && Position.MarketPosition == MarketPosition.Flat)

    {EnterLong("Long 1a");
    SetStopLoss("Long 1a", CalculationMode.Ticks, sL1, false);
    if (BarsSinceEntry() == bseL1) cond1 = false;
    }

    etc ....

    // --------------------

    As this scheme may be further extended with additional data-sets,
    I am looking for a different solution, where a single list of indicators is able to call many data-sets separately.

    Thanks much,

    bkool

    #2
    What are you trying to simplify bkool? The pattern your 'indicator chain' forms?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,
      Not merely simplifying. This is pattern of patterns, and it may get too complicated when I use additional data-sets or time frames. I have tried to call the data-sets as is from a private void, but that didn't work.
      Would it be helpful to have the data-sets as DataSeries, or in a switch/case format?

      Comment


        #4
        So the method would return the flag value then for pattern found or not? I'm not sure why it wouldn't work, but might need to see / test your snippet for that.

        For timeframes, it can get more involved as you would also have to ensure calling in the correct BarsInProgress context.

        DataSeries would help you if you need to have access to prior values, which can be handy if you plan to add conditions to the patterns, as they would likely not happen all on the exact same bar / timestamp you likely need to weaken the rules a bit (give and take one index / bar) to allow for signals to be seen.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          The Solution

          The solution came from using the int array as follows:

          // --------------
          // Variables
          int[] w = new int[3]; // array of 3

          protected override void OnBarUpdate()
          {
          if (CurrentBar < BarsRequired) return;

          if (ToTime(Time[0]) >= ToTime(t1, 00, 0) && ToTime(Time[0]) <= ToTime(t2, 00, 0))
          {for (x = 0; ( x < 3); x++)
          {p = x;
          if (p == x) {ds = x;
          {
          // data-sets
          if (ds == 0){x = 6; y = 4; z = 2; a = -2; b = 6; c = -4;}
          if (ds == 1){x = 1; y = 5; z = 9; a = -1; b = 0; c = -12;}
          if (ds == 2){x = 4; y = 0; z = 11; a = 8; b = -2; c = 3;}

          // conditions
          if (Indicator 1 <= x
          && Indicator 2 <= y
          && Indicator 3 <= z
          && Indicator 4 <= a
          && Indicator 5 <= b)
          {w[x] = 1;
          }}}}

          if (w[0] + w[1] + w[2] >= 1)
          {signalBar1 = CurrentBar; cond1 = true;
          w[0] = 0; w[1] = 0; w[2] = 0;
          }

          if (cond1 && CurrentBar == signalBar1 // bool flags
          && Position.MarketPosition == MarketPosition.Flat)

          {EnterLong("Long 1a");
          SetStopLoss("Long 1a", CalculationMode.Ticks, sL1, false);
          if (BarsSinceEntry() == bseL1) cond1 = false;
          }

          etc ....

          // --------------------

          I hope you find it useful...

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by AlessioCianini12, Today, 01:38 AM
          0 responses
          21 views
          0 likes
          Last Post AlessioCianini12  
          Started by nandhumca, Yesterday, 11:54 PM
          0 responses
          24 views
          0 likes
          Last Post nandhumca  
          Started by nandhumca, Yesterday, 11:51 PM
          0 responses
          23 views
          0 likes
          Last Post nandhumca  
          Started by ezrollin, Yesterday, 11:48 PM
          2 responses
          23 views
          0 likes
          Last Post ezrollin  
          Started by jjanguda, Yesterday, 10:15 PM
          1 response
          23 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Working...
          X