// Downloaded From https://www.WiseStockTrader.com SetOption("InitialEquity", 1000000); SetOption("MinShares", 100); RoundLotSize = 100; SetOption("CommissionMode", 1); SetOption("CommissionAmount", 0.16); SetTradeDelays( 0, 0, 0, 0); BuyPrice = SellPrice = Close; oMA1 = 10; //Optimize( "oMA1", 9, 1, 15, 3); oMA2 = 30; //Optimize ( "oMA2", 24, 10, 50, 5); MA1 = EMA( C, oMA1); MA2 = EMA( C, oMA2); Bullish = MA1 > MA2; Bearish = MA2 <= MA1; ADXperiod = 42; ADXline = ADX(ADXperiod); maADX = MA( ADXline, 10); buyCon1 = Bullish; buyCon2 = Cross( ADXline, maADX); sellCon1 = Cross(maADX, ADXline); sellCon2 = MACD() < 0; Buy = buyCon1 AND buyCon2; Sell = sellCon1 OR sellCon2 ; Buy = ExRem(Buy, Sell); Sell = ExRem(Sell, Buy); Short = Cover = 0; MaxOpenPositions = 10; PercentPerPosition = 100/MaxOpenPositions; SetOption("MaxOpenPositions", MaxOpenPositions); SetPositionSize( PercentPerPosition, spsPercentOfEquity); PositionScore = C*V/MA(C*V, 10); //Money Management Scaling Out FirstProfitTarget = 45; //Optimize("1TP", 40, 5, 50, 5); // profit SecondProfitTarget = 60; //Optimize("2TP", 50, 5, 50, 5); // in percent TrailingStop = 40; //Optimize("Trail", 40, 25, 45, 5) ; // also in percent Stoplevel = 15; //Optimize( "Stop", 10, 5, 15, 1); ScaleOut = 30; //sell 50% of original position priceatbuy=0; highsincebuy = 0; exit = 0; for( i = 0; i < BarCount; i++ ) { if( priceatbuy == 0 AND Buy[ i ] ) { priceatbuy = BuyPrice[ i ]; } if( priceatbuy > 0 ) { highsincebuy = Max( High[ i ], highsincebuy ); if( exit == 0 AND High[ i ] >= ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy ) { // first profit target hit - scale-out exit = 1; Buy[ i ] = sigScaleOut; } if( exit == 1 AND High[ i ] >= ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy ) { // second profit target hit - exit exit = 2; SellPrice[ i ] = Max( Open[ i ], ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy ); } if( Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * highsincebuy ) { // trailing stop hit - exit exit = 3; SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 0.01 ) * highsincebuy ); } if( exit >= 2 ) { Buy[ i ] = 0; Sell[ i ] = exit + 1; // mark appropriate exit code exit = 0; priceatbuy = 0; // reset price highsincebuy = 0; } } } ApplyStop( stopTypeLoss, stopModePercent, stoplevel); SetPositionSize( 10, spsPercentOfEquity ); SetPositionSize( ScaleOut, spsPercentOfPosition * ( Buy == sigScaleOut ) );