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

Re: [amibroker] Indicator counts over multiple dates



PureBytes Links

Trading Reference Links

Chuck,

yes I seen this .... I forgot to add something. If no sell is found in the j-loop you have to set i to BarCount. At least this is what I think you mean. Here is the adjusted version below that I think solves this problem. But like Tomasz mentioned one also can use ApllyStop for this. The version below gives the exact same result as when you use the ApplyStop function.

Let me know if this works and this solves the problem that you meant

rgds, Ed


procedure sell_proc(Buy,BuyPrice,open,high,low,close) {

global Sell;
global SellPrice;
global BuyAdjusted;
global exitLevel;

// initialise arrays
SellPrice = BuyPrice; SellPrice = 0; 
Sell = SellPrice; exitLevel = Sell;
BuyAdjusted = Sell;

exitLevel[ 0 ] = buyPrice[ 0 ];

for (i = 1; i < BarCount; i++) {

 exitLevel[ i ] = exitLevel[ i - 1 ];

 // 
 if (Buy[ i ] == 1) { 
 
  BuyAdjusted[ i ] = 1;
  exitLevel[ i ] = BuyPrice[ i ];
  
  // find a sell position + sellprice 
  for (j = i; j < BarCount; j++) {
   
   exitLevel[ j ] = exitLevel[ i ];
   
   // test if profit stop is hit
   if (Close[ j ] > exitLevel[ i ]) {
    
    Sell[ j ] = 1;
    SellPrice[ j ] = Close[ j ];
     
    // enter i-loop past the last sell
    i = j;
     
    // escape from j-loop
    j = BarCount;
    
   } else if (j == BarCount - 1) {
   
    i = BarCount;
   
   }
   
  }
  
 }
     
}


} // end procedure


SetBarsRequired(10000,10000);

Buy = C < BBandBot(C, 10, 2);
BuyPrice = Open;

sell_proc(Ref(Buy,-1),BuyPrice,open,high,low,close);
Buy = BuyAdjusted;
SellPrice = Close;

"";
"exit level: " + writeval(exitlevel);
"";

Plot(C,"C",1,64);
Plot(exitLevel,"",colorWhite,1);
Plot(BBandBot(C, 10, 2),"",colorLightBlue,1);
PlotShapes(IIf(Buy,shapeUpArrow,0),colorWhite, layer = 0, yposition = BuyPrice, offset = 0 );
PlotShapes(IIF(Sell,shapeDownArrow,0),colorYellow, layer = 0, yposition = SellPrice, offset = 0 );

Title=Name()+ ", O: "+WriteVal(O)+ ", H: "+WriteVal(H)+ ", L: "+WriteVal(L)+ ", C: "+WriteVal(C);


  ----- Original Message ----- 
  From: Chuck Rademacher 
  To: amibroker@xxxxxxxxxxxxxxx 
  Sent: Sunday, September 05, 2004 5:39 AM
  Subject: RE: [amibroker] Help with entry price? (for Ed)


  Ed,

  Thanks so much for taking the time to work on this for me.  I've been
  working with it for several hours and I still have one problem that I can't
  solve.

  Refreshing your memory as to what this system does:

  a.  It buys at the open tomorrow if the close today is below some bollinger
  band level.
  b.  It sells at the first profitable close.

  The problem arises when there is a fresh "buy" signal prior to getting a
  sell.  It nicely ignores the buy signal, since it is already long, but it
  establishes a new entry price based on the "buy" signal that is ignoring.

  I'm stumped.

  Any ideas?

  Thanks
    -----Original Message-----
    From: ed nl [mailto:ed2000nl@xxxxxxx]
    Sent: Friday, September 03, 2004 3:43 PM
    To: amibroker@xxxxxxxxxxxxxxx
    Subject: Re: [amibroker] Help with entry price?


    here is the version that uses loopings instead of ApplyStop,

    rgds, Ed


    procedure sell_proc(Buy,BuyPrice,open,high,low,close) {

    global Sell;
    global SellPrice;
    global BuyAdjusted;
    global exitLevel;

    // initialise arrays
    SellPrice = BuyPrice; SellPrice = 0;
    Sell = SellPrice; exitLevel = Sell;
    BuyAdjusted = Sell;

    exitLevel[ 0 ] = buyPrice[ 0 ];

    for (i = 1; i < BarCount; i++) {

    exitLevel[ i ] = exitLevel[ i - 1 ];

    //
    if (Buy[ i ] == 1) {

      BuyAdjusted[ i ] = 1;
      exitLevel[ i ] = BuyPrice[ i ];

      // find a sell position + sellprice
      for (j = i; j < BarCount; j++) {

       exitLevel[ j ] = exitLevel[ i ];

       // test if profit stop is hit
       if (Close[ j ] > exitLevel[ i ]) {

        Sell[ j ] = 1;
        SellPrice[ j ] = Close[ j ];

        // enter i-loop past the last sell
        i = j;

        // escape from j-loop
        j = BarCount;

       }

      }

    }

    }


    } // end procedure


    SetBarsRequired(10000,10000);

    Buy = C < BBandBot(C, 10, 2);
    BuyPrice = Open;

    sell_proc(Ref(Buy,-1),BuyPrice,open,high,low,close);
    Buy = BuyAdjusted;
    SellPrice = Close;

    Plot(C,"C",1,64);
    Plot(exitLevel,"",colorWhite,1);
    Plot(BBandBot(C, 10, 2),"",colorLightBlue,1);
    PlotShapes(IIf(Buy,shapeUpArrow,0),colorWhite, layer = 0, yposition =
  BuyPrice, offset = 0 );
    PlotShapes(IIF(Sell,shapeDownArrow,0),colorYellow, layer = 0, yposition =
  SellPrice, offset = 0 );



      ----- Original Message -----
      From: ed nl
      To: amibroker@xxxxxxxxxxxxxxx
      Sent: Friday, September 03, 2004 8:31 PM
      Subject: Re: [amibroker] Help with entry price?


      ofcourse ..... thanks TJ,

      this is how it's done ....

      ; ----------------------------------
      SetTradeDelays(1,0,1,0);
      SetBarsRequired(10000,10000);

      Buy = C < BBandBot(C, 10, 2);
      BuyPrice = Open;

      Sell = 0;
      ApplyStop(stopTypeProfit,stopModePoint,0.001,ExitAtStop = 0,False,1 );

      Equity(1);
      SellPrice = Close;


      Plot(C,"C",1,64);
      Plot(BBandBot(C, 10, 2),"",colorLightBlue,1);
      PlotShapes(IIf(Ref(Buy,-1),shapeUpArrow,0),colorWhite, layer = 0,
  yposition = BuyPrice, offset = 0 );
      PlotShapes(IIF(Sell,shapeDownArrow,0),colorYellow, layer = 0, yposition
  = SellPrice, offset = 0 );
      Title=Name()+ ", O: "+WriteVal(O)+ ", H: "+WriteVal(H)+ ", L:
  "+WriteVal(L)+ ", C: "+WriteVal(C);
      ; ------------------------------------


        ----- Original Message -----
        From: Tomasz Janeczko
        To: amibroker@xxxxxxxxxxxxxxx
        Sent: Friday, September 03, 2004 8:14 PM
        Subject: Re: [amibroker] Help with entry price?


        Hello,

        > I want to exit the position whenever the close is above my entry
        > price, including the close on the day of entry.

        This can be successfully achieved using ApplyStop (profit target stop)
        with mode set to point and profit set to small value (0.001)

        Best regards,
        Tomasz Janeczko
        amibroker.com


        Check AmiBroker web page at:
        http://www.amibroker.com/

        Check group FAQ at:
  http://groups.yahoo.com/group/amibroker/files/groupfaq.html


              Yahoo! Groups Sponsor
                    ADVERTISEMENT





      ------------------------------------------------------------------------
  ------
        Yahoo! Groups Links

          a.. To visit your group on the web, go to:
          http://groups.yahoo.com/group/amibroker/

          b.. To unsubscribe from this group, send an email to:
          amibroker-unsubscribe@xxxxxxxxxxxxxxx

          c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of
  Service.



      [Non-text portions of this message have been removed]



      Check AmiBroker web page at:
      http://www.amibroker.com/

      Check group FAQ at:
  http://groups.yahoo.com/group/amibroker/files/groupfaq.html


            Yahoo! Groups Sponsor




    --------------------------------------------------------------------------
  ----
      Yahoo! Groups Links

        a.. To visit your group on the web, go to:
        http://groups.yahoo.com/group/amibroker/

        b.. To unsubscribe from this group, send an email to:
        amibroker-unsubscribe@xxxxxxxxxxxxxxx

        c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of
  Service.



    [Non-text portions of this message have been removed]



    Check AmiBroker web page at:
    http://www.amibroker.com/

    Check group FAQ at:
  http://groups.yahoo.com/group/amibroker/files/groupfaq.html


          Yahoo! Groups Sponsor
                ADVERTISEMENT





  ----------------------------------------------------------------------------
  --
    Yahoo! Groups Links

      a.. To visit your group on the web, go to:
      http://groups.yahoo.com/group/amibroker/

      b.. To unsubscribe from this group, send an email to:
      amibroker-unsubscribe@xxxxxxxxxxxxxxx

      c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



  [Non-text portions of this message have been removed]



  Check AmiBroker web page at:
  http://www.amibroker.com/

  Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 


        Yahoo! Groups Sponsor 
              ADVERTISEMENT
             
       
       


------------------------------------------------------------------------------
  Yahoo! Groups Links

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



[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
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:
    http://docs.yahoo.com/info/terms/