Hi all,
I got three exit codes which is included in a for loop as below:
for (t = 1; t < BarCount-1;t++){
if(t>1){
If(
Close[t-1] >EL200[t-1]
) {
Buy[t]=1;
}
If(
EL10[t-1] < EL20[t-1] AND
EL10[t-1]<EL50[T-1] AND
Close[t] < EL10[t-1]-0.2*ATR_20 [t-1]
){
Short[t]=1;
}
If(
EL20[t-1] < EL10[t-1] AND
EL20[t-1]<EL50[T-1] AND
Close[t] < EL20[t-1]-0.2*ATR_20 [t-1]
){
Short[t]=1;
}
If(
EL50[t-1] < EL10[t-1] AND
EL50[t-1]<EL20[T-1] AND
Close[t] < EL50[t-1]-0.2*ATR_20 [t-1]
){
Short[t]=1;
}
Backtesting results are fine.
According to @tomasz by post Different exits - #3 by Tomasz, I try code --- Sell 1, Sell 2 and Sell 3 out of the for Loop. Below are the modified code:
Buy1 = Ref(Close,-1) >Ref(EL200,-1) ;
Sell1= Ref(EL10,-1) < Ref(EL20,-1) AND
Ref(EL10,-1)< Ref(EL50,-1) AND
Close < Ref(EL10,-1)-0.2*Ref(ATR_20,-1) ;
Sell2= Ref(EL20,-1) <Ref(EL10,-1) AND
Ref(EL20,-1) <Ref(EL50,-1) AND
Close < Ref(EL20,-1)-0.2*Ref(ATR_20,-1) ;
Sell3= Ref(EL50,-1) < Ref(EL10,-1) AND
Ref(EL50,-1) < Ref(EL20,-1) AND
Close < Ref(EL50,-1)-0.2*Ref(ATR_20,-1) ;
Buy = 0;
Sell = 0;
InTrade = 0;
for( i = 0; i < BarCount; i++ )
{
switch( InTrade )
{
case 0: // not in trade
if( Buy1[ i ] )
InTrade = Buy[ i ] = 1;
break;
case 1:
if( Sell1[ i ] )
{
Sell[ i ] = InTrade;
InTrade = 0;
}
break;
case 2:
if( Sell2[ i ] )
{
Sell[ i ] = InTrade;
InTrade = 0;
}
break;
case 3:
if( Sell3[ i ] )
{
Sell[ i ] = InTrade;
InTrade = 0;
}
break;
}
}
Are there any method that can identify if the sell trades are based on Sell1 , Sell2 or Sell3? is CBT required?
By the way, the backtest results of two methods are totally different. Do I code in a wrong way?
Thanks.