wavefollower

following the wave and trading happy
正文

new study

(2023-05-17 11:26:42) 下一個

declare lower;


input length1 = 6;
input length2 = 12;
input over_Bought = 70;
input over_Sold = 30;
input over_Bought2 = 91;
input over_Sold2 = 9;
input deter = 50;
input price = close;
input averageType = AverageType.WILDERS;

def NetChgAvg1 = MovingAverage(averageType, price - price[1], length1);
def TotChgAvg1 = MovingAverage(averageType, AbsValue(price - price[1]), length1);
def ChgRatio1 = if TotChgAvg1 != 0 then NetChgAvg1 / TotChgAvg1 else 0;


def NetChgAvg2 = MovingAverage(averageType, price - price[1], length2);
def TotChgAvg2 = MovingAverage(averageType, AbsValue(price - price[1]), length2);
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;

plot RSI1 = 50 * (ChgRatio1 + 1);
plot RSI2 = 50 * (ChgRatio2 + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot OverSold2 = over_Sold2;
plot OverBought2 = over_Bought2;
plot AVG = deter;

RSI1.DefineColor("Normal1", GetColor(5));
RSI2.DefineColor("Normal2", GetColor(2));
OverSold.SetDefaultColor(GetColor(7));
OverBought.SetDefaultColor(GetColor(7));
OverSold2.SetDefaultColor(GetColor(16));
OverBought2.SetDefaultColor(GetColor(5));
AVG.SetDefaultColor(GetColor(4));

#END  of Code

----------------------------------------

## Author: MZ 

input fastLength = 9;
input slowLength = 31;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

def Value = MACD(fastLength, slowLength, MACDLength, averageType).Value;
def Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;

def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
#def UpSignal = if Diff crosses above 0 then 0 else Double.NaN;
#def DownSignal = if Diff crosses below 0 then 0 else Double.NaN;

input price = close;
input fastAvgLength = 3;
input slowAvgLength = 8;
input displace = 0;
input averageAVGType = AverageType.EXPONENTIAL;

def fastAvg = MovingAverage(averageAVGType, price[-displace], fastAvgLength);
def slowAvg = MovingAverage(averageAVGType, price[-displace], slowAvgLength);
def UpMove = 1;

plot UpsignalStrong = if (fastAvg > slowAvg) and (Value > Avg) and (diff > diff[1]) and Value > 0 then UpMove else Double.NaN;
plot UpsignalWeak = if (fastAvg > slowAvg) and (Value > Avg) and (Value < 0 or diff < diff[1])then UpMove else Double.NaN;
plot DownsignalStrong = if (fastAvg < slowAvg) and (Value < Avg) and (diff < diff[1]) and Value < 0 then UpMove else Double.NaN;
plot DownsignalWeak = if (fastAvg < slowAvg) and (Value < Avg) and (Value > 0 or diff > diff[1]) then UpMove else Double.NaN;

UpsignalStrong.DefineColor("Negative to Positive", GetColor(3));
#signal.DefineColor("Positive to Negative", GetColor(4));
#signal.AssignValueColor(if crossingType == CrossingType."Negative to Positive" then #signal.color("Negative to Positive") else signal.color("Positive to Negative"));
#signal.SetPaintingStrategy(if signal > 0
#    then PaintingStrategy.BOOLEAN_ARROW_UP
#    else PaintingStrategy.BOOLEAN_ARROW_DOWN);

--------------------------------------------

## START STUDY
## Chandelier_Stops
## linus, 2014-07-18, v0.2

#hint: thinkScript adaptation of Chandelier stops.

#hint n: lookback length for highest highs, lowest lows.
input n = 15;

#hint atrLength: Period length of avg. true range.

#hint atrMult: Multiplier of avg. true range.
input atrMult = 3.0;  

#hint atrType: Moving average type of ATR.
input atrType = AverageType.WILDERS;

#hint shift: Offsets the data this many bars.
input shift = 1; 

#hint hideOppositeStop: Set to No to see the inactive stop.
input hideOppositeStop = Yes; 

#hint label: Toggles P/L label.
input label = Yes;

#hint bubbles: Toggles P/L bubbles.
input bubbles = Yes;

input price = close;
input fastLength = 23;
input slowLength = 59;
input displace = 0;
input averageType = AverageType.EXPONENTIAL;

def fastAvg = MovingAverage(averageType, price[-displace], fastLength);
def slowAvg = MovingAverage(averageType, price[-displace], slowLength);

input AtrPeriod = 12;

def TrueAtr = MovingAverage(atrType, TrueRange(high, close, low), AtrPeriod);
def atr = TrueAtr * atrMult;

def smax = Lowest(low, n)[shift] + atr[shift];
def smin = Highest(high, n)[shift] - atr[shift];

def dir = CompoundValue(1, if close > smax[1] then 1 else if close < smin[1] then -1 else dir[1], 0);

def rUB = CompoundValue(1, if dir > 0 then if smax > rUB[1] then smax else rUB[1] else if dir < 0 then if smax < rUB[1] then smax else rUB[1] else rUB[1], high);

def rLB = CompoundValue(1, if dir < 0 then if smin < rLB[1] then smin else rLB[1] else if dir > 0 then if smin > rLB[1] then smin else rLB[1] else rLB[1], low);

input chanderAdj = 0.8;

plot UB = if (!hideOppositeStop or dir < 0) and (slowAvg - fastAvg) > -chanderAdj * TrueAtr   then rUB else Double.NaN;
plot LB = if (!hideOppositeStop or dir > 0) and (fastAvg - slowAvg) > -chanderAdj * TrueAtr then rLB else Double.NaN;

def rUB1 = rUB;
def rLB1 = rLB;

plot subUB = if (!hideOppositeStop or dir < 0) and (fastAvg - slowAvg) > chanderAdj * TrueAtr then rUB1 else Double.NaN;
plot subLB = if (!hideOppositeStop or dir > 0) and (slowAvg - fastAvg) > chanderAdj * TrueAtr then rLB1 else Double.NaN;

UB.SetDefaultColor(Color.MAGENTA);
LB.SetDefaultColor(Color.CYAN);

UB.SetLineWeight(3);
LB.SetLineWeight(3);

subUB.SetDefaultColor(Color.WHITE);
subLB.SetDefaultColor(Color.WHITE);

subUB.SetLineWeight(2);
subLB.SetLineWeight(2);

def orderDir = dir;

def isOrder = orderDir crosses 0;

def orderCount = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder then orderCount[1] + 1 else orderCount[1], 0);

def noBar = IsNaN(open[-1]);

def orderPrice = if isOrder then if noBar then close else open[-1] else orderPrice[1];
def profitLoss = if !isOrder or orderCount == 1 then 0 else if orderDir > 0 then orderPrice[1] - orderPrice else if orderDir < 0 then orderPrice - orderPrice[1] else 0;
def profitLossSum = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0);

AddLabel(label, orderCount + " orders | P/L " + AsDollars((profitLossSum / TickSize()) * TickValue()), if profitLossSum > 0 then Color.GREEN else if profitLossSum < 0 then Color.RED else Color.GRAY);

AddChartBubble(bubbles and isOrder and orderDir > 0, low, profitLoss, if noBar then Color.LIGHT_GRAY else Color.GREEN, 0);
AddChartBubble(bubbles and isOrder and orderDir < 0, high, profitLoss, if noBar then Color.GRAY else Color.RED, 1);

## END STUDY

 

[ 打印 ]
閱讀 ()評論 (0)
評論
目前還沒有任何評論
登錄後才可評論.