Backtester and equitiy curve

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 );

Here is the updated code. I dunno if this makes sense and could use some advice.


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 );

    

    bo.ListTrades();

}
SetForeign("~~~My MACD");
PlotForeign("~~~My MACD","My Equity",colorBlue,styleLine);
 Plot( mymacd=EMA(C,9), "MA of Equity",  colorGreen, styleLine, Null, Null, 0 );
 Pass = IIf(C>mymacd,1,0);
 RestorePriceArrays();
 



Buy = Buy AND Pass;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

e1 = Equity();
Plot(e1,"FilteredEquity",colororange,styleLine|styleLeftAxisScale,15000,18000);

Howard Bandy has written a code for this which is freely available. You can find it on his site.

Note that the idea itself doesn't often work very well. Using an index filter or composite indicator filter seems to be better.