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

[amibroker] Re: How do you know what your last trade was



PureBytes Links

Trading Reference Links


... or ... you can simply check the buy, sell, short, cover arrays ...

One can restate these as often as one wants, the last one of each 
counts.  This for example is one way to do equity feedback.

--- In amibroker@xxxxxxxxxxxxxxx, Terry <MagicTH@xxxx> wrote:
> micmus2002,
> 
> Hereıs what I use. All my code above /* The Trading Signals */ is 
to decide
> what my conditions for Buy/Sell are and are in a LOOP. In this loop 
I
> determine if Iım on a buy or a sell. Then I execute the regular 
BUY/SELL
> commands after Iıve figured out whatıs going on day by day in the 
loop. Here
> I have used my loop variables to tell me if Iım on a Buy or a Sell. 
This
> particular code is always in the market so Short = Sell and Cover = 
Buy. You
> may have to extend it if you have separate signals. Watch out for 
line
> wraps.
> 
> PS: You need a loop because arrays are calculated as they are 
encountered,
> thus you canıt read the Buy array before itıs been computed. Loops 
let you
> do that.
> 
> for loop goes here()
> {
>     Your rules for trading go here
>  
>     /*   The Trading Signals   */
>  
>     if (Cond1[I] OR Cond2[I]) newBuy[i] = True;
>     if (Cond3[I] OR Cond4[I]) newSell[i] = True;
>     if (newBuy[i] OR (onBuy[i-1] AND NOT newSell[i])) //IF both are 
True,
> Long signal wins!
>     {
>          onBuy[i] = True; //Daily Buy State
>          newSell[i] = False; //In case of both being true due to 
rule
> sequencing (Can't happen! But will leave as insurance.)
>     }
>     onSell[i] = NOT onBuy[i]; //If it's not onBuy then it's onSell
>  
>     //Record bar of new Entry whether it is Buy or Sell isn't 
important
>     if (newBuy[i] OR newSell[i])
>       entry[i] = i;
>     else
>       entry[i] = entry[i-1]; //continue yesterday's value if no new 
signals
> }
>  
> /* End of looping Rules tests and Buy/Sell signals. Now just 
execute the
> results */
> 
> Buy = newBuy;
> gainbuy = IIf(OnBuy,(C - ValueWhen(Buy,BuyPrice,1)) /
> ValueWhen(Buy,BuyPrice,1),0);
> BuyStopValue = IIf(newSell,1,IIf(gainbuy <= -7,2,IIf(BarsSince(Buy) 
>
> 4,5,0)));
> Sell = BuyStopValue;
> Short = newSell; //A_LiU > 0; //Avoids shorting all D rules...goes 
to Cash
> gainsell = IIf(OnSell,(C - ValueWhen(Short,ShortPrice,1)) /
> ValueWhen(Short,ShortPrice,1),0);
> SellStopValue = IIf(newBuy,1,IIf(gainsell <= -4,2,IIf(BarsSince
(Short) >
> 3,5,0)));
> Cover = SellStopValue; //Buy;
> 
> -- 
> Terry
> 
> 
> From: "micmus2002" <micmus2002@xxxx>
> Reply-To: amibroker@xxxxxxxxxxxxxxx
> Date: Tue, 05 Oct 2004 02:34:10 -0000
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] How do you know what your last trade was
> 
> 
> I want to write stop logic, but since its based on a logical test I
> cannot seem to use the applystop function.
> 
> Therefore  it seems I will need to have another Cover /Sell 
statement
> which will only be triggered if I already have an opposite position.
> i.e. Cover if am already Short and my stop condition is true, and
> Sell if I am already long and that stop position is true.
> 
> This means I need to know what my current position is, and my
> question is how do I do this. I know Wealthlab has a Position Array
> but I can't find anything similar in AB.
> 
> I am sure there must be a way to do this. Would be grateful if
> someone could provide the code.
> 
> Thanks
> 
> 
> 
> [Non-text portions of this message have been removed]





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/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/