Could I get some help plotting this please

Questions about MultiCharts and user contributed studies.
shortski
Posts: 27
Joined: 21 May 2008

Could I get some help plotting this please

Postby shortski » 22 Jan 2009

I am just trying to get a basic +1/-1 histogram up to reflect when 2 indicators are both showing positive or negative values. The code looks good to me and compiles but doesn't show up anything on the chart. Ideas?

vars:

value1(0),
value2(0);

value1 = $rtOscillatorDivergence(high,low,GordoMACDDiff(close,12,26),1.0);
value2 = ThreeLineBreak;

If
value1 > 0 and value2 > 0 then begin
Plot1(1,"Buy",green);
end
else If
value1 < 0 and value2 < 0 then begin
Plot1(-1,"Sell",red);
end
else
NoPlot(1);

if(value1 > 0 and value2 > 0) then Green

else if(value1 < 0 and value2 < 0) then Red

Thanks

Shortski

User avatar
TJ
Posts: 6572
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1902 times

Postby TJ » 22 Jan 2009

do you know the value of value1 and value2?

they are pretty complicated functions. Do you know if they are returning any useable data?
if both conditions were not met, then you won't have any plot at all.

you can debug this by adding a plot3 and plot4:

plot3(value1, "value1");
plot4(value2, "value2");

then you will know if you are actually getting any returns from those function calls.

the plot code itself looks ok.

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 22 Jan 2009

I don't have your functions , so I replaced them with a simple oscillator. It seems to work. See image attached.
if, when you plug in your functions it stops working, the problem is with the functions. If you post them , I'll insert them and check it out.

vars:

value1(0),
value2(0);

value1 = average(H,10)-average(H,50); {$rtOscillatorDivergence(high,low,GordoMACDDiff(close,12,26),1.0);}
value2 = average(L,10)-average(L,50);{ThreeLineBreak;}

If
value1 > 0 and value2 > 0 then begin
Plot1(1,"Buy",green);
end
else If
value1 < 0 and value2 < 0 then begin
Plot1(-1,"Sell",red);
end
else
NoPlot(1);
Attachments
Candlesticks painted2.png
Candlesticks painted2.png (59.2 KiB) Viewed 239 times

shortski
Posts: 27
Joined: 21 May 2008

Postby shortski » 22 Jan 2009

Yes both functions/indicators are giving me results on the chart so both are working. That is how I can see that the code I am inputting for combining them isn't working. The second response is interesting in that by simply changing the indicators, you get results. I will have to look at that and see if it is just the inputs.

Thanks

S

User avatar
TJ
Posts: 6572
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1902 times

Postby TJ » 23 Jan 2009

you should add a catch-all at the end for the following conditions:

value1 > 0 and value2 <0,

or

value1 < 0 and value2 >0,




Code: Select all

vars:

value1(0),
value2(0);

value1 = average(H,10)-average(H,50); {$rtOscillatorDivergence(high,low,GordoMACDDiff(close,12,26),1.0);}
value2 = average(L,10)-average(L,50);{ThreeLineBreak;}

If
value1 > 0 and value2 > 0 then begin
Plot1(1,"Buy",green);
end
else If
value1 < 0 and value2 < 0 then begin
Plot1(-1,"Sell",red);
end


else
Plot1(0,"neither",blue); { <--- add this }





p.s. in the Format Study, make sure you define the plot style to thick line for the zero to show up.

.

shortski
Posts: 27
Joined: 21 May 2008

Postby shortski » 23 Jan 2009

I added the

value1 > 0 and value2 <0

at the end and it wouldn't compile.

Is there something more to do...?

Thanks

S

shortski
Posts: 27
Joined: 21 May 2008

Postby shortski » 23 Jan 2009

I just noticed the

Plot1(0,"neither",blue);

and it Plots as a solid blue line but no Histogram where there should be one.

User avatar
TJ
Posts: 6572
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1902 times

Postby TJ » 23 Jan 2009

I just noticed the
Plot1(0,"neither",blue);
and it Plots as a solid blue line but no Histogram where there should be one.


I have tried your code (with another function). It works, so the problem is not in the code.

there are 3 scenario for plotting:

1. value1 > 0 and value2 <0, (green)
2. value1 < 0 and value2 >0, (red)
3. neither (blue)

you are getting blue.

i.e. your functions are not returning the values you thought.

next step: use the print statement to debug.
(thank you for posting this question. this is a great learning experience for all)

add the following code to the end of the indicator:

Code: Select all

if barstatus = 2 then
print(
"d=" + text(d)
+", t=" + text(time_s)
+", v1=" + text(value1)
+", v2=" + text(value2)
);


go to your PowerEditor>View
make sure the Output Bar is checked.

On the bottom half of the PowerEditor, click on the Output tab.

Now you will see the values your indicator is processing.

enjoy.

shortski
Posts: 27
Joined: 21 May 2008

Postby shortski » 23 Jan 2009

Interesting. The Output tab is blank. Thanks for your time on this. I do appreciate it and am learning something as I go along.

shortski

User avatar
TJ
Posts: 6572
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1902 times

Postby TJ » 23 Jan 2009

the output tab is blank?
it should show red something like this:

Code: Select all

d=1090123.00, t=91000.00, v1=   2.50, v2=   2.50
d=1090123.00, t=91500.00, v1=   0.50, v2=   0.50


where
D= is the date (in EL time)
T= is the closing time of the bar
V1= is the value in Value1
V2= is the value in Value2


if you had plotted Value1 and Value2 as I suggested before, the V1 and V2 should not be blank.

User avatar
TJ
Posts: 6572
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1902 times

Postby TJ » 23 Jan 2009

I added the
Value1 > 0 and value2 <0


this not a good way to debug...
because you are not covering the situation where

Value1 = 0

and/or

Value2 = 0

a catch-all with no condition is preferred.

shortski
Posts: 27
Joined: 21 May 2008

Postby shortski » 23 Jan 2009

I may have found the problem. There is a line of code that is proprietary in the Functions I am using and the programmer just got back to me on it. He is unlocking it now and I will try it and let you know if it works.


Return to “MultiCharts”