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

[amibroker] Re: Detecting an Open Position with AFL?



PureBytes Links

Trading Reference Links


Here's my code that's supposed to exit at either my stop-loss price 
level or my profit target, whichever comes first.  However, it's not 
working as I had planned.  Is this not the right approach to do this?

Furthermore, I haven't added in the code yet, but for sells 
triggered by my sell-stop price level I not only want to sell one 
contract to offset the long position, but now I want to be short one 
contract.  

Any ideas about what I'm doing wrong in my code?
If this can be done without using a loop please let me know as I 
haven't seen any good complex examples of buy/sell conditions which 
don't use loops.  Again, thanks.

//Profit Target and Stop Loss conditions to exit the trade
for( i = 0; i < BarCount; i++ )
{
if  ( Buy[i] == 1 && High[i] >= (1 + Profit_Target/100) * BuyPrice
[i])
{
	Sell[i] = 1;
	SellPrice[i] = (1 + Profit_Target/100) * BuyPrice[i];
}
if ( Buy[i] == 1 && Low[i] <= (1 - MAE_Threshold/100) * BuyPrice[i])
{
	Sell[i] = 1;
	SellPrice = (1 - MAE_Threshold/100) * BuyPrice[i];
}
else
	Sell[i] = 0;
}











--- In amibroker@xxxxxxxxxxxxxxx, "Christoper" <turkey@xxxx> wrote:
> 
> Look, I'm don't know what you're trying to do...
> 
> But in AB, just set your "Sell" conditions and then AB will make 
sure
> you're "in" before that Sell condition is triggered.  You don't 
really
> need to know when you're in.
> 
> Basically I don't know if such a function exists, and I don't see 
how
> that would be used.  Can you give us a little more of an idea of 
what
> you're trying to do?
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "The Webmaster"
> <maintainer_wiz@xxxx> wrote:
> > 
> > Is there a function to detect the open trading position of a bar?
> > 
> > I'm trying to use a for loop to check certain conditions which 
would 
> > exit my long and go short.  However, it's not working because I 
> > think my coding assumptions about how this array programming 
thing 
> > works are incorrect.
> > 
> > If it's not already available, AB should add an AFL function or 
> > variable called Position which would return the open position of 
the 
> > bar.  Just like in Trade Station's EasyLanguage.  AB has 
potential, 
> > but they should really look to Easy Language as a guide to 
improving 
> > AFL.





------------------------ 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/