I have a conceptual idea where i want to trade only when the equity curve is above 9 ema. for eg. Here is my sample strategy where i plotted the equity curve along with a 9 ema.
so i want to use this as a model. i want to run the same strategy where it enters trade when the model is above 9 ema ie when the blue line is above the green line and ignore the trades when the blue line is below green line.
How do i do the same. I want to create a new equity curve based on this model.
Existing formula i used is
Buy = Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() );
// trade on next bar open
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = SellPrice = Open;
Short=Cover=False;
SetCustomBacktestProc( "" );
// trade size: 25% of current portfolio equity
SetPositionSize( 25, spsPercentOfEquity );
if( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject(); // Get backtester object
bo.Backtest( 1 ); // run default backtest procedure
AddToComposite( bo.EquityArray,
"~~~My MACD", "X",
atcFlagDeleteValues | atcFlagEnableInPortfolio );
// iterate through closed trades first
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
mae = StaticVarGet( trade.Symbol + "mae" + DateTimeToStr( trade.EntryDateTime , 3 ) ); //risk %
trade.AddCustomMetric( "mae", mae );
}
bo.ListTrades();
}
SetForeign("~~~My MACD");
PlotForeign("~~~My MACD","My Equity",colorBlue,styleLine);
Plot( EMA(C,9), "MA of Equity", colorGreen, styleLine, Null, Null, 0 );