#StepMA_PriceChannel - BLT 20170013
#Step_MovingAverage - adapted from prorealcode
script stepscript {
input steptype = { default ATR, Fixed};
input fixed_step = .05;
input stepma_finetuner = 0.5;#hint stepma_finetuner: 0.0 - 1.00; lower the value then closer stepma is to price
input stepaveragetype = AverageType.SIMPLE;
input stepavg_length = 8;
input stepprice = close;
input stepatraveragetype = AverageType.WILDERS;
input stepatrlength = 14;
input stepatrfactor = 1.0;
def step;
switch (steptype){
case Fixed:
step = fixed_step;
case ATR:
step = ATR(stepatrlength, stepatraveragetype) * stepatrfactor;
}
def MA = MovingAverage(stepaveragetype, stepprice, stepavg_length)[1];
def ssMA = if (MA > ssMA[1] + step * stepma_finetuner)
then MA
else if (MA < ssMA[1] - step * stepma_finetuner)
then MA
else ssMA[1];
plot stepma = ssMA;
}
input steptype_ = {ATR, default Fixed};
input fixed_step_ = .1;
input stepma_finetuner_ = 0.3;#hint stepma_finetuner_: 0.0 - 1.00; lower then value then closer stepma is to price
Assert(Between(stepma_finetuner_, 0.0, 1.00), "fine tuner must be between 0.0 - 1.00");
input stepaveragetype_ = AverageType.EXPONENTIAL;
input stepavg_length_ = 5;
input stepprice_ = ohlc4;
input stepmaatraveragetype_ = AverageType.WILDERS;
input stepmaatrlength_ = 7;
input stepatrfactor_ = 1.0;
plot stepma_ = stepscript(steptype_, fixed_step_, stepma_finetuner_, stepaveragetype_, stepavg_length_ , stepprice_, stepmaatraveragetype_, stepmaatrlength_, stepatrfactor_);
stepma_.DefineColor("UP", Color.YELLOW);
stepma_.DefineColor("DOWN", Color.BLACK);
def up;
up = if up[1] == 0 and stepma_ > stepma_[1] then 1 #used without HA Smoothed as price
else if up[1] == 1 and stepma_ >= stepma_[1] then 1
else 0;
stepma_.AssignValueColor(if up then stepma_.Color("UP") else stepma_.Color("DOWN"));
stepma_.HideBubble();
stepma_.SetLineWeight(3);
def stephigh = stepscript(steptype_, fixed_step_, stepma_finetuner_, stepaveragetype_, stepavg_length_ , high, stepmaatraveragetype_, stepmaatrlength_);
def steplow = stepscript(steptype_, fixed_step_, stepma_finetuner_, stepaveragetype_, stepavg_length_ , low, stepmaatraveragetype_, stepmaatrlength_);