// Downloaded From https://www.WiseStockTrader.com
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
TimeFrameSet( in5Minute ); // switch to 5 minute frame
 
/* MA now operates on 5 minute data, ma5_13 holds time-compressed 13 bar MA of 5min bars */
 
//ma5_13 = MA( C, 13 );
 
TimeFrameRestore(); // restore time frame to original
 
TimeFrameSet( inHourly ); // switch now to hourly
 
mah_9 = EMA( C, 9 ); // 9 bar moving average from hourly data
 
TimeFrameRestore(); // restore time frame to original
TimeFrameRestore(); // restore time frame to original
 
 
//TimeFrameSet( inDaily ); // switch now to hourly
 
Plot( Close, "Price", colorWhite, styleCandle );
 
// plot expanded average
 
//Plot( TimeFrameExpand( ma5_13, in5Minute), "13 bar moving average from 5 min bars", colorRed );
Plot( TimeFrameExpand( mah_9, inHourly), "9 bar moving average from hourly bars", colorBlue );
 
Plot( TimeFrameExpand( mah_9, inDaily), "9 bar moving average from daily bars", colorGreen );
cond1 = Close > Ref( Close, -1 );
Cond2 = High < Ref( High, -1 ) AND Low > Ref( Low, -1 );
Cond3 = Close < Ref( Close, -1 );
 
SetTradeDelays( 1, 1, 1, 1 );
 
Buy = Cond1 AND Ref( Cond2, -1 ) AND Ref( Cond1, -2 );
BuyPrice = Open;
Short = Cond3 AND Ref( Cond2, -1 ) AND Ref( Cond3, -2 );
ShortPrice = Open;
 
Sell = Cover = False; // exits only by stops
 
// profit target being higher than loss gives better result
// than proposed in article equal to 0.75%
Target = 6.5;
Loss = 0.75; // 0.75% max loss stop;
 
SetOption("InitialEquity", 30000 );
 
ApplyStop( stopTypeLoss, stopModePercent, Loss, True );
ApplyStop( stopTypeProfit, stopModePercent, Target, True );
 
SetOption("ActivateStopsImmediately", False ); // activate stops next bar
SetPositionSize( 1, spsShares );
PointValue = 1000; // big point value NYMEX CL
MarginDeposit = 5063; // overnight margin NYMEX CL