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

[amibroker] Conditional Buy/Sell orders



PureBytes Links

Trading Reference Links

I have the following code, however,I would like to trigger buy/sell
rules only under certain conditions:

1.  Positions are entered on the cross of the Blue and red lines.
2.  positions are exited on the cross of the blue and green lines
3.  If I enter long on cross(Blue, Red)I will exit on Cross(green, blue).
4.  Although I have exited the initial LONG, if the BLUE does not
cross below the RED (triggering a SHORT), BUT turns and recrosses
above green again (usually due to short term price action), I would
like to re-enter LONG 
5.  Obviously there could be periods of NO POSITION.

Any help greatly appreciated.  


//The Shifted EMA - Default is 3 Period and -3 Lead/Lag
//Code Credit help  to Franklin from AB Board

EMAPeriod = Param("Fast EMA",3,1,25,1);
DisplacementPeriod = Param("Shift",-3,-25,25,1);

Blue = Ref(EMA(Close,EMAPeriod),-DisplacementPeriod);
Green = EMA(C, 5);
Red = EMA(C, 15);

//Plot the Lines
Plot(Ref(EMA(Close,EMAPeriod),-DisplacementPeriod),"DEMA1",colorBlue,styleThick|styleLine);
Plot(EMA(Close, 5 ), "5 Wk EMA", colorGreen, styleLine);
Plot(EMA(Close, 15 ), "15 Wk EMA", colorRed, styleLine);

//Buy and Sell Rules

Buy = Cross(blue, red);
Sell = Cross(green, blue);
Short = Cross(red, blue);
Cover = Cross(blue, green);

for ( i = 12; i < BarCount; i++)
{
if( Buy[i]) PlotText ("LE" + C[i], i, L[i], colorGreen );
if( Sell[i]) PlotText ("LX" + C[i], i, H[i], colorGreen );
if( Short[i]) PlotText ("SE" + C[i], i, L[i], colorRed );
if( Cover[i]) PlotText ("SX" + C[i], i, H[i], colorRed );
}

Title = Name() + " " + Date() + EncodeColor(colorIndigo) + " " + C +
WriteVal(ROC( Close, 1) ) + "%" + EncodeColor(colorBlue) + " Three
Shift Indicator "; 






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