[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Profit target and Max loss



PureBytes Links

Trading Reference Links

Hi Igor

>Could someone help me with the same formule used by the system tester for the profit target and Max
loss...so I could put it in >the advisor for any kind of system or formule.

The following indicator, previously posted on another group, comes close to doing what you ask but
will need a little work to be adapted to your specific requirements. The critical component of this
indicator is the EntryAmt variable and I am including a slightly cut down version of the same with
explanatory comments following the indicator proper.

If you are prepared to take the time to understand how the indicator works you will be rewarded with
a useful tool that you can adapt in a number of ways. Without applying a little effort it will
remain useless gibberish.

Roy


  {Multi Stop Indicator}
  {** Set options and defaults as required **}
EntryCost:=Input("Entry cost $",0,100,0);
ExitCost:= Input(" Exit cost $",0,100,0);
Profit:=Input("Profit goal %",1,50,10)/100;
Loss:=Input("  Stop loss %"  ,1,50,5)/100;
Equity:=Input("Trade equity $",500,100000,5000);
EntryPrice:=Input("Entry price option, 1=O 2=C 3=Stop",1,3,2);
ExitOpt:=2; {Exit option,  1=O 2=C 3=Stop}
n:=Fml("Your Entry Signal");
x:=Fml("Your Exit Signal");
i:=Cum(n<>-1 AND x<>-1)=1;
EntryPrice:=If(EntryPrice=1,O,If(EntryPrice=2,C,n));
ExitPrice:=If(ExitOpt=1,O,If(ExitOpt=2,C,H));
pFactor:=((Equity*(1+Profit)+ExitCost)/ (Equity-EntryCost));
lFactor:=((Equity*(1-Loss)+ExitCost)/ (Equity-EntryCost));
EntryAmt:=If(BarsSince(i OR n>0)>=BarsSince(i OR x>0 OR
ExitPrice>pFactor*(ValueWhen(1,i OR (n>0 AND Alert(If(BarsSince(i
OR n>0)>=BarsSince(i OR x>0),0,1)=0,2)), EntryPrice)) OR If(ExitOpt<3,
ExitPrice,L)<=lFactor*(ValueWhen(1,i OR (n>0 AND Alert(If(BarsSince(i
OR n>0)>=BarsSince(i OR x>0),0,1)=0,2)), EntryPrice))),0,
ValueWhen(1,i OR (n>0 AND Alert(If(BarsSince(i OR n>0)>=
BarsSince(i OR x>0),0,1)=0,2)),EntryPrice));
y:=If(EntryAmt=0 AND Alert(EntryAmt>0,2) AND ExitPrice>=
ValueWhen(1,i OR EntryAmt>0,EntryAmt)*pFactor,If(ExitOpt=1,O,
If(ExitOpt=2,C,ValueWhen(1,i OR EntryAmt>0,EntryAmt)*pFactor)),0);
z:=If(EntryAmt=0 AND Alert(EntryAmt>0,2) AND If(ExitOpt<3,
ExitPrice,L)<ValueWhen(1,i OR EntryAmt>0,EntryAmt)*lFactor,
If(ExitOpt=1,O,If(ExitOpt=2,C,ValueWhen(1,i OR EntryAmt>0,
EntryAmt)*lFactor)),0);
pTarget:=If(Y=0,0,If(Y>0.1 AND Y<=0.5,
If(Int(Y*200)=Y*200,Y, Int((Y)*200)/200),
If(Y<=0.1,If(Int(Y*1000)=Y*1000,Y,
Int((Y)*1000)/1000),If(Int(Y*100)=Y*100,Y, Int((Y)*100)/100))));
lTarget:=If(Z=0,0,If(Z>0.1 AND Z<=0.5,
If(Int(Z*200)=Z*200,Z, Int((Z)*200)/200),
If(Z<=0.1,If(Int(Z*1000)=Z*1000,Z,
Int((Z)*1000)/1000),If(Int(Z*100)=Z*100,Z, Int((Z)*100)/100))));
EntryAmt; {EntryAmt*pFactor; EntryAmt*lFactor; }


  {**  simplified EntryAmt with comments  **}
{If bars since entry >= bars since conventional exit}
EntryAmt:=If(BarsSince(I OR N)>=BarsSince(I OR X
OR
{or if bars since entry >= bars since profit exit}
ExitPrice>=(1+Profit)*(ValueWhen(1,I OR (N AND
Alert(If(BarsSince(I OR N)>= BarsSince(I OR X),0,1)=0,2)), EntryPrice))
OR
{or if bars since entry >= bars since loss exit}
ExitPrice<=(1-Loss)*(ValueWhen(1,I OR (N AND
Alert(If(BarsSince(I OR N)>=BarsSince(I OR X),0,1)=0,2)), EntryPrice))),
{then flag value is 0}
0,
{else flag value = entry price when entry is true and flag =0 on previous bar}
ValueWhen(1,I OR (N AND Alert(If(BarsSince(I OR N)>=
BarsSince(I OR X),0,1)=0,2)),EntryPrice));