Ciao, I want build some trading system but I have first problems on Multicharts.
I wote a simple code that buy and sell on cross EMA but can't understand why buy and sell order are always on top or bottom of candles and not near the EMA crossing.
Someone can help me please? I lost all afternoon sigh :pcguru:
[IntrabarOrderGeneration = True]
inputs:
FastLength(5), // Lunghezza della EMA veloce su Data1 (grafico a 15 minuti)
SlowLength(52); // Lunghezza della EMA lenta su Data1 (grafico a 15 minuti)
variables:
FastEMA(0),
SlowEMA(0);
// Calcolo delle medie mobili esponenziali su Data1 (15 minuti)
FastEMA = XAverage(Close, FastLength);
SlowEMA = XAverage(Close, SlowLength);
// Condizione di acquisto: EMA veloce incrocia al rialzo la EMA lenta
if (FastEMA crosses over SlowEMA) and MarketPosition = 0 then begin
Buy ("BuySignal") next bar at market;
end;
// Condizione di vendita: EMA veloce incrocia al ribasso la EMA lenta
if MarketPosition = 1 and (FastEMA crosses under SlowEMA) then begin
Sell ("ExitOnCross") next bar at market;
end;