//------------------------------------------------------------------ // EasyLanguage Code for Tradestation / MultiCharts of Strategy 0.14759.sqx // Beta version (not ready for live trading without review of the code) // // Generated by StrategyQuant 3.9.128 for MetaTrader // at 91/22/2018 15:07 //------------------------------------------------------------------ inputs: // Strategy variables MagicNumber(11111), // Trading Options ExitAtEndOfDay(false), ExitOnFriday(false), LimitSignalsTimeRange(false), SignalTimeRangeFrom(0800), SignalTimeRangeTo(0800), ExitAtEndOfRange(false), MaxTradesPerDay(0), MinimumSLPT(0), // Minimum SL/PT in ticks/pips, 0 means unlimited MaximumSLPT(0), // Maximum SL/PT in ticks/pips, 0 means unlimited // Money Management - Fixed size mmLots(0.1), InitialCapital(10000), CreatedBy("StrategyQuant X"); vars: // Internal variables LongEntrySignal(false), ShortEntrySignal(false), LongExitSignal(false), ShortExitSignal(false), NumberOfShares(0), tickSize(MinMove/PriceScale), OpenOrdersAllowed(true), PriceLevel(0),SL(0), PT(0); Array: bool cond[100](false); // ================================================================= // MONEY MANAGEMENT LOGIC // ================================================================= // Money Management - Fixed Size used // ================================================================= // TRADING OPTIONS LOGIC // ================================================================= OpenOrdersAllowed = true; // Exit on close (end of day) if(ExitAtEndOfDay) then SetExitOnClose; // Exit on Friday if ExitOnFriday and DayOfWeek(Date) = 5 then SetExitOnClose; // Limit time range if(OpenOrdersAllowed = True and LimitSignalsTimeRange = True and (Time < SignalTimeRangeFrom or Time >= SignalTimeRangeTo)) then OpenOrdersAllowed = False; // Max trades per day if(OpenOrdersAllowed = True and MaxTradesPerDay <> 0 and EntriesToday(Date) >= MaxTradesPerDay) then OpenOrdersAllowed = False; // ================================================================= // TRADING RULES LOGIC // ================================================================= //------------------------------------------------------------------ // Rule: Trading signals //------------------------------------------------------------------ LongEntrySignal = ((Open[1] < SQ_BollingerBands(Close, 50, 2.1, 1)[1]) and (Open[0] > SQ_BollingerBands(Close, 50, 2.1, 1)[1])); ShortEntrySignal = ((Open[1] > SQ_BollingerBands(Close, 50, 2.1, 0)[1]) and (Open[0] < SQ_BollingerBands(Close, 50, 2.1, 0)[1])); LongExitSignal = ((SQ_StandardDeviation(TypicalPrice, 50)[3+2] > SQ_StandardDeviation(TypicalPrice, 50)[3+1]) and (SQ_StandardDeviation(TypicalPrice, 50)[3+1] < SQ_StandardDeviation(TypicalPrice, 50)[3])) and ((SQ_ADX(40, 0)[2+2] > SQ_ADX(40, 0)[2+1]) and (SQ_ADX(40, 0)[2+1] < SQ_ADX(40, 0)[2])); ShortExitSignal = ((SQ_StandardDeviation(TypicalPrice, 50)[3+2] > SQ_StandardDeviation(TypicalPrice, 50)[3+1]) and (SQ_StandardDeviation(TypicalPrice, 50)[3+1] < SQ_StandardDeviation(TypicalPrice, 50)[3])) and ((SQ_ADX(40, 0)[2+2] < SQ_ADX(40, 0)[2+1]) and (SQ_ADX(40, 0)[2+1] > SQ_ADX(40, 0)[2])); //------------------------------------------------------------------ // Rule: Long entry //------------------------------------------------------------------ if LongEntrySignal then begin // Action #1 if(OpenOrdersAllowed) then begin NumberOfShares = mmLots; Buy("LongMarket") NumberOfShares shares next bar at market; end; end; //------------------------ // Rule: Long entry - Orders Exits //------------------------ if(MarketPosition > 0) then begin // StopLoss SL = CurrentAsk - 60.0; SL = SQ_CorrectMinMaxSLPT(SL, MinimumSLPT, MaximumSLPT, true); Sell("LongSL") next bar at SL stop; // ProfitTarget PT = CurrentAsk + 150.0; PT = SQ_CorrectMinMaxSLPT(PT, MinimumSLPT, MaximumSLPT, false); Sell("LongPT") next bar at PT limit; // Move SL to BE PriceLevel = 40.0; If PriceLevel > 0 then begin If Entryprice <= PriceLevel and (SL = 0 or SL < Entryprice + 0) then begin SL = Entryprice + 0; Sell("LongSL2BE") next bar at SL stop; end; end; end; //------------------------------------------------------------------ // Rule: Short entry //------------------------------------------------------------------ if ShortEntrySignal and (not(LongEntrySignal)) then begin // Action #1 if(OpenOrdersAllowed) then begin NumberOfShares = mmLots; SellShort("ShortMarket") NumberOfShares shares next bar at market; end; end; //------------------------ // Rule: Short entry - Orders Exits //------------------------ if(MarketPosition < 0) then begin // StopLoss SL = CurrentBid + 60; SL = SQ_CorrectMinMaxSLPT(SL, MinimumSLPT, MaximumSLPT, true); BuyToCover("ShortSL") next bar at SL stop; // ProfitTarget PT = CurrentBid - 150; PT = SQ_CorrectMinMaxSLPT(PT, MinimumSLPT, MaximumSLPT, false); BuyToCover("ShortPT") next bar at PT limit; // Move SL to BE PriceLevel = 40; If PriceLevel > 0 then begin If Entryprice >= PriceLevel and (SL = 0 or SL > Entryprice - 0) then begin SL = Entryprice - 0; BuyToCover("ShortSL2BE") next bar at SL stop; end; end; end; //------------------------------------------------------------------ // Rule: Long exit //------------------------------------------------------------------ if LongExitSignal and (not(LongEntrySignal)) and (MarketPosition > 0) then begin // Action #1 Sell("ClosePositionLong") next bar at market; end; //------------------------------------------------------------------ // Rule: Short exit //------------------------------------------------------------------ if ShortExitSignal and (not(ShortEntrySignal)) and (MarketPosition < 0) then begin // Action #1 BuyToCover("ClosePositionShort") next bar at market; end;