Move arrows from lower study to price graph


Category:
0
0

Hi, Pete,

Hope all is well with you.

I was thinking that maybe it would be a better idea to transform this into a superior study so that the arrows can be clearly marked on the graph. But I have a problem with the graph. The sails are flattened and the signal arrows are at the bottom of the table. Do you have any ideas on how to fix this?
Code lower:

#—–Momentum
Declare lower;

input length = 12;
input price = close;
input showBreakoutSignals = no;

Assert(length > 0, “‘length’ must be positive: ” + length);

plot Momentum = price – price[length];
plot ZeroLine = 0;
plot UpSignal = if Momentum crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Momentum crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Momentum.SetDefaultColor(GetColor(1));
ZeroLine.SetDefaultColor(GetColor(0));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# Alerts
Alert( UpSignal, ” “, Alert.BAR, Sound.RING);
Alert(DownSignal, ” “, Alert.BAR, Sound.RING);

…. and the other one is the code I tried to convert to upper study.

#---Momentum_Upper

input length = 12;
input price = close;

Assert(length > 0, "'length' must be positive: " + length);

def Momentum = price - price[length];
def ZeroLine = 0;

plot UpSignal = if Momentum crosses above ZeroLine then ZeroLine else Double.NaN;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

plot DownSignal = if Momentum crosses below ZeroLine then ZeroLine else Double.NaN;
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# Alerts
Alert( UpSignal, " ", Alert.BAR, Sound.Ring);
Alert(DownSignal, " ", Alert.BAR, Sound.Ring);

Enclosed is screenshots as an example.I am waiting for your response.  Thank you!

Attachments:
Marked as spam
Posted by (Questions: 3, Answers: 2)
Asked on April 26, 2020 9:09 am
102 views
0
Private answer

In order to move this chart study to upper subgraph so that the arrows plot at the highs and lows of the candles we need to modify the two plot statements. The original plot statements checked for a crossing event and assigned the value of the zero line. Here is an example from the original:

plot UpSignal = if Momentum crosses above ZeroLine then ZeroLine else Double.NaN;

Step one is to convert that to a simple true/false statement:

plot upSignal = momentum crosses above zeroLine;

Now that we have converted this we still have one more step. Each plot statement is followed by several style statements. Here is the original line that plotted the arrow for the upSignal:

UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

Since we have converted the signal itself to a true/false statement we do the same with the style statement that plots the arrows:

upSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

Ok, that is the step-by-step explanation of what we need to do. Here is the full and complete code with those modifications applied.

input length = 12;
input price = close;
Assert(length > 0, "'length' must be positive: " + length);
def momentum = price - price[length];
def zeroLine = 0;
plot upSignal = momentum crosses above zeroLine;
upSignal.SetDefaultColor(Color.UPTICK);
upSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot downSignal = momentum crosses below zeroLine;
downSignal.SetDefaultColor(Color.DOWNTICK);
downSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
# Alerts
Alert( upSignal, " ", Alert.BAR, Sound.Ring);
Alert(downSignal, " ", Alert.BAR, Sound.Ring);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 26, 2020 9:39 am