LIMIT ORDERS for Amibroker (AFL)
Trending almost 11 years ago Amibroker (AFL)
If you hope to get a better price on the entry, you might try a limit order. You get complete control over the entry with the following code
Indicator / Formula
Copy & Paste Friendly
// EnterAtLimit.afl
//
// Entry using a Limit Order.
// Try to get a better price than the Market Order would give.
//
// This example uses a simple moving average crossover to
// illustrate entering a long position at the market.
//
// The delay between the signal and the entry is
// controlled either by the Settings window or the AFL code.
//
// For market orders, enter and exit Market On Close
// with no delay
SetTradeDelays(0,0,0,0);
BuyPrice = C;
SellPrice = C;
// The trading system is a simple moving average crossover
MA1 = MA(C,5);
MA2 = MA(C,25);
// The signal is generated on the bar when MA1
// crosses above MA2
BuySig = Cross(MA1,MA2);
// If we can get in at 1% below the Close on the
// day the signal was generated, we will enter,
// otherwise pass on this signal.
Buy = (Ref (BuySig,-1)==1) AND (L<0.99*Ref(C,-1));
BuyPrice = 0.99*Ref(C,-1);
// When the sell signal comes, use a Market On Close order. Sell = Cross(MA2,MA1);
1 comments
Leave Comment
Please login here to leave a comment.
can u please post for short side limit order entry afl