RoundLotSize = 1;
MarginDeposit = 350;
TickSize = 0;
PointValue = 25;
SetPositionSize(4, spsShares);
_SECTION_BEGIN("Price");
// Toggle candle visibility
if (ParamToggle("Candles", "Show|Hide",0)){
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
}
_SECTION_END();
_SECTION_BEGIN("EMA Fast");
Periods1 = Param("Period Fast", 5, 2, 15, 1);
Periods1 = Optimize("Period Fast", Periods1, 2, 15, 1);
P1 = ParamField("Price field Fast", 3);
EMAFast = EMA( P1, Periods1 );
Plot( EMAFast, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("EMA Slow");
Periods2 = Param("Period Slow", 13, 10, 30, 1);
Periods2 = Optimize("Periods Slow", Periods2, 10, 30, 1);
P2 = ParamField("Price field Slow", 3);
EMASlow = EMA( P2, Periods2 );
Plot( EMASlow, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
TimeFrameSet(in5Minute*3);
expand = expandLast;
_SECTION_BEGIN("EMA Fast 15min");
Periods15 = Param("Period Fast 15min", 5, 2, 15, 1);
Periods15 = Optimize("Period Fast 15min", Periods1, 2, 15, 1);
P15 = ParamField("Price field Fast 15min", 3);
EMAFast15 = EMA( P15, Periods15 );
EMAFaste = TimeFrameExpand(EMAFast15, in5Minute*3, expand);
Plot( EMAFaste, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("EMA Slow 15min");
Periods25 = Param("Period Slow 15min", 13, 10, 30, 1);
Periods25 = Optimize("Periods Slow 15min", Periods2, 10, 30, 1);
P25 = ParamField("Price field Slow 15min", 3);
EMASlow5 = EMA( P25, Periods25 );
EMASlowe = TimeFrameExpand(EMASlow5, in5Minute*3, expand);
Plot( EMASlowe, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
TimeFrameRestore();
_SECTION_BEGIN("Trading signals");
Buy = EMAFaste>EMASlowe AND Cross(EMAFast, EMASlow);
Short = EMAFaste<EMASlowe AND Cross(EMASlow, EMAFast);
Cover = Cross(EMAFast, EMASlow);
Sell = Cross(EMASlow, EMAFast);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
BuyPrice = ValueWhen(Buy, Close);
SellPrice = ValueWhen(Sell, Close);
ShortPrice = ValueWhen(Short, Close);
CoverPrice = ValueWhen(Cover, Close);
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low, -28);
PlotShapes(Short*shapeDownArrow, colorRed, 0, High, -28);
PlotShapes(Cover*shapeHollowUpArrow, colorGreen, 0, Low, -45);
PlotShapes(Sell*shapeHollowDownArrow, colorRed, 0, High, -45);
dist = 1.5*ATR(10);
for (i=0; i<BarCount; i++) {
if (Cover[i]) {
PlotText( "\nCover short: " + CoverPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
PlotText( "\n\nProfit: " + (ShortPrice[i]-CoverPrice[i]), i+1.5, L[ i ]-dist[i]-3, colorLime);
} else if (Sell[i]) {
PlotText( "\nSell bought: " + SellPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
PlotText( "\n\nProfit: " + (SellPrice[i]-BuyPrice[i]), i+1.5, H[ i ]+dist[i]+5, colorOrange);
}
if(Buy[i]) {
PlotText( "Buy: " + BuyPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
sig = "Buy";
} else if( Short[i]) {
PlotText( "Short: " + ShortPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
sig = "Short";
}
}
_SECTION_END();
RoundLotSize = 1;
MarginDeposit = 350;
TickSize = 0;
PointValue = 25;
SetPositionSize(4, spsShares);
_SECTION_BEGIN("Price");
// Toggle candle visibility
if (ParamToggle("Candles", "Show|Hide",0)){
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
}
_SECTION_END();
_SECTION_BEGIN("EMA Fast");
Periods1 = Param("Period Fast", 5, 2, 15, 1);
Periods1 = Optimize("Period Fast", Periods1, 2, 15, 1);
P1 = ParamField("Price field Fast", 3);
EMAFast = EMA( P1, Periods1 );
Plot( EMAFast, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("EMA Slow");
Periods2 = Param("Period Slow", 13, 10, 30, 1);
Periods2 = Optimize("Periods Slow", Periods2, 10, 30, 1);
P2 = ParamField("Price field Slow", 3);
EMASlow = EMA( P2, Periods2 );
Plot( EMASlow, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
TimeFrameSet(in5Minute*3);
expand = expandLast;
_SECTION_BEGIN("EMA Fast 15min");
Periods15 = Param("Period Fast 15min", 5, 2, 15, 1);
Periods15 = Optimize("Period Fast 15min", Periods1, 2, 15, 1);
P15 = ParamField("Price field Fast 15min", 3);
EMAFast15 = EMA( P15, Periods15 );
EMAFaste = TimeFrameExpand(EMAFast15, in5Minute*3, expand);
Plot( EMAFaste, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("EMA Slow 15min");
Periods25 = Param("Period Slow 15min", 13, 10, 30, 1);
Periods25 = Optimize("Periods Slow 15min", Periods2, 10, 30, 1);
P25 = ParamField("Price field Slow 15min", 3);
EMASlow5 = EMA( P25, Periods25 );
EMASlowe = TimeFrameExpand(EMASlow5, in5Minute*3, expand);
Plot( EMASlowe, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
TimeFrameRestore();
_SECTION_BEGIN("Trading signals");
Buy = EMAFaste>EMASlowe AND Cross(EMAFast, EMASlow);
Short = EMAFaste<EMASlowe AND Cross(EMASlow, EMAFast);
Cover = Cross(EMAFast, EMASlow);
Sell = Cross(EMASlow, EMAFast);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
BuyPrice = ValueWhen(Buy, Close);
SellPrice = ValueWhen(Sell, Close);
ShortPrice = ValueWhen(Short, Close);
CoverPrice = ValueWhen(Cover, Close);
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low, -28);
PlotShapes(Short*shapeDownArrow, colorRed, 0, High, -28);
PlotShapes(Cover*shapeHollowUpArrow, colorGreen, 0, Low, -45);
PlotShapes(Sell*shapeHollowDownArrow, colorRed, 0, High, -45);
dist = 1.5*ATR(10);
for (i=0; i<BarCount; i++) {
if (Cover[i]) {
PlotText( "\nCover short: " + CoverPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
PlotText( "\n\nProfit: " + (ShortPrice[i]-CoverPrice[i]), i+1.5, L[ i ]-dist[i]-3, colorLime);
} else if (Sell[i]) {
PlotText( "\nSell bought: " + SellPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
PlotText( "\n\nProfit: " + (SellPrice[i]-BuyPrice[i]), i+1.5, H[ i ]+dist[i]+5, colorOrange);
}
if(Buy[i]) {
PlotText( "Buy: " + BuyPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
sig = "Buy";
} else if( Short[i]) {
PlotText( "Short: " + ShortPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
sig = "Short";
}
}
_SECTION_END();