Monkey Hammer
New member
Hello All! New to the forum. Thanks in advance if anyone can help me. I'll do this in "Long" mode understanding the reverse is applicable for "short" mode. I'm trying to indicate the first pullback price bars after a bullish trailing stop flip. I use another line I call a Bolic which is reall a trailing stop with different, quicker, settings. So, if the trailing stop flips bull, I save that state until the price flips the Bolic bear which indicates a pullback has begun. The pullback state remains until price has flipped the Bolic bullish or the trailing stop bearish. I hope that makes sense. My "long" code is below. The errors are in the **'s. Please excuse my code structure. I guess you can take the dummy out of C++ but you can't take the C++ out of the dummy!
# Define the first pullback Flip Zones
def BW; #Buy Window I get this BW in a red box
def SW; #Sell Window
def state = {default FlipCheck, Long, Short};
switch (state)
{
case FlipCheck:
if (vshort[1] > 0 and vlong > 0) #Trailing stop bull flip.
{
state = state.Long; #Buy Window possible.
}
else
{
if (vlong[1] > 0 and vshort > 0) #Trailing stop bear flip.
then
{
state = state.Short; #Sell Window possible.
}
else
{
state = state.FlipCheck; #No trailing stop flip. Keep checking.
}
}
case Long: # we have had a trailing stop flip bull
if (bshort > 0) #if bear bolic short, then pullback has started.
{
BW = 1; #Set buy window to true
}
else #if bear bolic active
{
if (bshort[1] > 0 and blong > 0 or #bear bolic has flipped to bull bolic.
vlong[1] > 0 and vshort > 0) #bull trailstop has flipped to bear.
{
BW = 0; #Cancel buy window
state = state.FlipCheck; #Start checking again for trailng stop flip
}
else
{
BW = 1; #No change. I get this BW in a red box
state = state.Long; #No change. I get this state in a red box
}
}
case Short:
if (blong > 0) #if bull bolic short, then pullback has started.
{
SW = 1; #Set sell window to true
}
else
{
if (blong[1] > 0 and blong > 0 or
vshort[1] > 0 and vlong > 0)
{
SW = 0;
state = state.FlipCheck;
}
else
{
state = state.Short; I get this BW in a red box
SW = 1; I get this state in a red box
}
}
}
plot BuyWindow = if BW == 1 then low else Double.NaN;
plot SellWindow = if SW == 1 then high else Double.NaN;
# BuyWindowSellWindow Formatting:
BuyWindow.SetDefaultColor(Color.LIGHT_GREEN);
BuyWindow.SetStyle(Curve.POINTS);
BuyWindow.SetLineWeight(5);
SellWindow.SetDefaultColor(Color.LIGHT_RED);
SellWindow.SetStyle(Curve.POINTS);
SellWindow.SetLineWeight(5);
# End Code
I have multiple "value not assigned" errors to the "state" and the "BW"
# Define the first pullback Flip Zones
def BW; #Buy Window I get this BW in a red box
def SW; #Sell Window
def state = {default FlipCheck, Long, Short};
switch (state)
{
case FlipCheck:
if (vshort[1] > 0 and vlong > 0) #Trailing stop bull flip.
{
state = state.Long; #Buy Window possible.
}
else
{
if (vlong[1] > 0 and vshort > 0) #Trailing stop bear flip.
then
{
state = state.Short; #Sell Window possible.
}
else
{
state = state.FlipCheck; #No trailing stop flip. Keep checking.
}
}
case Long: # we have had a trailing stop flip bull
if (bshort > 0) #if bear bolic short, then pullback has started.
{
BW = 1; #Set buy window to true
}
else #if bear bolic active
{
if (bshort[1] > 0 and blong > 0 or #bear bolic has flipped to bull bolic.
vlong[1] > 0 and vshort > 0) #bull trailstop has flipped to bear.
{
BW = 0; #Cancel buy window
state = state.FlipCheck; #Start checking again for trailng stop flip
}
else
{
BW = 1; #No change. I get this BW in a red box
state = state.Long; #No change. I get this state in a red box
}
}
case Short:
if (blong > 0) #if bull bolic short, then pullback has started.
{
SW = 1; #Set sell window to true
}
else
{
if (blong[1] > 0 and blong > 0 or
vshort[1] > 0 and vlong > 0)
{
SW = 0;
state = state.FlipCheck;
}
else
{
state = state.Short; I get this BW in a red box
SW = 1; I get this state in a red box
}
}
}
plot BuyWindow = if BW == 1 then low else Double.NaN;
plot SellWindow = if SW == 1 then high else Double.NaN;
# BuyWindowSellWindow Formatting:
BuyWindow.SetDefaultColor(Color.LIGHT_GREEN);
BuyWindow.SetStyle(Curve.POINTS);
BuyWindow.SetLineWeight(5);
SellWindow.SetDefaultColor(Color.LIGHT_RED);
SellWindow.SetStyle(Curve.POINTS);
SellWindow.SetLineWeight(5);
# End Code
I have multiple "value not assigned" errors to the "state" and the "BW"