I want to use this formula from an indicator but the pr,choose,and multi1 to be Optimizer Variables and the Output from my Indicator to be the Ema. I hope someone can help me.
pr:=Input("ZigZag cycle reversal %",0,100,5);
choose:=Input("EMA periods based on: [1]Cycle, [2]Cycle Avg",1,2,1);
multi1:=Input("EMA periodicity: Cycle/Avg length x",.1,100,2);
x:=C;
zz:=Zig(x,pr,%);
zzpk:=Ref(zz,-1)>zz AND Ref(zz,-1)>Ref(zz,-2);
zztr:=Ref(zz,-1)<zz AND Ref(zz,-1)<ref(zz,-2);
PkTr:=zzpk OR zztr;
CycleLen:=PkTr*(Ref(BarsSince(PkTr),-1)+1);
CycleCount:=Cum(PkTr)-1;
CycleCount:=If(CycleCount=0,.000001,CycleCount);
CycleLenAvg:=Cum(CycleLen)/CycleCount;
pds:=If(choose=1,ValueWhen(1,CycleLen>0 AND CycleCount>0,CycleLen),CycleLenAvg)*multi1;
Init:=CycleCount=1 AND Alert(CycleCount<1,2);
pds:= If(pds>BarsSince(Init),BarsSince(Init),pds);
pds:=If(pds<1,1,pds);
Ema:=x*2/(pds+1)+PREV*(1-2/(pds+1));
Ema;