/** Реверсивная трендовая стратегия на пересечении быстрой экспоненциальной и медленной простой скользящих средних. Вход в позицию только на пересечении EMA и SMA. Developed by AlfaDirect; Algorithm = ТРЕНД; Hash code 23B639E60D11042ADA76E9598B438577 **/ function Initialize() { StrategyName = "Alfa_ES_Take"; AddParameter("P1", 15, "период EMA ", 1); AddParameter("P2", 35, "период SMA", 1); AddParameter("PTake", 3, "", 1); AddInput("Input1", Inputs.Candle, 60, true, "SBER=МБ ЦК"); LongLimit = 1; ShortLimit = -1; } function OnUpdate() { /// ПРАВИЛО 1 if ( (EMA(Input1.Close, P1) > SMA(Input1.Close, P2)) && (EMA(Input1.Close, P1)[1] <= SMA(Input1.Close, P2)[1]) ) { EnterLong(); } /// ПРАВИЛО 2 if ( (EMA(Input1.Close, P1) < SMA(Input1.Close, P2)) && (EMA(Input1.Close, P1)[1] >= SMA(Input1.Close, P2)[1]) ) { EnterShort(); } /// ПРАВИЛО 3 if ( (CurrentPosition() > 0) && (CurrentPLper() > PTake) ) { CloseLong(); } /// ПРАВИЛО 4 if ( (CurrentPosition() < 0) && (CurrentPLper() > PTake) ) { CloseShort(); } }