That is:
After attain profit target, calculate the loss of closed position(after attain the target) and open position profit.
Then use the average value per contract as the filter.
The code can run correctly on TS, but it can't on MC, and I try several days but it still can't work...
Code: Select all
inputs:
Per_PL_Min_TARG( numericsimple );
variables:
Closedpositionprofit( 0 ),//only consider when currentcontracts != 0
Closedpositionprofit_pre( 0 ),//only consider when currentcontracts != 0
Closedbarloss( 0 ),//only consider when currentcontracts != 0
value_currentcontract( 0 ),
Cl_grossloss_AfterTARG( 0 ),//only consider when currentcontracts != 0
Closedbarlosscontracts( 0 ),
Cl_losscontracts_AfterTARG( 0 ),//only consider when currentcontracts != 0
ProfitTargetAttain( false );
Closedpositionprofit = positionprofit - openpositionprofit;
Closedpositionprofit_pre = positionprofit[1] - openpositionprofit[1];
value_currentcontract = currentcontracts;
If Closedpositionprofit - Closedpositionprofit_pre > 0.1
Then ProfitTargetAttain = true;
If currentcontracts = 0
Then Begin
ProfitTargetAttain = False;
Closedbarloss = 0;
Closedbarlosscontracts = 0;
Cl_grossloss_AfterTARG = 0;
Cl_losscontracts_AfterTARG = 0;
end;
If Closedpositionprofit[ 0 ] - Closedpositionprofit[ 1 ] < -0.1
Then Begin
Closedbarloss = Closedpositionprofit[ 0 ] - Closedpositionprofit[ 1 ];
Closedbarlosscontracts = currentcontracts[ 1 ] - currentcontracts[ 0 ]; //This is true if profit rarget is greater than or equal to stop loss and # of max. contracts hold is 3.
End
Else Begin
Closedbarloss = 0;
Closedbarlosscontracts = 0;
End;
If ProfitTargetAttain = True
Then
Begin
Cl_grossloss_AfterTARG = Cl_grossloss_AfterTARG + Closedbarloss;
Cl_losscontracts_AfterTARG = Cl_losscontracts_AfterTARG + Closedbarlosscontracts;
{if Cl_losscontracts_AfterTARG + Currentcontracts > 0 then}
_Filter_Per_PL_TARG = IFFLogic( ( {Cl_grossloss_AfterTARG +} Openpositionprofit ) / ( {Cl_losscontracts_AfterTARG +} Currentcontracts ) > Per_PL_Min_TARG, True, False );
End
Else _Filter_Per_PL_TARG = True;
I think it is but it can't work correctly. It seems ProfitTargetAttain = true will lag for several bars...
2.Is Closedpositionprofit[0]-Closedpositionprofit[1] the closed position profit on the last bar?
it always implies ProfitTargetAttain = true
I also try positionprofit[0] - openpositionprofit[0] - ( positionprofit[1] - openpositionprofit[1] ),
it always implies ProfitTargetAttain = false
Does any one know how to calculate closed position profit/closed position profit on the last bar on MC?
the codes work correctly on TS is as following:
Code: Select all
inputs:
Per_PL_Min_TARG( numericsimple );
variables:
Closedpositionprofit( 0 ),//only consider when currentcontracts != 0
Closedbarloss( 0 ),//only consider when currentcontracts != 0
Closedpositiongrossloss_AfterTARG( 0 ),//only consider when currentcontracts != 0
value_currentcontracts( 0 ),
Closedbarlosscontracts( 0 ),
Closedpositionlosscontracts_AfterTARG( 0 ),//only consider when currentcontracts != 0
ProfitTargetAttain( false );
value_currentcontracts = Currentcontracts;
Closedpositionprofit = Positionprofit - Openpositionprofit;
If Closedpositionprofit[ 0 ] - Closedpositionprofit[ 1 ] > 0.1
Then ProfitTargetAttain = True;
If currentcontracts = 0
Then Begin
ProfitTargetAttain = False;
Closedpositiongrossloss_AfterTARG = 0;
Closedpositionlosscontracts_AfterTARG = 0;
end;
If Closedpositionprofit[ 0 ] - Closedpositionprofit[ 1 ] < -0.1
Then Begin
Closedbarloss = Closedpositionprofit[ 0 ] - Closedpositionprofit[ 1 ];
Closedbarlosscontracts = value_currentcontracts[ 1 ] - value_currentcontracts[ 0 ]; //This is true if profit rarget is greater than stop loss and # of max. contracts hold is 3.
End
Else Begin
Closedbarloss = 0;
Closedbarlosscontracts = 0;
End;
If ProfitTargetAttain = True
Then Begin
Closedpositiongrossloss_AfterTARG = Closedpositiongrossloss_AfterTARG + Closedbarloss;
Closedpositionlosscontracts_AfterTARG = Closedpositionlosscontracts_AfterTARG + Closedbarlosscontracts;
_Filter_Per_PL_TARG = IFFLogic( ( Closedpositiongrossloss_AfterTARG + Openpositionprofit ) / ( Closedpositionlosscontracts_AfterTARG + Currentcontracts ) > Per_PL_Min_TARG, True, False );
End
Else _Filter_Per_PL_TARG = True;