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

Re: [amibroker] TJ: Traders Tips TASC August 2004



PureBytes Links

Trading Reference Links

Graham,

I want to do something that should be simple.

I want to place a Buy (It does not matter what the rule is) Lets say buy on
first bar.

THEN, I want to use a trailing stop.

When stop is triggered i want to go short. I then want the same trailing
stop to apply to the new short position.

When the short is stopped out I want to go Long again with the same trailing
stop.


It seems that everything I tried so far requires buy, sell, cover and short
to be defined before the first trade and of course one does not know the
rule to take any position except for the trailing stop being broken.

If I define the rule for Short it should be  "when The current price breaks
the highest price since the Buy entry price less the stop figure"


Think this is going to require a loop and a loop within a loop. What do you
think Bob?



Here is an attempt at looping. This does not work. Any suggestions?

NumContracts = 1;
PositionSize = NumContracts * MarginDeposit;


stop_figure = Optimize("Stop", 4, 1, 20, 1);

Buy = Short = Cover = Sell = O;
HighAtBuy = 0;
LowAtSell = 0;

for( i = 0; i < BarCount; i++ )
{
     if( Buy ==0 && Sell = 0 && Short = 0 && Cover == 0 )
      {
	      Buy = Buy[ i ] == 1;
	HighAtBuy = High[ i ];
              }

	for( j = 0; j < BarCount; j++)
	{
		if((HighatBuy < High[ i ] && Buy == 1) OR (HighatBuy < High[ i ] && Cover
== 1))
		{
		HighatBuy = High[ i ];
		}
		else
		if((highatBuy > High[ i ] + stop_figure) && Buy == 1)
		{
		Sell = 1; Buy = 0; LowatSell = Low[ i ];
		}
		else
		if((highatBuy > High[ i ] + stop_figure)&& Cover == 1)
		{
		Short = 1; Cover = 0; LowatSell = Low[ i ];
		}

	}

	for( j = 0; j < BarCount; j++)
	{
		if((LowatSell > Low[ i ] && Short == 1) OR (LowatSell > Low[ i ] && Sell
== 1))
		{
		LowatBuy = Low[ i ];
		}
		else
		if((LowAtSell < Low[ i ] - stop_figure) && Short == 1)
		{
		Cover = 1; Short = 0; HighatBuy = High[ i ];
		}
		else
		if((LowAtSell < Low[ i ] - stop_figure) && Sell == 1)
		{
		Buy = 1; Sell = 0; Highatbuy = High[ i ];
		}

	}


}

SetTradeDelays(0,0,0,0);

/* the equity curve comes from the next bit of code.*/

AddToComposite( Equity (), "~MACD", "V");
Graph0 = Foreign("~MACD", "V");



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/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/