PureBytes Links
Trading Reference Links
|
I will add one other item to this
If you are entering your trade with one bar delay then you need to
include this to find the buyprice
SellPrice > valuewhen(ref(buy,-1),BuyPrice + 10);
--
Cheers
Graham Kav
AFL Writing Service
http://www.aflwriting.com
2008/7/11 ozzyapeman <zoopfree@xxxxxxxxxxx>:
> Graham, very helpful post. Thank you very much. I will continue to study.
>
> I haven't programmed for about twenty years, so it's taking me some
> time to regain my footing on basic stuff. But the rework of my code
> that you so kindly performed will allow me to make solid strides over
> the next few weeks.
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@xxx> wrote:
>>
>> Buyprice, sellprice, shortprice and coverprice are arrays and have a
>> value in every bar according to how they are defined
>> eg Buyprice = O; means it is Open price in every bar
>>
>> you can use valuewhen(buy,buyprice)
>> but if buy has many bars where it is true, even after entry then you
>> are just referencing the most recent bar where it is true
>> In this even exrem cannot help as it is only effective after it is used
>>
>> Buy = (myMA1 > MyMA2); means every bar that myMA1 is greater than
>> MyMA2 gives buy==true
>> You can use Cross(myMA1, MyMA2) to overcome the defficiency of using a
>> straight > for the condition.
>> Provided the ultimate Sell is reverse Cross(myMA2, MyMA1) then you can
>> use the valuewhen as above because you would never get a true buy
>> result when inside a trade
>>
>> Also be extremely careful with exit conditions, because if you do not
>> get all conditions true then an exit may never occur, ie
>> Sell = FastMA < SlowMA AND SellPrice > (BuyPrice + 10);
>> what happens if the array you have defined as sellprice never gets
>> above the (BuyPrice + 10)? It would not matter what happens to the
>> MA's as the price has not recovered. You couyld be in the trade for
>> years waiting for the price to recover to above the entry price
>> Even changing to Sell = FastMA < SlowMA AND SellPrice > valuewhen(buy,
>> BuyPrice + 10); will not help
>> Also consider if you defined both buyprice and sellprice as Open, then
>> a straight SellPrice > (BuyPrice+10) as both would be equal for every
>> bar, like saying Open > Open+10, can never happen
>>
>> Of course if you have a stop loss defined then OK, exit will happen
>> and your Sell would only be needed for a profitable exit
>>
>> Hard to express everything within 5 minutes I allot as a full
>> explanation of the problems and what to look for would take pages, if
>> not a book on designing trading systems in required computer logic
>>
>>
>> --
>> Cheers
>> Graham Kav
>> AFL Writing Service
>> http://www.aflwriting.com
>>
>>
>> 2008/7/11 ozzyapeman <zoopfree@xxx>:
>> > Thanks Graham. I think this does the trick. Much appreciated.
>> >
>> > If you have a chance, can you spot the logic flaw as to why my mod to
>> > Prashanth's code in this same thread does not work? That one does not
>> > use loops and looks much simpler. But if there is a reason why it
>> > can't work in that format, I'll just stick with the more complex
>> > looping and develop that.
>> >
>> >
>> > --- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@> wrote:
>> >>
>> >> Here is an approach from your code with some changes to make it
> follow
>> >> logic to me, and ensure variables are correctly initiated
>> >>
>> >> SetTradeDelays( 1, 1, 1, 1 );
>> >>
>> >> Sell = Cover = 0;
>> >> BuyPrice = SellPrice = ShortPrice = CoverPrice = O;
>> >>
>> >> myMA1 = MA(C,10);
>> >> MyMA2 = MA(C,100);
>> >>
>> >> Buy = (myMA1 > MyMA2);
>> >> Short = (myMA1 < MyMA2);
>> >>
>> >> inBuy = inShort = 0;
>> >> ValueAtBuy = ValueAtShort = Null;
>> >>
>> >>
>> >> for( i = 0; i < BarCount; i++ )
>> >> {
>> >> if(myMA1[i]<MyMA2[i] AND inBuy AND C[i]>(ValueAtBuy + 0.0010) )
>> >> {
>> >> Sell[i] = 1;
>> >> inBuy= 0;
>> >> ValueAtBuy = Null;
>> >> }
>> >> if(myMA1[i]>MyMA2[i] AND inShort AND C[i]<(ValueAtShort - 0.0010) )
>> >> {
>> >> Cover[i] = 1;
>> >> inShort = 0;
>> >> ValueAtShort = Null;
>> >> }
>> >>
>> >> if(inBuy) Buy[i] = 0;
>> >> if(inShort) Short[i] = 0;
>> >>
>> >> if( inBuy==0 AND Buy[i] )
>> >> {
>> >> inBuy= 1;
>> >> ValueAtBuy = C[i];
>> >> }
>> >> if( inShort==0 AND Short[i] )
>> >> {
>> >> inShort = 1;
>> >> ValueAtShort = C[i];
>> >> }
>> >> }
>> >>
>> >>
>> >> --
>> >> Cheers
>> >> Graham Kav
>> >> AFL Writing Service
>> >> http://www.aflwriting.com
>> >>
>> >> 2008/7/11 Prashanth <prash454.ta@>:
>> >> > I am not sure you require loops to do what you are looking for.
>> >> >
>> >> >
>> >> > SlowMA = MA(C,20);
>> >> >
>> >> > FastMA = MA(C,5);
>> >> >
>> >> > Buy
>> >> >
>> >> > = FastMA > SlowMA ;
>> >> >
>> >> > Sell
>> >> >
>> >> > = Cross(SlowMA , FastMA) OR SellPrice > (BuyPrice + 10);
>> >> >
>> >> > Short
>> >> >
>> >> > = FastMA < SlowMA;
>> >> >
>> >> > Cover
>> >> >
>> >> > = Cross(FastMA, SlowMA) OR CoverPrice < (ShortPrice - 10);
>> >> >
>> >> > Instead of AND, I have used OR since both Crossover and Price
>> > being above 10
>> >> > pips cannot happen simultaneously.
>> >> >
>> >> > Cheers
>> >> >
>> >> > Prashanth
>> >> >
>> >> >
>> >> >
>> >> > ----- Original Message -----
>> >> > From: ozzyapeman
>> >> > To: amibroker@xxxxxxxxxxxxxxx
>> >> > Sent: Friday, July 11, 2008 3:09 AM
>> >> > Subject: [amibroker] Re: Help on Debugging this If-Else Loop
>> >> > Still toying around with this and still can't get it to work. I
>> > just can't
>> >> > seem to figure out how to specify the current price. Thought
> that the
>> >> > ValueWhen function might be able to help.
>> >> >
>> >> > All I'm trying to achieve is this very simple test system, for
> Forex
>> >> > Intraday:
>> >> >
>> >> > 1. Buy Long position when the fast MA is above the slow MA
>> >> > 2. Sell the Long position when the fast MA falls below the slow
>> > MA, AND
>> >> > the current price is at least 10 pips higher than the original
>> > entry price.
>> >> >
>> >> > 3. Enter Short position when fast MA is below the slow MA
>> >> > 4. Sell the Short position when the fast MA rises above the slow
>> > MA, AND
>> >> > the current price is at least 10 pips lower than the original
>> > entry price.
>> >> > Code below. Anyone?
>> >> >
>> >> >
>> >> >
>> >> > Buy = (myMA1 > MyMA2);
>> >> > Short = (myMA1 < MyMA2);
>> >> >
>> >> > PriceAtBuy = 0;
>> >> > PriceAtShort = 0;
>> >> >
>> >> > for( i = 0; i < BarCount; i++ )
>> >> > {
>> >> > if( PriceAtBuy == 0 AND Buy[ i ] )
>> >> > {
>> >> > PriceAtBuy = Buy[ i ];
>> >> > ValueAtBuy = ValueWhen(Buy[i]>0,C,1);
>> >> > }
>> >> >
>> >> > if( PriceAtShort == 0 AND Short[ i ] )
>> >> > {
>> >> > PriceAtShort = ShortPrice[ i ];
>> >> > ValueAtShort = ValueWhen(Short[i]>0,C,1);
>> >> > }
>> >> >
>> >> >
>> >> > if(
>> >> > (myMA1[i] < MyMA2[i]) AND (PriceAtBuy > 0) AND (C[i] >
>> >> > (ValueAtBuy[i] + 0.0010))
>> >> > )
>> >> > {
>> >> > Sell[ i ] = 1;
>> >> > PriceAtBuy = 0;
>> >> >
>> >> > }
>> >> > else
>> >> > Sell[ i ] = 0;
>> >> >
>> >> > if(
>> >> > (myMA1[i] > MyMA2[i]) AND (PriceAtShort > 0) AND (C[i] <
>> >> > (ValueAtShort[i] - 0.0010))
>> >> > )
>> >> > {
>> >> > Cover[ i ] = 1;
>> >> > PriceAtShort = 0;
>> >> > }
>> >> > else
>> >> > Cover[ i ] = 0;
>> >> >
>> >> >
>> >> > }
>> >> >
>> >>
------------------------------------
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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
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/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> 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/
|