So if the Equity > its Avg then trade, if not don’t trade. Of course I’m talking about using a virtual Equity curve i.e. the Equity curve the system would generate if it was allowed to operate always.
The strategy is applied on 1 instrument only(for the moment).
These my first attempts (calc 1 to 6) which don't work properly.
Any suggestion?
Code: Select all
Inputs: Calc(1),PortfolioPctStop(1);
Vars: Eq(0),EqAvg(0);
var: need_convert(false), equity(0);
Eq=NetProfit{+OpenPositionProfit}{+InitalCapital};
EqAvg=Average(Eq,20);
If Calc=1 and BarNumber>20 and MP=0 then begin
If Eq[1]>=EqAvg[1] and Eq<EqAvg then pmms_strategies_pause_all(){pmms_strategy_pause(idx)};
If Eq[1]<EqAvg[1] and Eq>=EqAvg then pmms_strategies_resume_all(){pmms_strategy_resume(idx)};
End;
If Calc=2 and BarNumber>20 then begin
If Eq[1]>=EqAvg[1] and Eq<EqAvg then begin
pmms_strategies_pause_all(){pmms_strategy_pause(idx)};
pmms_strategy_close_position(0);
End;
If Eq[1]<EqAvg[1] and Eq>=EqAvg then pmms_strategies_resume_all(){pmms_strategy_resume(idx)};
End;
If Calc=3 and BarNumber>20 then begin
{pmm_set_my_named_num(var_name, val) ?set the numerical value ?val?for var_name variable}
If Eq[1]>=EqAvg[1] and Eq<EqAvg then begin
pmms_strategy_pause(0);
pmms_strategy_close_position(0);
End;
If Eq[1]<EqAvg[1] and Eq>=EqAvg then pmms_strategy_resume(0);
End;
If Calc=4 then begin
equity = Portfolio_Equity;
if (SymbolCurrencyCode <> portfolio_CurrencyCode) then
equity = convert_currency( datetime, portfolio_CurrencyCode, SymbolCurrencyCode, equity);
setstopposition;
setstoploss(0.01 * equity);
End;
If Calc=5 then begin
equity = Portfolio_Equity;
SetStopPosition;
SetStopLoss((PortfolioPctStop/100) * equity) ;
End;
If Calc=6 then begin
equity = NetProfit;
SetStopPosition;
SetStopLoss((PortfolioPctStop/100) * equity) ;
End;