Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reversals

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

    Reversals

    I have an indicator which draws an arrow when certain (multi time frame) conditions are fullfilled. I use this code to draw the arrow.

    DrawArrowUp("My Arrow" + CurrentBar, false, 0, Low [0] - 1 * TickSize, symbolUpColor);

    That gives me also the past arrows. When I delete the "+ CurrentBar":

    DrawArrowUp("My Arrow", false, 0, Low [0] - 1 * TickSize, symbolUpColor);

    I do not get the past arrows but only the current one right when it occurs.

    How would I need to modify the code to end up with it drawing an arrow when the condition first appears and now make it stay BUT only draw a new arrow when it occurs in the OPPOSITE direction. In other words: My conditions are met. Give me an arrow. But only one. Stay where you are. Now give me an arrow only when my conditions indicate the opposite direction.

    I attach an image. The top part shows what I currently get. The bottom one (photo shopped) shows what I would like to get.

    Is there a way to arrive at that? Perhaps there's an already existing indicator which utilizes what I am trying to get at. If so could someone point me to it.

    sandman
    Attached Files

    #2
    Hello,

    Thank you for the question.

    I am unsure of your exact logic, but it sounds like possibly just a set of simple Bools may work?

    If your condition remains true, you could check a bool and switch it on the first occurrence so it can not draw again until the opposite is true and repeat the same process for the opposite direction.

    Here is a simple example of what I am referring:

    Code:
    private drawUpOnce= false; 
    private drawDownOnce= false; 
    
    if(SomeCondition)
    {
        drawDownOnce = false;
        if(drawUpOnce == false)
        {
             DrawArrowUp("My Arrow", false, 0, Low [0] - 1 * TickSize, symbolUpColor);
             drawUpOnce = true;
        }
    } else {
        drawUpOnce = false;
        if(drawDownOnce == false)
        {
             DrawArrowDown("My Arrow", false, 0, Low [0] - 1 * TickSize, symbolDownColor);
             drawDownOnce = true;
        }
    }
    Again I have no idea on your scripts logic so this would just be an idea that might work.

    I look forward to being of further assistance.

    Comment


      #3
      Or Make 2 arrows,with different names.
      My arrow up, and my arrow down.

      Comment


        #4
        Thank you Jesse. That provided the basic code of what I was looking for. Much appreciated.

        sandman

        Comment


          #5
          Jesse.

          Again thanks. That set of simple Bools works very well and gives me the correct visual indications for my purposes. Chart 1 attached shows with an arrow the first occurrence of my indicators and that is what I would like to now also have accompanied by a sound.

          However what I run into is that the alert sound file is played not only in that first minute when the conditions are met but also in the subsequent minutes as long as the condition remains the same. I have included Chart 2 where the first instance of the condition being met is indicated visually with an arrow, the continuation with a triangle.

          What do I have to do with the sound alert (see code) so it only plays in that first minute concurrent with the arrow (but not when the triangles pop up).

          (I hope I am clear in what I am trying to achieve).

          sandman
          Attached Files

          Comment


            #6
            Hello,

            It looks like this could just be a minor C# syntax item you hit here.

            If statements without braces { } can execute 1 command where if statements with braces can execute multiple.

            You have
            Code:
            if(arrowc_On) {
            if(drawUpOnce)
            
            DrawArrowUp(...)
            Alert()
            }
            In this situation, Alert is in the scope of "if(arrowc_On) {" rather than if(drawUpOnce)

            The way you have it now is being evaluated as:

            Code:
            if(arrowc_On) {
            if(drawUpOnce)
            {
            DrawArrowUp(...)
            }
            Alert()
            }

            You would just need to restructure this like the following to include the Alert with the Arrows if statement:

            Code:
            if(arrowc_On) {
            if(drawUpOnce)
            [B]{[/B]
            DrawArrowUp(...)
            Alert()
            [B]}[/B]
            }
            Could you try these changes and see if this is all that needs addressed?


            I look forward to being of further assistance.

            Comment


              #7
              Aha. I'll try this out and will let you know.

              sandman

              Comment


                #8
                Jesse. Yes, that worked out well. Enclosed image shows how I used it in my code. That leads me to another question:

                There is the odd occasion where a signal is generated, meaning an arrow is drawn but within the Data Series being used (let's say 1 Minute), the conditions change. But the arrow is drawn. When that happens I want the arrow to be removed and to achieve that I have that second part:

                if (Close[0] < Open[0])
                {
                RemoveDrawObject("My Arrow Up" + CurrentBar);
                }

                It works sometime but not always i.e. it's not perfect. Is there another code snippet that would remove the arrow if the condition reverses within the DataSeries being used.

                sandman
                Attached Files

                Comment


                  #9
                  i didnt read through the chat an all, so i dont even know whats goin on, but just lookin at ur last post..

                  the way u use it would only work if you try to remove the arrow while still being on the same candle as the arrow was printed. if not, currentbar would be a diffrent value and the tag wouldnt fit anymore. could that be the problem?

                  also, i think the code to remove the drawnobjects should work fine, another "code snippet" even if there would be something, i think wouldnt make things work better.
                  if it doesnt work as expected then something in your syntax is wrong, so you should look into those if statements that lead to the drawings and to the removal of those

                  Comment


                    #10
                    Thanks BigRo. Based on your comment I amended my code. Instead of a simple "if" I changed it to "else if" and that seems to give me what I want. BUT I don't know why because I am not really a programmer.

                    What's the difference between "if" "if" and "if" "else if"? See attached. Could you or someone else explain in layman's terms the difference.

                    sandman
                    Attached Files

                    Comment


                      #11
                      i dont really see how changing to else if would change any thing here bc Close[0]>Open[0] and Close[0]<Open[0] contradict each other anyway. but maybe there is a weird interaction with the multitimeframe syntax. and why bother thinking about it, if your problem is fixed. everthing is fine, so whatever

                      to answer your question:
                      if statements always stand alone and are processed alone. else and else if statement always have a realationship to the prior if statement. else ifs are basicly just a short version of
                      Code:
                      else
                      {
                          if (something)
                          {
                          do something
                          }
                      }
                      basicly something like this
                      Code:
                      if (bla)
                          // executed only if "bla" is true
                      
                      if (condition)
                          // executed only if "condition" is true
                      
                      else if (other condition)
                          // executed only if "condition" was false and "other condition" is true
                      
                      else
                          // executed only if both "condition" and "other condition" were false
                          // if there is no "else if" prior to this, "else" would only but always execute if the if "condition" is false
                      this is the general causal dependence

                      and now u can see why iam a bit confused that the "else" made a diffrence
                      because if Close[0]>Open[0] then Close[0]<Open[0] will automaticly be false. so linking those two statements together with an else if to check if the first condition is false really shouldnt make any diffrence. but maybe i am missing something.
                      Last edited by BigRo; 12-11-2015, 02:06 PM.

                      Comment


                        #12
                        Originally posted by sandman View Post
                        Thanks BigRo. Based on your comment I amended my code. Instead of a simple "if" I changed it to "else if" and that seems to give me what I want. BUT I don't know why because I am not really a programmer.

                        What's the difference between "if" "if" and "if" "else if"? See attached. Could you or someone else explain in layman's terms the difference.

                        sandman
                        "else" means exactly that: the same as it means in all versions of the English language. It means that: "only do this next action if the last action failed. If the last filter was valid and caused its "if" block to process, then skip the block that is immediately after the "else" key word. Rinse, repeat, for any "if" filter until you complete the processing of filtered blocks, including any "if" filter that is included in the "else" block."

                        Comment


                          #13
                          i just googled a bit and since i too didnt put much research into this topic yet (am also not a programmer)
                          and found this.

                          Code:
                                  if (Method1() && Method2())
                                      Console.WriteLine("Both methods returned true.");
                                  else
                                      Console.WriteLine("At least one of the methods returned false.");
                          can somone confirm this to be true?
                          i always thought that the full "(Method1() && Method2())" need to be false(so everypart of it) for the else to kick in, but this indicates that only one of those need to be false.

                          that would ofc then explains why your "else", sandman, changed so much. because basicly the "else if" gets processed whenever at least one of your if(condition1&&condition2&&condition3&&condition4) is false.

                          again, can someone confirm that?

                          Comment


                            #14
                            Originally posted by BigRo View Post
                            i just googled a bit and since i too didnt put much research into this topic yet (am also not a programmer)
                            and found this.

                            Code:
                                    if (Method1() && Method2())
                                        Console.WriteLine("Both methods returned true.");
                                    else
                                        Console.WriteLine("At least one of the methods returned false.");
                            can somone confirm this to be true?
                            i always thought that the full "(Method1() && Method2())" need to be false(so everypart of it) for the else to kick in, but this indicates that only one of those need to be false.

                            that would ofc then explains why your "else", sandman, changed so much. because basicly the "else if" gets processed whenever at least one of your if(condition1&&condition2&&condition3&&condition4) is false.

                            again, can someone confirm that?
                            That is correct. If part of a compound condition is false, then, necessarily, the whole must also be false. IOW, for a compound statement to be true, all parts must be true.

                            e.g., if (animal == dog && dog == pitbull) will not be true if the dog is anything other than a pitbull. Ergo, both parts must be true for the whole to be true, but only one part need be false for the whole to be false.

                            I have deliberately avoided using a truth table, as you have stated that you are not a programmer, and I am unsure of how mathematically astute you may be.

                            Comment


                              #15
                              Jesse (or perhaps someone else). I have it now fully working to my satisfaction and they are very good as potential entry signals. The RemoveDrawObject command for the opposite handles the odd occasion when a signal is generated within the same bar. It erases the first one on the spot and replaces it with the newest one. Here is the code I am using

                              if (Falling(LinReg(BarsArray[1],9))
                              && Falling(LinReg(BarsArray[2],4))
                              && Falling(LinReg(BarsArray[2],9))
                              ||
                              Falling(LinReg(BarsArray[1],9))
                              && Falling(LinReg(BarsArray[3],4))
                              && Falling(LinReg(BarsArray[3],9)))

                              {
                              { drawUpOnce = false;
                              if(drawDownOnce == false)

                              {
                              DrawArrowDown("RArrow Down", false, 0, High[0] + drawplace *TickSize, downsym);
                              RemoveDrawObject ("RArrow Up");
                              }
                              drawDownOnce = true;
                              }
                              }

                              Here is an additional question. Please see attached image where I marked the arrows 1,2 and 3. 1 and 3 are good entries, 2 is not. I have formulated a specific condition using yet another BarsArray that would identify "2" as non-genuine. BUT because 2 would then not be identified, only 1 would be generated by the code, 3 would not, thus killing a good entry signal at 3.

                              The code as you know, requires "2" to be calculated so that "3" can eventually be generated. If "2" were not generated then "3" would not be generated. What I am looking at is if there is a way to insert a line that leaves the code as is but add a line with the specific condition and return a non-colored transparent arrow. Something like this:

                              {
                              (A)if (Rising(LinReg(BarsArray[4],4))) DrawArrowDown("RArrow Down", false, 0, High[0] + drawplace *TickSize, Color.Transparent);
                              (B)DrawArrowDown("RArrow Down", false, 0, High[0] + drawplace *TickSize, downsym);
                              RemoveDrawObject ("RArrow Up");
                              }

                              Obviously that cannot work as it now has two contradictory drawing commands to carry out. And I don't even know if a condition can be placed into the command(then do) area of the code. I guess the question becomes "How and where do I tell it to do (B) only if (A) is not true?"

                              I hope it's clear enough what I am after. I look forward to your reply.
                              sandman
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              581 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              338 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              554 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              552 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X