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

Re: [amibroker] Re: Plotting Bands when Long or Short



PureBytes Links

Trading Reference Links

I didn't get a chance to look at your code yet.  But here's a generic loop 
that might be useful

Buy = Short = Bought = Shorted = BuyopenPrice = Shortopenprice = 0;

Buy[1] = Bought[1] = 1; //Initialize 1st bar to a Buy

for (i = 2; i < BarCount-1; i++)

{

//Continue these variables across the loop

Bought[i] = Bought[i-1];

Shorted[i] = Shorted[i-1];

BuyOpenPrice[i] = BuyOpenPrice[i-1];

ShortOpenPrice[i] = ShortOpenPrice[i-1];



//Remove intermediate signals

if (Short[i] AND Shorted[i-1])

{Short[i] = 0;

}

if (Buy[i] AND Bought[i-1])

{Buy[i] = 0;

}


//Test for Buy exit

if (Bought[i-1])

{


Buystopprice[i] = BuyOpenPrice[i] - XXX; //Stop value code here

if (C[i] < BuyStopprice[i] )

{

Short[i] = Shorted[i] = 1; //This is reversal system (New short when Long 
closes) You may not want this

ShortOpenPrice[i] = C[i];

Bought[i] = 0;

}


}

//Test for Short exit

if (Shorted[i-1])

{

ShortStopPrice[i] = ShortOpenPrice[i] + XXX; //Stop value code here

if (C[i] > ShortStopprice[i] )

{

Buy[i] = Bought[i] = 1;

BuyOpenPrice[i] = C[i];

Shorted[i] = 0;

}


}

}

----- Original Message ----- 
From: "sslack88" <jzzpiano88@xxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Sunday, January 22, 2006 11:44 PM
Subject: [amibroker] Re: Plotting Bands when Long or Short


> Thanks for the reply chuck.  TrailingStop is the LLV value of the
> past three days (ignoring inside periods).  I don't want to initiate
> a short position until the lowerstop is violated.  It sounds like I
> might have to create a FOR loop.  Could you give me a basic piece of
> code on how to do this type of LongOpenPosition and
> ShortOpenPosition?
>
> Here is the sample code that I was writing (run this as an
> explore).  Everthing works except the LongPosition because I cannot
> initialize the ShortPosition == 0 until the array is run.  Take a
> look and see if you can figure it out.
>
> //3-Bar Pattern Exploration
>
> Filter=1;
>
> //Bar Number
> AddColumn(BarIndex(),"Bar Index");
>
>
> //Identifys number of lookback bars to ignore inside days
> Countbars=BarIndex()-ValueWhen(Inside()==0,BarIndex(),4);
>
> //Long and Short Setups
> HigherClose = C > Ref(C,-1);
> LowerClose = C < Ref(C,-1);
> AddColumn (HigherClose,"Higher Close");
> AddColumn (LowerClose, "Lower Close");
>
> //3-bar stop level
> ThreeBarLow = LLV(L,Countbars);
> ThreeBarHigh = HHV(H,Countbars);
>
> //Recalculates stop based on a higher close or lower close
> LowerStopLoss = IIf(HigherClose, ThreeBarLow, Ref(ThreeBarLow,-1));
> UpperStopLoss = IIf(LowerClose, ThreeBarHigh, Ref(ThreeBarHigh,-1));
> AddColumn (LowerStopLoss,"3-Bar High Stop");
> AddColumn (UpperStopLoss,"3-Bar Low Stop");
>
> //Long and Short stop loss levels
> LongStopOut = C < LowerStopLoss;
> ShortStopOut = C > UpperStopLoss;
> AddColumn (LongStopOut,"LongStopOut");
> AddColumn (ShortStopOut,"ShortStopOut");
>
> //Identifying if there is an open long or short position
> LongEntry = HigherClose;
> LongPosition = Flip(LongEntry,LongStopOut);
> ShortEntry = LowerClose AND LongPosition == 0;
> ShortPosition = Flip(ShortEntry,ShortStopOut);
> AddColumn (LongPosition,"LongPosition");
> AddColumn (ShortPosition,"ShortPosition");
>
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "cstrader" <cstrader232@xxxx>
> wrote:
>>
>> I believe you are having the same troubles that I was in a few
> weeks ago.
>> It's not clear to me if you want the long to close when the short
> is opened
>> or not.  Also, your 'trailing stop' formula is not clear.  If the
> trailing
>> stop is based on the open price then your sell is linked to the
> buy.  I'm
>> guessing you are also wanting to exclude unwanted intermediate
> signals.  To
>> do these things I have discovered -- with much help from the users
> of this
>> group -- that you must use either applystop if it is suitable, or
> use a
>> 'for' loop to define your trade signals -- Flip, exrem etc are not
> suitable
>> for this.
>>
>> chuck
>>
>>
>> ----- Original Message ----- 
>> From: "sslack88" <jzzpiano88@xxxx>
>> To: <amibroker@xxxxxxxxxxxxxxx>
>> Sent: Sunday, January 22, 2006 7:45 PM
>> Subject: [amibroker] Plotting Bands when Long or Short
>>
>>
>> >I want to plot a green band if I am in a long position, and a red
> band
>> > if I am in a short position.  No problem, right?
>> >
>> > Here's the tricky part:
>> >
>> > ** Only one position can be open at a time
>> > * TrailingStop is a function I created
>> >
>> > LongEntry = C > Ref(C,-1);
>> > LongExit = C < TrailingStop;
>> >
>> > ShortEntry = C < Ref(C,-1);
>> > ShortExit = C > TrailingStop;
>> >
>> > * Remember, only one position can be open at a time.  Obviously,
>> > higher closes are going to exist even when I am in a short
> position,
>> > so using the FLIP function doesn't seem to work.
>> >
>> > Any Ideas?  Thanks in advance.
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > 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
>> >
>> >
>> >
>> >
>> >
>> >
>>
>
>
>
>
>
>
>
> 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
>
>
>
>
>
> 



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/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/