Hi ab-ami,
Thank you very much for the reply!
That was helpful in that it lets me know I don't need to learn how to use loops, but I still haven't solved my goal.
I have the two variables I need in arrays (initial stop, trailing stop) as well as a third variable which contains the one I want currently (active stop). What I'm still struggling with is how to keep that variable from decreasing.
I've tried using Highest, Max, and Ref to make it work but am still not successful. Is there a way to keep a variable from decreasing?
//Regime Filter
FilterMALength = 10;//Optimize ( "filterMALength", 20, 10, 400, 10);
Index = Foreign("$SP", "C", True);
FilterMA = MA (Index, FilterMALength);
IndexClose = Foreign("SP", "C", True);
FilterPass = IIf (FilterMA <= Foreign("$SP", "C", True), 1, 0);
//Entry
Cond1=FilterPass;
RateOfChange=ROC (C,20);
Cond3=IIf (RateOfChange >= 10, 1,0);
//Exit
//Inital Stop
InitialStop=H*0.6;
//Trailing Stop
TrailingStop=H*0.9;
ActiveStop=Iif(FilterPass*H*.9 > H*.6, InitialStop,TrailingStop);
// unsuccessful attempts
OldStop=Iif(FilterPass*HHV(C,-1)*.9 > HHV(C,-1)*.6, InitialStop,TrailingStop);
LastWeek=TimeFrameGetPrice("H",inWeekly,-1);
ThisWeek=H;
OldInitialStop=LastWeek*0.6;
OldTrailingStop=LastWeek*0.9;
OldActiveStop=Iif(FilterPass*LastWeek*.9 > LastWeek*.6, OldInitialStop,OldTrailingStop);
Try1=Iif(FilterPass*TimeFrameGetPrice("H",inWeekly,-1)*.9 > TimeFrameGetPrice("H",inWeekly,-1)*.6, OldInitialStop,OldTrailingStop);
GreaterStop=OldActiveStop-ActiveStop;
highervar=Highest(activestop);
Currentstop=ActiveStop+GreaterStop;
Ratchetstop=Highest(ActiveStop);
RatchetInitial=Highest(InitialStop);
RatchetTrailing=Highest(TrailingStop);
maxstop=Max(activestop,oldactivestop);
MaxInitialStop=Max(initialStop,OldInitialStop);
HighestMaxInitialStop=Highest(MaxInitialStop);
RefInitialStop=Ref(InitialStop,-1);
MaxRefInitialStop=Max(InitialStop,RefInitialStop);
RefActiveStop=Ref(ActiveStop,-1);
MaxRefActiveStop=Max(ActiveStop,RefActiveStop);
RefMaxRefActiveStop=Ref(MaxRefActiveStop,-1);
MaxRefMaxRefActiveStop=Max(RefMaxRefActiveStop,MaxRefActiveStop);
MaxActiveStop=Max(ActiveStop,MaxRefActiveStop);
Whatif=Max(ActiveStop,Ref(ActiveStop,-1));
FrozenStop =ApplyStop(stopTypeTrailing, stopModePercent, 15, True, True );
// Buy and Sell rules
Buy = Cond1 AND Cond3;
//Sell = InitialStop OR TrailingStop;
//Sell = Cross (C, ActiveStop);
Sell = (C<=ActiveStop);
Try2=HighestSince(Buy,activestop,2);
// use Explore to create a table
Filter = 1;
//AddColumn (mySignal, "signal", 1.0);
//AddColumn (FilterPass, "FilterPass", 1.0);
//AddColumn (FilterMA, "FilterMA", 1.0);
//AddColumn (Index, "IndexClose", 1.0);
AddColumn (Close, "Close", 1.2);
//AddColumn (Cond1, "Cond1 Regime Filter", 1.0);
//AddColumn (RateOfChange, "Rate of Change", 1.0);
//AddColumn (Cond3, "Cond3 Rate of Change", 1.0);
AddColumn (InitialStop, "Initial Stop", 1.0);
//AddColumn (RatchetInitial, "RatchetInitial", 1.0);
//AddColumn (OldInitialStop, "Old Initial Stop", 1.0);
//AddColumn (MaxInitialStop, "MaxInitialStop", 1.0);
//AddColumn (HighestMaxInitialStop, "HighestMaxInitialStop", 1.0);
//AddColumn (RefInitialStop, "RefInitialStop", 1.0);
//AddColumn (MaxRefInitialStop, "MaxRefInitialStop", 1.0);
AddColumn (TrailingStop, "Trailing Stop", 1.0);
//AddColumn (RatchetTrailing, "RatchetTrailing", 1.0);
//AddColumn (OldTrailingStop, " OldTrailing Stop", 1.0);
//AddColumn (FrozenStop, "FrozenStop", 1.0);
AddColumn (ActiveStop, "Active Stop", 1.0);
AddColumn (RefActiveStop, "RefActiveStop", 1.0);
AddColumn (MaxRefActiveStop, "MaxRefActiveStop", 1.0);
AddColumn (MaxActiveStop, "MaxActiveStop", 1.0);
AddColumn (RefMaxRefActiveStop, "RefMaxRefActiveStop", 1.0);
AddColumn (MaxRefMaxRefActiveStop, "MaxRefMaxRefActiveStop", 1.0);
AddColumn (whatif, "whatif",1.0);
//addColumn (StatStop, "StatStop", 1.0);
AddColumn (RatchetStop, "RatchetStop", 1.0);
AddColumn (OldActiveStop, "Old Active Stop", 1.0);
AddColumn (maxstop, "maxstop", 1.0);
AddColumn (Try1, "Try1", 1.0);
//AddColumn (StaticStop, "StaticStop", 1.0);
AddColumn (OldStop, "OldStop", 1.0);
AddColumn (GreaterStop, "GreaterStop", 1.0);
AddColumn (CurrentStop, "CurrentStop", 1.0);
AddColumn (HigherVar, "HigherVar", 1.0);
AddColumn (RatchetStop, "RatchetStop", 1.0);
//AddColumn (try2, "try2", 1.0);
Here is a picture of the explore output with the table. You can see I highlighted where my active stop first decreases in value. I'm just not certain what logic or command I need to use to keep it from decreasing as time passes.
