Code and it debug output below
The variable SellLast should have a value of 1.0 when MACDslope < 0 and and MACDslope < ref(MACDslope,-1). All values are for lastvalue.
The debug printout red lines have the correct value of 1.0 for SellLast. The Blue lines also have the value of 1.0 but are incorrect.
In addtition, lines that are not highlighted and have a value of 0.0 for SellLast also have random errors of value.
//Develop Trading Criteria
EMA1 = EMA( price, 12 );
EMA2 = EMA( price, 26 );
MACD1 = EMA1 - EMA2;
MACDslope = MACD1 - ref( MACD1, -1 );
MACD_Bullaccelerate = ref( MACDslope, -1 ) > 0 and MACDslope > ref( MACDslope, -1 );
MACD_Bearaccelerate = ref( MACDslope, -1 ) < 0 and MACDslope < ref( MACDslope, -1 );
//
MA20 = MA( price, 20 );
MA20slope = MA20 - ref( MA20, -1 );
//
// Buy / Sell critetia
BuyLast = MACD_Bullaccelerate and MA20slope > ref( MA20slope,-1);
SellLast = lastvalue(MA20slope) < 0 and Lastvalue(MA20slope) < lastvalue(ref( MA20slope, -1 ));
//_trace( "tradedata-A5 MD - TF: " + writeval( TF, 1.0 ) + " min. Sym " + sym + " Buy: " + writeval( buyLast, 1.1 ) + " price " + writeval( price, 1.2 ) + " MDbull " + writeval( MACD_Bullaccelerate, 1.1 ));
_trace( "tradedata-A6 MD - TF: " + writeval( TF, 1.0 ) + " min. Sym " + sym + " SellLast " + writeval( SellLast, 1.1 ) + " MACDslope[1] " + writeval( lastvalue(ref(MACDslope,-1), 1.1 ))
+ " MACDslope " + writeval( LAstvalue(MACDslope), 1.1 ) );
Appreciate your feedback
