0

This is my Amibroker code for a 2 bar swing chart, I need to add a condition that if price falls below the previous swing low in one bar, then to treat it as a two bar move. The problem I have is, holding the last swing low price variable to check against todays low. I have commented the problem lines in caps. What I have I thought would work but the condition is not showing up on the swing chart. Can someone tell me what I am doing wrong.Thanks.

_SECTION_BEGIN("2 day swing");
upBar = H>Ref(H,-1);
dnBar = L<Ref(L,-1);

HighBarPrice=LowBarPrice=Null;
inLong=inShort=upCount=dnCount=fupbar=fdnbar=0;

for( i=1; i<BarCount; i++ )
   {
    if(inLong==0 AND inShort==0)
      {
       if(upBar[i])
         {
          upCount=upCount+1;
          if(upCount==2)
            {
             fupbar[i] = 1;
             inLong=1;
             dnCount=0;
            }
         }

       if(dnBar[i])
         {
          dnCount=dnCount+1;
          if(dnCount==2)
            {
             fdnbar[i] = 1;
             inShort=1;
             upCount=0;
            }
         }
    if(inLong==1)
      {
       if(dnBar[i])
         {
          dnCount=dnCount+1;
          if(L[i]<LowBarPrice) {dnCount=2;} //THIS IS THE PROBLEM
          if(dnCount==2)
            {
             fdnbar[i]=1;
             inShort=1;
             if(upBar[i])
               {
                upCount=1;
               }
             else
               {
                upCount=0;
               }
          continue;
            }
         }
       if(upBar[i]) {HighBarPrice=H[i];}
       if(upBar[i] AND NOT dnBar[i]){ dnCount=0;}
      }
    if(inShort==1)
      {
       if(upBar[i])
         {
          upCount=upCount+1;
          if(H[i]>HighBarPrice) {upCount=2;}
          if(upCount==2)
            {
             fupbar[i]=1;
             inLong=1;
             if(dnBar[i])
               {
                dnCount=1;
               }
             else
               {
                dnCount=0;
               }
          continue;
            }
      }
       if(dnBar[i]) {LowBarPrice=L[i];}// DOWN BAR IN SHORT SWING SHOULD GIVE NEW LOW
       if(dnBar[i] AND NOT upBar[i]){ upCount=0;}
      }
   }


// Swing chart drawn here 
_SECTION_END();
4

1 に答える 1