PowerLanguage to .NET conversion  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Zoli
Posts: 90
Joined: 12 Sep 2012
Has thanked: 24 times
Been thanked: 38 times

PowerLanguage to .NET conversion  [SOLVED]

Postby Zoli » 14 Sep 2012

Hi,

I struggled to learn coding in PowerLanguage and I managed somehow to finish the indicator I needed. I switched to .NET because it opens new opportunities (e.g. Dru's TPO thx for that) and I find it very difficult to translate the code to C#. I cannot find examples how to use the Pivot function for ex. and I cannot find examples of complex but still easy to understand code in C# for MC which I could use as a reference tool for my learning (that approach helped me manage to code for PL). It is a simple code but important for my trading style. Could anyone help me translate it?
I attached an image of how the indicator looks like.

Code: Select all

inputs:
Strength(5),Diff(0),ShowText(True),ShowTotal(true),Digits(5),
MarginofErr(5),
colour_stop_long(cyan),colour_stop_short(red),colour_be_long(green),colour_be_short(magenta),
PlotChart(false),ColourChangeNumber(24);

Vars:
PriceLo(0),BarLo(0),PriceHi(0),BarHi(0),Length(0),j(0),diff2(0),
count_lowpivots(1), // pivots number
count_highpivots(1),
colour(white),textfortotal(0),hit_low(0),hit_high(0),
colour2(ColourChangeNumber/2),alarm_hit(false); // plotting colour

arrays:
lowpivots[50000](0), // pivots value
highpivots[50000](0),
lowpivots_deleted[50000](false),//pivot 1-pivot deleted,0-not
highpivots_deleted[50000](false),
lowtext[50000](0), // pivots text
hightext[50000](0),
highlines[50000](0), //pivots trendlines
lowlines[50000](0),
low_triggered[50000](false), //pivot hit
high_triggered[50000](false),
breakof_lowpivots[50000](false), // 1-pivot broken,0-not
breakof_highpivots[50000](false),
breakbarof_lowpivots[50000](0), // barnumber of broken pivot
breakbarof_highpivots[50000](0),
touchbarof_lowpivots[50000](0),
touchbarof_highpivots[50000](0);

if barstatus=2 then begin

Length=strength+1;
diff2=diff/power(10,digits-1);

value1=Pivot(Low,Length,Strength,Strength,1,-1,PriceLo,BarLo);
value2=Pivot(high,Length,Strength,Strength,1,1,PriceHi,BarHi);

if value1=1 then begin
lowpivots[count_lowpivots]=pricelo;
if ShowText=true then begin
lowtext[count_lowpivots]=text_new(date[barlo],time[barlo],pricelo,numtostr(pricelo,digits));
text_setcolor(lowtext[count_lowpivots],colour_stop_short);
text_setstyle(lowtext[count_lowpivots],2,0);
end;
lowlines[count_lowpivots]=tl_new(date[barlo],time[barlo],pricelo+diff2,date,time,pricelo+diff2);
tl_setextright(lowlines[count_lowpivots],true);
tl_setcolor(lowlines[count_lowpivots],colour_stop_short);
tl_setstyle(lowlines[count_lowpivots],4);
count_lowpivots=count_lowpivots+1;
end;

if value2=1 then begin
highpivots[count_highpivots]=pricehi;
if ShowText=true then begin
hightext[count_highpivots]=text_new(date[barhi],time[barhi],pricehi,numtostr(pricehi,digits));
text_setcolor(hightext[count_highpivots],colour_stop_long);
text_setstyle(hightext[count_highpivots],2,1);
end;
highlines[count_highpivots]=tl_new(date[barhi],time[barhi],pricehi-diff2,date,time,pricehi-diff2);
tl_setextright(highlines[count_highpivots],true);
tl_setcolor(highlines[count_highpivots],colour_stop_long);
tl_setstyle(highlines[count_highpivots],4);
count_highpivots=count_highpivots+1;
end;

for j=1 to count_lowpivots-1 begin
if lowpivots_deleted[j]=false then begin
if high>=lowpivots[j] and barnumber>=breakbarof_lowpivots[j]+MarginofErr-1 and breakof_lowpivots[j]=true then begin
if showtext=true then text_delete(lowtext[j]);
tl_delete(lowlines[j]);
lowpivots_deleted[j]=true;
if colour2>0 then colour2=colour2-1;
hit_high=hit_high+1;
end;
if low_triggered[j]=false then
if low<=lowpivots[j] and breakof_lowpivots[j]=false then begin
low_triggered[j]=true;
touchbarof_lowpivots[j]=barnumber;
if colour2<ColourChangeNumber then colour2=colour2+1;
hit_low=hit_low+1;
end;
if low_triggered[j]=true and breakof_lowpivots[j]=false then
if barnumber>=touchbarof_lowpivots[j]+MarginofErr then begin
if showtext=true then text_delete(lowtext[j]);
tl_delete(lowlines[j]);
lowpivots_deleted[j]=true;
end;
if close<lowpivots[j] and breakof_lowpivots[j]=false then begin
breakof_lowpivots[j]=true;
breakbarof_lowpivots[j]=BarNumber;
tl_setcolor(lowlines[j],colour_be_short);
if low_triggered[j]=false then begin
if colour2<ColourChangeNumber then colour2=colour2+1;
hit_low=hit_low+1;
end;
end;
end;
end;

for j=1 to count_highpivots-1 begin
if highpivots_deleted[j]=false then begin
if low<=highpivots[j] and barnumber>=breakbarof_highpivots[j]+MarginofErr-1 and breakof_highpivots[j]=true then begin
if showtext=true then text_delete(hightext[j]);
tl_delete(highlines[j]);
highpivots_deleted[j]=true;
if colour2<ColourChangeNumber then colour2=colour2+1;
hit_low=hit_low+1;
end;
if high_triggered[j]=false then
if high>=highpivots[j] and breakof_highpivots[j]=false then begin
high_triggered[j]=true;
touchbarof_highpivots[j]=barnumber;
if colour2>0 then colour2=colour2-1;
hit_high=hit_high+1;
end;
if high_triggered[j]=true and breakof_highpivots[j]=false then
if barnumber>=touchbarof_highpivots[j]+MarginofErr then begin
if showtext=true then text_delete(hightext[j]);
tl_delete(highlines[j]);
highpivots_deleted[j]=true;
end;
if close>highpivots[j] and breakof_highpivots[j]=false then begin
breakof_highpivots[j]=true;
breakbarof_highpivots[j]=BarNumber;
tl_setcolor(highlines[j],colour_be_long);
if high_triggered[j]=false then begin
if colour2>0 then colour2=colour2-1;
hit_high=hit_high+1;
end;
end;
end;
end;

value3=round(colourchangenumber/6,0);

if colour2<=value3 then colour=rgb(255,0,0);
if colour2<=value3*2 and colour2>value3 then colour=rgb(223,100,9);
if colour2<=value3*3 and colour2>value3*2 then colour=rgb(158,88,46);
if colour2<=value3*4 and colour2>value3*3 then colour=rgb(159,146,45);
if colour2<=value3*5 and colour2>value3*4 then colour=rgb(72,163,33);
if colour2<=value3*6 and colour2>value3*5 then colour=rgb(0,255,0);

if alarm_hit=false then begin
if colour=rgb(255,0,0) then begin
alert("SELL Zone");
alarm_hit=true;
end;
if colour=rgb(0,255,0) then begin
alert("BUY Zone");
alarm_hit=true;
end;
end;
if colour=rgb(72,163,33) or colour=rgb(223,100,9) then alarm_hit=false;

end; // if barstatus

if plotchart=true then begin
plot1(high);
SetPlotColor(1,colour);
plot2(Low);
SetPlotColor(2,colour);
plot4(close);
SetPlotColor(4,colour);
SetPlotWidth(4,2);
end;

if ShowTotal=true and lastbaronchart then begin
if text_exist(textfortotal)=false then begin
if hit_high>hit_low then begin
textfortotal=text_new(date,time,GetAppInfo(aiHighestDispValue),numtostr(hit_high-hit_low,0));
text_setcolor(textfortotal,red);
end;
if hit_high<hit_low then begin
textfortotal=text_new(date,time,GetAppInfo(aiHighestDispValue),numtostr(hit_low-hit_high,0));
text_setcolor(textfortotal,green);
end;
if hit_high=hit_low then begin
textfortotal=text_new(date,time,GetAppInfo(aiHighestDispValue),numtostr(hit_high-hit_low,0));
text_setcolor(textfortotal,white);
end;
text_setsize(textfortotal,20);
end
else if barstatus=2 then begin
Text_SetLocation(textfortotal, date, time, GetAppInfo(aiHighestDispValue));
text_setstring(textfortotal,numtostr(hit_high-hit_low,0));
if hit_high>hit_low then begin
text_setcolor(textfortotal,red);
text_setstring(textfortotal,numtostr(hit_high-hit_low,0));
end;
if hit_high<hit_low then begin
text_setcolor(textfortotal,green);
text_setstring(textfortotal,numtostr(hit_low-hit_high,0));
end;
if hit_high=hit_low then begin
text_setcolor(textfortotal,white);
text_setstring(textfortotal,numtostr(hit_low-hit_high,0));
end;
end;
end;
Attachments
example.png
(45.15 KiB) Downloaded 879 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: PowerLanguage to .NET conversion

Postby Henry MultiСharts » 14 Sep 2012

Hello Zoli,

Please contact us directly if you are interested in custom programming.


Return to “MultiCharts .NET”