PureBytes Links
Trading Reference Links
|
Hi,
Did anyone find an answer to this?
I want to program in a stop and reverse system, where the stoploss,
limit exit and break even are different for the initial trade and
subsequent reverse trade.
The reverse trade has a stoploss based upon the where the first trade
stoploss was taken.
I've narrowed down the solution to using barssince(lasttrade) to find
out what the most recent trade was (buy or sell).
I can't use barssince(buy/sell) because how they are triggered is
dependent on the previous transaction.
In order to work out my short-reverse (a buy trade) stoploss, I need to
determine if the last transaction was a buy (therefore
short-reverse-stop-loss cannot be valid) or if was a short-stop-loss trade.
Thanks
micmus2002 wrote:
>Fred,
>
>
>My understanding of the Buy and Sell array is that a reference will
>get the value for the current bar. i.e. whether your buy (or sell
>signal) is true for that bar.
>
>The actual trade you are currently in which would have been based on
>Buy/Sell signals in a previous bar is not directly calculable from
>here.
>
>The Equity function has its own built in method to calculate what the
>current position would be based on Buy Sell, but i don't know how you
>could use that to get your current open position.
>
>Perhaps i am missing something.
>
>MM
>
>--- In amibroker@xxxxxxxxxxxxxxx, "Fred" <ftonetti@xxxx> wrote:
>
>
>>... 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]
>>>
>>>
>
>
>
>
>
>
>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
>
>
>
>
>
>
>
>
>
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
In low income neighborhoods, 84% do not own computers.
At Network for Good, help bridge the Digital Divide!
http://us.click.yahoo.com/EpW3eD/3MnJAA/cosFAA/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/
|