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

Re: [amibroker] Re: Multiple Positions, same Security



PureBytes Links

Trading Reference Links

Hello,
 
Here is sample code promised before Easter. I am sorry for the delay in writing this for
you but I was busy with some other projects.
You need AmiBroker 4.70 to run this.
 
 
// This is sample formula that allows
// to open multiple, separate positions on the same symbol

// without averaging effect (i.e. each position on the same

// symbol is completely independent).

//

// Sample code is provided for trading one symbol

// Enter symbol you want to trade below

Symbol =
"MSFT"
;

Buy=Sell=Short=Cover=0; // real rules are defined inside custom backtest proc


// Exits will be done only by stops

ApplyStop( stopTypeProfit, stopModePercent, 5, True
);

SetCustomBacktestProc(""); // enable custom backtest



if( Status("action") == actionPortfolio
)
{
   
// actual backtest routine

   
// (low-level)


   bo =
GetBacktesterObject
();

  
SetForeign
( Symbol );
   
// make sure to calculate actual buy and buyprice arrays for symbol we need to backtest

  
Buy=Ref(Open,0) < Ref(Low,-1) AND Ref(Avg,0) < Ref(Avg,-1) AND Ref(Avg,-1) < Ref(Avg,-2
);
  
BuyPrice = Open
;
  
RestorePriceArrays
();

   
// actual backtest loop

   bo.PreProcess();

   
for( i = 1; i < BarCount
; i++ )
   {
      
// first update backtest stats and handle stops

      bo.UpdateStats( i,
0
);
      bo.HandleStops( i );
      
      
if( Buy[ i - 1 ] ) // if buy signal in previous bar

      {
         
//bo.RawTextOutput("ENTRY, bar " + i );

         bo.EnterTrade( i, Symbol,
True, BuyPrice[ i ], 5000 /* $5000 into one trade */
);
      }
      bo.UpdateStats( i,
2
);
   }
      
   bo.PostProcess();
}


Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: "Jeff" <jeffstr@xxxxxxxxxxxxx>
Sent: Wednesday, March 23, 2005 4:44 PM
Subject: [amibroker] Re: Multiple Positions, same Security

>
>
> --- In
amibroker@xxxxxxxxxxxxxxx, "Fred" <ftonetti@x...> wrote:
>>
>> For those not well versed in Wealth Lab syntax, can you describe the
>> system in English ?
>>
> Hi Fred,  EOD System.   Very simple to code in AB.
>
> Buy=Ref(Open,0) < Ref(Low,-1) AND Ref(Avg,0) < Ref(Avg,-1) AND
> Ref(Avg,-1) < Ref(Avg,-2);
>
> Very disappointed with Thomasz response (or lack of).   All I want to
> do is track and manage the SELL's of the individual BUY's, instead of
> lumping in and averaging.   I assume Thomasz avoidance of the
> objective was confirmation.   Apparently, this isn't possible with AB
> and unfortunately look's like it may be useless for my trading purposes.
>
> --Jeff 
>
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor --------------------~-->
> What would our lives be like without music, dance, and theater?
> Donate or volunteer in the arts today at Network for Good!
>
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
> --------------------------------------------------------------------~->
>
> Please note that this group is for discussion between users only.
>
> To get support from AmiBroker please send an e-mail directly to
> SUPPORT {at} amibroker.com
>
> For other support material please check also:
>
http://www.amibroker.com/support.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/

>
>
>
>


Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html





Yahoo! Groups Links