[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] last bar in day, close price



PureBytes Links

Trading Reference Links




Ed,
 
You are using looping, please add SetBarsRequired 
call at the beginning of your code <A 
href="">http://www.amibroker.com/f?setbarsrequired
Best regards,Tomasz Janeczkoamibroker.com
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  ed 
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">amibroker@xxxxxxxxxxxxxxx 
  Sent: Thursday, May 20, 2004 10:19 
  AM
  Subject: [amibroker] question about 
  symbols in chart
  
  hello,
   
  what I sometime notice is that certain symbols 
  whcih I try to put at certain places in the chart seem to change if I blow up 
  the chart and scroll through it. 
   
  My question is: is this an indication of an error 
  in the code or do I not understand how exactly Amibroker operates when 
  plotting the chart. As an example I give the code below which is part my 
  interpretation of Welles Wilders "Reaction Trend System". I give here only the 
  calculation of the "phase". This phase is added to the chart using the numbers 
  1, 2 and 3. 
   
  Now if you make a chart of INTRADAY data (e.g. 
  the hourly data) and not plot all the data but just like 30 days and use the 
  mouse-scroll to move the chart from left to right or the other way around you 
  will notice that sometimes the numbers change. Why is that? Is it due to an 
  error in coding or is it the way Amibroker calculates the chart?
   
  So maybe in general my question is: if I see 
  indicators changing in the chart when scrolling through it is this 
  immediatelly a sign that there is an error in the code?
   
  thnks, Ed
   
   
  part of the code. Note: try it using Intraday 
  data (hourly)
   
   
   
  <FONT 
  color=#0000ff>TimeFrameSet( <FONT 
  color=#000000>inDaily<FONT 
  face="Courier New"> ); <FONT 
  color=#008000>// 
  --------------------------------------<FONT 
  face="Courier New"> <FONT 
  color=#008000>//calculate the average + the four price action 
  points.<FONT 
  color=#000000> // 
  average<FONT 
  color=#000000> xx = (H<FONT 
  color=#000000> + L<FONT 
  color=#000000> + C<FONT 
  color=#000000>) / 3<FONT 
  face="Courier New">; <FONT 
  color=#008000>// four price action points<FONT 
  face="Courier New"> <FONT 
  color=#008000>// 1) Buy point<FONT 
  face="Courier New"> B1 = <FONT 
  color=#ff00ff>2 * <FONT 
  color=#0000ff>Ref(xx,-<FONT 
  color=#ff00ff>1) - <FONT 
  color=#0000ff>Ref(<FONT 
  color=#000000>H,-<FONT 
  color=#ff00ff>1<FONT 
  size=2>); // 2) Sell 
  point<FONT 
  color=#000000> S1 = 2<FONT 
  color=#000000> * Ref<FONT 
  color=#000000>(xx,-1) - 
  Ref(<FONT 
  color=#000000>L,-<FONT 
  color=#ff00ff>1<FONT 
  size=2>); // 3) High break 
  out point<FONT 
  color=#000000> HBOP = 2<FONT 
  color=#000000> * Ref<FONT 
  color=#000000>(xx,-1) - 
  2 * <FONT 
  color=#0000ff>Ref(<FONT 
  color=#000000>L,-<FONT 
  color=#ff00ff>1) + <FONT 
  color=#0000ff>Ref(<FONT 
  color=#000000>H,-<FONT 
  color=#ff00ff>1<FONT 
  size=2>); // 4) Low break 
  out point <FONT 
  face="Courier New" size=2>LBOP = <FONT 
  size=2>2 * <FONT 
  color=#0000ff>Ref(xx,-<FONT 
  color=#ff00ff>1) - <FONT 
  color=#ff00ff>2 * <FONT 
  color=#0000ff>Ref(<FONT 
  color=#000000>H,-<FONT 
  color=#ff00ff>1) + <FONT 
  color=#0000ff>Ref(<FONT 
  color=#000000>L,-<FONT 
  color=#ff00ff>1<FONT 
  size=2>); // short 
  trail stop: highest high made in previous 2 days (used in trend mode 
  only)<FONT 
  color=#000000> trailstop_short = <FONT 
  color=#0000ff>Ref(<FONT 
  color=#0000ff>HHV(<FONT 
  color=#000000>H,<FONT 
  color=#ff00ff>2),-<FONT 
  color=#ff00ff>1<FONT 
  size=2>); // long trail 
  stop: lowest low made in previous 2 days (used in trend mode 
  only)<FONT 
  color=#000000> trailstop_long = Ref<FONT 
  color=#000000>(LLV<FONT 
  color=#000000>(L<FONT 
  color=#000000>,2<FONT 
  color=#000000>),-1<FONT 
  face="Courier New">); <FONT 
  color=#008000>// 
  --------------------------------------<FONT 
  face="Courier New"> phase_arr = 
  C<FONT 
  face="Courier New">; phase_arr = 
  0<FONT 
  face="Courier New">; phase_arr_l1 = 
  phase_arr; // additional layer of phase 
  changes<FONT 
  color=#000000> stop_short = phase_arr; stop_long = stop_short; 
  short_index_position = phase_arr; long_index_position = 
  short_index_position; b_day = phase_arr; s_day = phase_arr; 
  // first determine "B" and "S" 
  days<FONT 
  color=#000000> idx = <FONT 
  color=#ff00ff>0<FONT 
  size=2>; <FONT 
  color=#800000>for (i = <FONT 
  color=#ff00ff>0; i < <FONT 
  color=#000000>BarCount<FONT 
  face="Courier New">; i++) { 
     // short trend 
  mode<FONT 
  color=#000000>    <FONT 
  color=#800000>if (<FONT 
  color=#000000>L[ i ] < LBOP[ i ] 
  AND<FONT 
  face="Courier New"> i >= idx) { 
            <FONT 
  color=#008000>// indicate the short trend mode 
  outbreak<FONT 
  color=#000000>       short_index_position[ i 
  ] = 1<FONT 
  face="Courier New">;     
        // 
  variables tracking lowest day in short trend mode<FONT 
  face="Courier New"> 
        idx_b = i; 
        loi = <FONT 
  color=#000000>L<FONT 
  size=2>[ i ];        
        // exit at 
  trailing stop<FONT 
  color=#000000>       <FONT 
  color=#800000>for (j = i + <FONT 
  color=#ff00ff>1; j < <FONT 
  color=#000000>BarCount<FONT 
  face="Courier New">; j++) { 
         
           <FONT 
  color=#800000>if (<FONT 
  color=#000000>L<FONT 
  size=2>[ j ] < loi) { 
            
              loi 
  = L<FONT 
  face="Courier New">[ j ]; 
               
              <FONT 
  color=#008000>// track index of lowest point in trend mode 
  <FONT face="Courier New" 
  size=2>            idx_b 
  = j;           
           } 
         
           <FONT 
  face="Courier New">if<FONT 
  color=#000000> (H<FONT 
  face="Courier New">[ j ] > 
  trailstop_short[ j ]) { 
            
              stop_short[ 
  j ] = 1<FONT 
  face="Courier New">; 
               
              <FONT 
  color=#008000>// idx is used to make sure we finish a position before starting 
  a new one<FONT 
  color=#000000> 
              idx 
  = j; 
               
              <FONT 
  color=#008000>// used to exit the j-for loop<FONT 
  face="Courier New"> 
              j 
  = BarCount - 
  1<FONT 
  face="Courier New">; 
            
           } 
         
        } 
         
        // save 
  index position of lowest point in short trend mode<FONT 
  face="Courier New"> 
        b_day[ idx_b ] = <FONT 
  color=#ff00ff>1<FONT 
  size=2>;     
     } else<FONT 
  color=#000000> if 
  (H[ i ] > 
  HBOP[ i ] AND<FONT 
  face="Courier New"> i >= idx) { 
            <FONT 
  color=#008000>// indicate the long trend mode 
  outbreak<FONT 
  color=#000000>       long_index_position[ i 
  ] = 1<FONT 
  face="Courier New">;     
        // 
  variables tracking highest day in long trend mode<FONT 
  face="Courier New"> 
        idx_s = i; 
        hii = <FONT 
  color=#000000>H<FONT 
  size=2>[ i ];     
        // exit at 
  trailing stop<FONT 
  color=#000000>       <FONT 
  color=#800000>for (j = i + <FONT 
  color=#ff00ff>1; j < <FONT 
  color=#000000>BarCount<FONT 
  face="Courier New">; j++) { 
         
           <FONT 
  color=#800000>if (<FONT 
  color=#000000>H<FONT 
  size=2>[ j ] > hii) { 
            
              hii 
  = H<FONT 
  face="Courier New">[ j ]; 
               
              <FONT 
  color=#008000>// track index of highest point in trend mode 
  <FONT face="Courier New" 
  size=2>            idx_s 
  = j;           
           } 
            
           <FONT 
  face="Courier New">if<FONT 
  color=#000000> (L<FONT 
  face="Courier New">[ j ] < trailstop_long[ 
  j ]) {           
              stop_long[ 
  j ] = 1<FONT 
  face="Courier New">; 
               
              <FONT 
  color=#008000>// idx is used to make sure we finish a position before starting 
  a new one<FONT 
  color=#000000> 
              idx 
  = j; 
               
              <FONT 
  color=#008000>// used to exit the j-for loop<FONT 
  face="Courier New"> 
              j 
  = BarCount - 
  1<FONT 
  face="Courier New">; 
            
           } 
         
        } 
         
        // save 
  index position of highest point in long trend mode<FONT 
  face="Courier New"> 
        s_day[ idx_s ] = <FONT 
  color=#ff00ff>1<FONT 
  size=2>;        
     }     } <FONT 
  color=#008000>// fill in the rest of the phase array. Sequence: 1 - 2 - 3 - 1 
  - 2 - etc<FONT 
  color=#000000> for<FONT 
  color=#000000> (i = 1; i 
  < BarCount<FONT 
  face="Courier New">; i++) { 
     if<FONT 
  color=#000000> (b_day[ i ] == <FONT 
  color=#ff00ff>1<FONT 
  size=2>) {     
        phase_arr[ i ] = <FONT 
  color=#ff00ff>1<FONT 
  size=2>;        
        // if b_day 
  equal to the day of outbreak store the original 
  phase<FONT 
  color=#000000>       <FONT 
  color=#800000>if (b_day[ i ] == <FONT 
  color=#ff00ff>1 <FONT 
  color=#000000>AND short_index_position[ i ] 
  == 1<FONT 
  face="Courier New">) { 
         
           <FONT 
  color=#800000>if (phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>1<FONT 
  size=2>) { 
            
              phase_arr_l1[ 
  i ] = 2<FONT 
  face="Courier New">; 
               
           } <FONT 
  color=#800000>else<FONT 
  size=2> 
            
           <FONT 
  color=#800000>if (phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>2<FONT 
  size=2>) { 
            
              phase_arr_l1[ 
  i ] = 3<FONT 
  face="Courier New">; 
            
           } 
            
           <FONT 
  color=#800000>if (phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>3<FONT 
  size=2>) { 
            
              phase_arr_l1[ 
  i ] = 1<FONT 
  face="Courier New">; 
            
           } 
            
           <FONT 
  color=#800000>if (phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>0<FONT 
  size=2>) { 
            
              phase_arr_l1[ 
  i ] = 1<FONT 
  face="Courier New">; 
            
           }          
         
        } 
            } <FONT 
  color=#800000>else <FONT 
  color=#800000>if (s_day[ i ] == <FONT 
  color=#ff00ff>1<FONT 
  size=2>) {     
        phase_arr[ i ]  = 
  3<FONT 
  face="Courier New">; 
         
        // if s_day 
  equal to the day of outbreak store the original 
  phase<FONT 
  color=#000000>       <FONT 
  color=#800000>if (s_day[ i ] == <FONT 
  color=#ff00ff>1 <FONT 
  color=#000000>AND long_index_position[ i ] 
  == 1<FONT 
  face="Courier New">) { 
         
           <FONT 
  color=#800000>if (phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>1<FONT 
  size=2>) { 
            
              phase_arr_l1[ 
  i ] = 2<FONT 
  face="Courier New">; 
               
           } <FONT 
  color=#800000>else<FONT 
  size=2> 
            
           <FONT 
  color=#800000>if (phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>2<FONT 
  size=2>) { 
            
              phase_arr_l1[ 
  i ] = 3<FONT 
  face="Courier New">; 
            
           } 
            
           <FONT 
  color=#800000>if (phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>3<FONT 
  size=2>) { 
            
              phase_arr_l1[ 
  i ] = 1<FONT 
  face="Courier New">; 
            
           } 
            
           <FONT 
  color=#800000>if (phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>0<FONT 
  size=2>) { 
            
              phase_arr_l1[ 
  i ] = 1<FONT 
  face="Courier New">; 
            
           }          
         
        }       
         
            } <FONT 
  color=#800000>else <FONT 
  color=#800000>if (b_day[ i ] == <FONT 
  color=#ff00ff>0 <FONT 
  color=#000000>AND s_day[ i ] == <FONT 
  color=#ff00ff>0 <FONT 
  color=#000000>AND phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>3<FONT 
  size=2>) {     
        phase_arr[ i ] = <FONT 
  color=#ff00ff>1<FONT 
  size=2>;        } 
  else <FONT 
  color=#800000>if (b_day[ i ] == <FONT 
  color=#ff00ff>0 <FONT 
  color=#000000>AND s_day[ i ] == <FONT 
  color=#ff00ff>0 <FONT 
  color=#000000>AND phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>2<FONT 
  size=2>) {     
        phase_arr[ i ] = <FONT 
  color=#ff00ff>3<FONT 
  size=2>;        } 
  else <FONT 
  color=#800000>if (b_day[ i ] == <FONT 
  color=#ff00ff>0 <FONT 
  color=#000000>AND s_day[ i ] == <FONT 
  color=#ff00ff>0 <FONT 
  color=#000000>AND phase_arr[ i - 
  1 ] == <FONT 
  color=#ff00ff>1<FONT 
  size=2>) { 
        phase_arr[ i ] = <FONT 
  color=#ff00ff>2<FONT 
  size=2>;    } } 
  //<FONT 
  face="Courier New"> daybar = <FONT 
  color=#0000ff>Day<FONT 
  size=2>(); // 
  --------------------------------------<FONT 
  face="Courier New"> <FONT 
  color=#0000ff>TimeFrameRestore<FONT 
  face="Courier New">(); <FONT 
  color=#008000>// expand arrays <FONT 
  color=#000000>xx = <FONT 
  face="Courier New"><FONT 
  color=#0000ff>TimeFrameExpand( xx, <FONT 
  color=#000000>inDaily,mode = <FONT 
  color=#000000>expandFirst<FONT 
  face="Courier New">  ); B1 = 
  TimeFrameExpand( B1, 
  inDaily,mode = 
  expandFirst<FONT 
  face="Courier New">  ); S1 = 
  TimeFrameExpand( S1, 
  inDaily,mode = 
  expandFirst<FONT 
  face="Courier New">  ); HBOP = 
  TimeFrameExpand( HBOP, 
  inDaily,mode = 
  expandFirst<FONT 
  face="Courier New">  ); LBOP = 
  TimeFrameExpand( LBOP, 
  inDaily,mode = 
  expandFirst<FONT 
  face="Courier New">  ); 
  trailstop_short = <FONT 
  color=#0000ff>TimeFrameExpand( trailstop_short, 
  inDaily,mode = 
  expandFirst<FONT 
  face="Courier New">  ); 
  trailstop_long = TimeFrameExpand<FONT 
  color=#000000>( trailstop_long, <FONT 
  color=#000000>inDaily,mode = <FONT 
  color=#000000>expandFirst<FONT 
  face="Courier New">  ); 
  // expand arrays <FONT 
  color=#000000>phase_arr = 
  <FONT 
  color=#0000ff>TimeFrameExpand( phase_arr, 
  inDaily,mode = 
  expandFirst<FONT 
  face="Courier New">  ); 
  phase_arr_l1 = TimeFrameExpand<FONT 
  color=#000000>( phase_arr_l1, <FONT 
  color=#000000>inDaily,mode = <FONT 
  color=#000000>expandFirst<FONT 
  face="Courier New">  ); b_day = 
  TimeFrameExpand( b_day, 
  inDaily,mode = 
  expandFirst<FONT 
  face="Courier New">  ); s_day = 
  TimeFrameExpand( s_day, 
  inDaily,mode = 
  expandFirst<FONT 
  face="Courier New">  ); daybar 
  = TimeFrameExpand( 
  daybar, inDaily<FONT 
  color=#000000>,mode = <FONT 
  color=#000000>expandFirst<FONT 
  face="Courier New">  ); 
  // adjust phase array for charting 
  purposes<FONT 
  color=#000000> hlp_phase = phase_arr; hlp_phase = <FONT 
  color=#ff00ff>0<FONT 
  size=2>; hlp_b = hlp_phase; hlp_s = hlp_phase; 
  hlp_phase_l1 = hlp_phase; <FONT 
  color=#800000>for (i = <FONT 
  color=#ff00ff>1; i < <FONT 
  color=#000000>BarCount<FONT 
  face="Courier New">; i++) { 
     if<FONT 
  color=#000000> (HBOP[ i ] != HBOP[ i - <FONT 
  color=#ff00ff>1<FONT 
  size=2>]) {     
        hlp_phase[ i ] = phase_arr[ i ]; 
        hlp_phase_l1[ i ] = phase_arr_l1[ i ]; 
        hlp_b[ i ] = b_day[ i ]; 
        hlp_s[ i ] = s_day[ i ]; 
            } } 
  // For Chart <FONT 
  color=#000000><FONT 
  color=#0000ff>Plot(<FONT 
  color=#000000>C,<FONT 
  color=#ff00ff>"",<FONT 
  color=#ff00ff>1,<FONT 
  color=#ff00ff>64<FONT 
  size=2>); <FONT 
  color=#000000>Title=<FONT 
  color=#0000ff>Name()+ ", 
  O:"+WriteVal<FONT 
  color=#000000>(O<FONT 
  color=#000000>)+ ", H:"<FONT 
  color=#000000>+WriteVal<FONT 
  color=#000000>(H<FONT 
  color=#000000>)+ ", L:"<FONT 
  color=#000000>+WriteVal<FONT 
  color=#000000>(L<FONT 
  color=#000000>)+ ", C:"<FONT 
  color=#000000>+WriteVal<FONT 
  color=#000000>(C<FONT 
  face="Courier New">); <FONT 
  color=#008000>// 1 = "B" day, 2 = "O" day, 3 = "S" 
  day<FONT 
  color=#000000> PlotShapes<FONT 
  color=#000000>(shapeDigit1<FONT 
  color=#000000> * (hlp_phase == 1<FONT 
  color=#000000>),IIf<FONT 
  color=#000000>(hlp_b == 1<FONT 
  color=#000000>,colorYellow<FONT 
  color=#000000>,colorWhite<FONT 
  color=#000000>),0, 
  HBOP,0<FONT 
  face="Courier New">); <FONT 
  color=#0000ff>PlotShapes(<FONT 
  color=#000000>shapeDigit2 * (hlp_phase == 
  2),<FONT 
  color=#000000>colorWhite,<FONT 
  color=#ff00ff>0, HBOP,<FONT 
  color=#ff00ff>0<FONT 
  size=2>); <FONT 
  color=#0000ff>PlotShapes(<FONT 
  color=#000000>shapeDigit3 * (hlp_phase == 
  3),<FONT 
  color=#0000ff>IIf(hlp_s == <FONT 
  color=#ff00ff>1,<FONT 
  color=#000000>colorYellow,<FONT 
  color=#000000>colorWhite),<FONT 
  color=#ff00ff>0, HBOP,<FONT 
  color=#ff00ff>0<FONT 
  size=2>); <FONT 
  color=#0000ff>PlotShapes(<FONT 
  color=#000000>shapeDigit1 * (hlp_phase_l1 == 
  1),<FONT 
  color=#000000>colorLightBlue,<FONT 
  color=#ff00ff>0, HBOP,-<FONT 
  color=#ff00ff>15<FONT 
  size=2>); <FONT 
  color=#0000ff>PlotShapes(<FONT 
  color=#000000>shapeDigit3 * (hlp_phase_l1 == 
  3),<FONT 
  color=#000000>colorLightBlue,<FONT 
  color=#ff00ff>0, HBOP,-<FONT 
  color=#ff00ff>15<FONT 
  size=2>); // 
  levels<FONT 
  color=#000000> Plot<FONT 
  color=#000000>(B1,""<FONT 
  color=#000000>,colorBrightGreen<FONT 
  color=#000000>,1<FONT 
  face="Courier New">); <FONT 
  color=#0000ff>Plot(S1,<FONT 
  color=#ff00ff>"",<FONT 
  color=#000000>colorRed,<FONT 
  color=#ff00ff>1<FONT 
  size=2>); Plot<FONT 
  color=#000000>(HBOP,""<FONT 
  color=#000000>,colorOrange<FONT 
  color=#000000>,1<FONT 
  face="Courier New">); <FONT 
  color=#0000ff>Plot(LBOP,<FONT 
  color=#ff00ff>"",<FONT 
  color=#000000>colorGreen,<FONT 
  color=#ff00ff>1<FONT 
  face="Courier New">); Send 
  BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to 
  suggest@xxxxxxxxxxxxx-----------------------------------------Post 
  AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check 
  group FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  


Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html








Yahoo! Groups Sponsor


  ADVERTISEMENT 












Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/ 
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.