Try this:

SetTradeDelays( 1, 1, 1, 1 );
SetPositionSize(2, spsPercentOfEquity);

BuyPrice = O;
SellPrice = O;

Buy = mtRandomA() <= 0.4;       // 40% chance of buy
Sell = mtRandomA() <= 0.2;      // 20% chance of sell


Mike

--- In [email protected], "spacebass5000" <spacebass5...@...> wrote:
>
> Hey all,
> 
> I need to formulate a way to create an algo that randomly enters and exits a 
> given stock. I have devised the following (to no avail):
> 
> // start code ==============================
> 
> SetTradeDelays(1,1,1,1);
> 
> BuyPrice = O;
> SellPrice = O;
> ShortPrice = O;
> CoverPrice = O;
> 
> RandomNum = floor(mtRandom() * 10000);
> 
> printf("\nRandomNum = %5.2f\n", RandomNum);
> 
> while(RandomNum >= BarCount)
> {
>       RandomNum = floor(mtRandom() * 10000);
>       printf("RandomNum = %5.2f\n", RandomNum);
> }
> 
> SetOption("HoldMinBars", RandomNum );
> 
> CoinFlip = floor(mtRandom() * 10);
> 
> printf("\nCoinFlip = %5.2f\n", CoinFlip);
> 
> if(CoinFlip >= 5)
> {
>       Buy = True;
>       Sell = False;
>       Short = Sell;   
>       Cover = Buy;
>       
> }
> else
> {
>       Buy = False;
>       Sell = True;
>       Short = Sell;   
>       Cover = Buy;
> }
> 
> Buy = ExRem(Buy, Sell);
> Sell = ExRem(Sell, Buy);
> 
> Short = ExRem(Short, Cover);
> Cover = ExRem(Cover, Short);
> 
> // end code ==============================
> 
> I am planning at looking at 15 years of daily data... the reason to multiply 
> the random number by 10000. Granted, this hasn't really seemed to work out 
> for me yet. I don't really see really small numbers generated from mtRandom 
> so most of my holding times are really long. 
> 
> Any comments related to created random entries/exits and/or the code I have 
> whipped up are surely welcome.
>


Reply via email to