Subject: How do I generate a conditional clear signal for an
average price?I want to have a sell signal that is conditional on the
average price of pyramided buys. The problem is, how do I clear
the total invested and total shares owned sum variables to zero only after the
conditional sell signal is generated?PurchaseAmount:=5000;
BuySignal:= Cross(C,Mov(C,20,E));
TotalInvested:= If(BuySignal,PREV+PurchaseAmount,PREV);
TotalShares:= If(BuySignal,PREV+(PurchaseAmount/C),PREV);
AvePrice:=TotalInvested/TotalShares;
SellCondition:=Cross(Mov(C,20,E),C);
SellSignal:=SellCondition AND (C>(AvePrice));
How do I clear TotalInvested and TotalShares, to 0 only if
sell signal is true?
I tried many variations following the SellSignal including;
If(SellSignal,TotalInvested=0,Ref(TotalInvested,-1));
If(SellSignal,TotalShares=0,Ref(TotalShares,-1));
I’ve also tried
If(Ref(SellSignal,-1),TotalInvested=0,Ref(TotalInvested,-1));
If(Ref(SellSignal,-1),TotalShares=0,Ref(TotalShares,-1));
And I’ve tried
If(Ref(SellSignal,-1),TotalInvested=0,
TotalInvested=Ref(TotalInvested,-1));
If(Ref(SellSignal,-1),TotalShares=0,
TotalShares=Ref(TotalShares,-1));
But I get strange results. Thanks and Happy Holidays,
|