Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

10 consecutive bars under stochastics logic

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

    10 consecutive bars under stochastics logic


    Hi i am using multitimeframe strategy and want to create a condition to have
    last 10 bars under readings of 20
    I use the logic below but it only captures just one instance and retuns true, I need 20 consecutive instances

    How can i modiify it?

    bool result = true;
    for (int i = 1; i <= 20; i++)
    {
    if (dStochPrim[i] <= 10)
    {
    result = false;
    break;
    }
    }
    Print("result"+result);​

    #2
    Hello tkaboris,

    Your loop has a break in it so it will stop when that condition is true, you can use a Print inside the loop to get a better idea of what values are being used and what the logic is doing.

    Comment


      #3
      Ok I was able to modify the loop that prints the allBelow bool. However I now need this condition

      if (close[1] >open[1] && Close[0] > Open[0] && allBelow evaluated to true within last 10 bars)
      How can I do this?

      bool allBelow = true;

      for (int i = 0; i < 20; i++)
      {

      if (dStochPrim[i] >= 10)
      {
      allBelow = false;
      // break;
      }
      }


      if (allBelow)
      {
      Print("All last 20 bars were less than dStochPrim[0] < 10");
      }
      else
      {
      Print("Not all last 20 bars were less than dStochPrim[0] < 10");
      }​

      Comment


        #4
        Hello tkaboris,

        If you want to use the result of that bool variable your condition needs to go after the loop. In the code you provided you are already doing that with the if(allBelow). If you want more conditions in addition to that you will need to add them to the condition.

        Comment


          #5
          I am a bit confused about how to modify this section so it takes into consideration previous 20 consecutive readings below 10, space of 10 or so bars and close,open
          bool allBelow = true;

          for (int i = 0; i < 20; i++)
          {

          if (dStochPrim[i] >= 10)
          {
          allBelow = false;
          // break;
          }
          }​

          This is my selling condition
          if(Close[1] > Open[1] && Close[0] < Open[0] && allBelow && dStochPrim[1] > 95)
          {
          Print(Time[0] + "Condition True");
          }​


          Click image for larger version

Name:	image.png
Views:	52
Size:	148.7 KB
ID:	1301989

          Comment


            #6
            Hello tkaboris,

            All I can suggest here is to add additional prints so you can see what values you are working with so you know how to form the condition as you want. Adding single prints inside your conditions is fine to know the condition is true but that won't tell you anything if the condition is not true or not working as expected. Adding a print outside the condition to output the values you used in the condition would be needed if you want to know why it is not becoming true when you think it should.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            56 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            132 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            73 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X