Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

chrisleonard

Help with Code

Recommended Posts

Hi,

 

Below are some floor pivs that i like, can someone help me add a label to the half piv points?

 

At the moment it just shows the price nothing else, i would like to add mid piv before that!

 

Thanks

 

 

Chris

 

 

 

[LegacyColorValue = true]; 

input: PivotType(0),
BarsBack(60),
ShowClose(1),
ShowOpen(1),
ShowHalfPivots(1),
ShowLevel(0),
DaysBack(1),
NewDayTM(1510),
RoundLevels(false),
DecPlaces(2),
SupResType(0);

var: theday(0);
var: Maxcnt(11);
array:
TL[12](-1),Val[12](-1),
Color[12](6),Label[12]("L"),FTextID[12](-1), TLabel[12](" ");

var: cnt(0),sdate(0),stime(0),fPivot(0),twOpen(0),theRange(0);

if lastbaronchart then begin

if time >= NewDayTM then theday = 0  else theday = 1;
theday = theday + DaysBack-1;
if theday <= 0 then begin 
theday = 0;
twOpen = 0;
end else twopen = theday-1;  {make sure this weeks open isn't <0}

{store weekly Open and Close that we care about}
Val[10] = CloseD(theday);
if PivotType >0 and PivotType <4 then Val[11] = OpenD(twopen) else Val[11] = OpenD(theday);

{calculate central pivot based on pivot type}{not sure how usefull some of these might be}
if      PivotType = 1 then fPivot = (HighD(theday) + LowD(theday) + Val[11]) /3
else if PivotType = 2 then fPivot = (HighD(theday) + LowD(theday) + Val[11] + Val[11]) /4
else if PivotType = 3 then fPivot = (HighD(theday) + LowD(theday) + Val[10] + Val[11]) /4
else if PivotType = 4 then fPivot = (HighD(theday) + LowD(theday) + Val[10] + Val[11]) /4
else fPivot = (HighD(theday) + LowD(theday) + Val[10]) /3; {default standard Pivot}

if SupResType = 1 then begin {seems like there is always a little different way to do these}
theRange = (HighD(theday) - LowD(theday))/2;
VAl[1] = fPivot;
VAl[2] = fPivot + theRange; {R1}
VAl[3] = fPivot - theRange; {S1}

VAl[4] = VAl[2] + theRange; {R2}
VAl[5] = VAl[3] - theRange; {S2}

VAl[6] = VAl[4] + theRange; {R3}
VAl[7] = VAl[5] - theRange; {S3}
VAl[8] = VAl[6] + theRange; {R4}
VAl[9] = VAl[7] - theRange; {S4}
end
else begin
VAl[1] = fPivot;
VAl[2] = fPivot + fPivot - LowD(theday); {R1}
VAl[3] = fPivot + fPivot - HighD(theday); {S1}

VAl[4] = fPivot + VAl[2] - VAl[3]; {R2}
VAl[5] = fPivot - VAl[2] + VAl[3]; {S2}

VAl[6] = fPivot + VAl[4] - VAl[3]; {R3}
VAl[7] = fPivot - VAl[4] + VAl[3]; {S3}
VAl[8] = fPivot + VAl[4] - VAl[5]; {R4}
VAl[9] = fPivot - VAl[4] + VAl[5]; {S4}
end;

if RoundLevels then begin
for cnt = 1 to 11 begin
	val[cnt] = roundInst(val[cnt]);
end;
end;

Color[1] = LightGray;
Color[2] = Darkred;
Color[3] = Darkgreen;
Color[4] = Darkred;
Color[5] = Darkgreen;
Color[6] = Darkred;
Color[7] = Darkgreen;
Color[8] = Darkred;
Color[9] = Darkgreen;
Color[10] = Yellow;
Color[11] = DarkBrown;

TLabel[1] = "Daily Pivot - ";
TLabel[2] = "Daily R1 - ";
TLabel[3] = "Daily S1 - ";
TLabel[4] = "Daily R2 - ";
TLabel[5] = "Daily S2 - ";
TLabel[6] = "Daily R3 - ";
TLabel[7] = "Daily S3 - ";
TLabel[8] = "Daily R4 - ";
TLabel[9] = "Daily S4 - ";
TLabel[10] = "Prev Day Close - ";
TLabel[11] = "Prev Day Open - ";


sdate = Date[barsBack];
stime = Time[barsBack];


for cnt= 1 to Maxcnt begin
if cnt < 10 or (ShowClose <> 0 and cnt = 10) or (ShowOpen <> 0 and cnt = 11) then begin
	if TL[cnt] < 0 then begin {dosn't exist, create new TL}
		TL[cnt] = TL_New (sdate, stime, Val[cnt],
			date, time , Val[cnt]);
		TL_SetColor (TL[cnt], Color[cnt]);
		if cnt >= 10 then TL_SetStyle (TL[cnt], Tool_Dashed)
			else TL_SetStyle (TL[cnt], Tool_Dashed);
	end;
	if TL_Exist(TL[cnt]) then begin {exist}
		TL_SetEnd (TL[cnt], date, time , Val[cnt]);
		TL_SetBegin (TL[cnt], sdate, stime, Val[cnt]); {reset TL}
		TL_SetExtRight(TL[cnt],true);
	end;

	{do text stuff}
	if FTextID[cnt] < 0 then begin  {is new}
		FTextID[cnt] = Text_New(sdate, stime, Val[cnt], "zzz");
		Text_SetStyle(FTextID[cnt], 1, 2);
		Text_SetColor(FTextID[cnt], Color[cnt]);
	end;
	if FTextID[cnt] >= 0 then begin  {already exists}
		Text_SetLocation(FTextID[cnt], sdate, stime, Val[cnt]);
		Text_SetString(FTextID[cnt],TLabel[cnt] + NumToStr(Val[cnt], DecPlaces) + " " );
	end;
end; {count < 6, etc.}
end; {cnt}

Array: HalfTL[9](-1),HalfVal[9](0),HTextID[9](-1);

if ShowHalfPivots <> 0 then begin
HalfVal[1] = ((Val[4] - Val[2])/2) + Val[2];
HalfVal[2] = ((Val[2] - Val[1])/2) + Val[1];
HalfVal[3] = ((Val[1] - Val[3])/2) + Val[3];
HalfVal[4] = ((Val[3] - Val[5])/2) + Val[5]; {s1-s2}
HalfVal[5] = ((Val[4] - Val[6])/2) + Val[6];
HalfVal[6] = ((Val[5] - Val[7])/2) + Val[7]; {s2-s3}
HalfVal[7] = ((Val[6] - Val[8])/2) + Val[8];
HalfVal[8] = ((Val[7] - Val[9])/2) + Val[9]; {s3-s4}

if RoundLevels then begin
	for cnt = 1 to 8 begin
		HalfVal[cnt] = roundInst(HalfVal[cnt]);
	end;
end;

for cnt= 1 to 8 begin
	if HalfTL[cnt] < 0 then begin {dosn't exist, create new TL}
		HalfTL[cnt] = TL_New (sdate, stime, HalfVal[cnt],
		date, time , HalfVal[cnt]);
		TL_SetColor (HalfTL[cnt], DarkGray);
		TL_SetStyle (HalfTL[cnt], Tool_Dashed);
	end;
	if TL_Exist(HalfTL[cnt]) then begin {exist}
		TL_SetEnd (HalfTL[cnt], date, time , HalfVal[cnt]);
		TL_SetBegin (HalfTL[cnt], sdate, stime, HalfVal[cnt]); {reset TL}
		TL_SetExtRight(HalfTL[cnt],true);

	end;

	{do text stuff}
	if HTextID[cnt] < 0 then begin  {is new}
		HTextID[cnt] = Text_New(sdate, stime, HalfVal[cnt], "zzz");
		Text_SetStyle(HTextID[cnt], 1, 2);
		Text_SetColor(HTextID[cnt], DarkGray);
	end;
	if HTextID[cnt] >= 0 then begin  {already exists}
		Text_SetLocation(HTextID[cnt], sdate, stime, HalfVal[cnt]);
		Text_SetString(HTextID[cnt], NumToStr(HalfVal[cnt], DecPlaces) + " " );
	end;
end; {cnt}
end; {ShowHalfPivots}

end; {last bar}

if ShowLevel > 0 and ShowLevel <= 4 then begin
noplot(2);
noplot(3);
if ShowLevel = 1 then begin
	Plot2[-1](Val[2] + .5,"h");
	Plot3[-1](Val[3] - .5,"l");
end
else if ShowLevel = 2 then begin
	Plot2[-1](Val[4] + .5,"h");
	Plot3[-1](Val[5] - .5,"l");
end
else if ShowLevel = 3 then begin
	Plot2[-1](Val[6] + .5,"h");
	Plot3[-1](Val[7] - .5,"l");
end
else if ShowLevel = 4 then begin
	Plot2[-1](Val[8] + .5,"h");
	Plot3[-1](Val[9] - .5,"l");
end;

end;

Share this post


Link to post
Share on other sites
Hi, I have sorted this now.

 

Thanks Anyway

 

Chris

 

 

as a courtesy to the community, you should post your solution, so that everybody can learn from it.

Share this post


Link to post
Share on other sites

No Probs,

 

I kind of bodged it but it did the job!!

 

i added

 

MLabel[1] = "Mid Point - ";

 

then i changed the string from

 

Text_SetString(HTextID[cnt], NumToStr(HalfVal[cnt], DecPlaces) + " " );

 

To

 

Text_SetString(HTextID[cnt], MLabel[1] + NumToStr(HalfVal[cnt], DecPlaces) + " " );

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Topics

  • Posts

    • ...hallucinates.... Student: “What if we gave the monkey LSD?” Guru: “The monkey already did LSD”
    • Question: To those that had/have cancer, what were the signs that made you think “something is not right here” to make you go see a doctor? Answer: So, 5/25/2018, I woke up, got ready for work, and as I walked to my car, I started gagging. Like something was stuck in my throat and I needed to clear it. And then it went away.   But 10 minutes after that, I was T-boned at 40mph on the driver side door. But what made me see a doctor was while my muscles felt better and bruises were going away, the gagging still continued, I started having fevers, my neck felt swollen, I was having such a hard time breathing, and I'd have random sharp pains in my chest, but not from where the seat belt saved me.   2 weeks after the accident, I finally see an urgent care doctor, who looks me over, tells me I'm fine, but luckily requests a neck X-ray. And I ask for a chest X-ray, which he rolls his eyes but let me have (most of my pain was in the neck, so I understand).   The very next day, he calls and says “So, that chest X-ray shows there's a 4 inch mass on your heart and lungs, and your lungs have been filling up with fluid, as well as in your pericardial (heart) wall. We need you to come in tomorrow.”   Turns out the big mass, due to the accident, caused my heart and lungs to tear and fill with fluid, the swollen neck and gagging was caused by 2 metastasized tumors, and the fevers and weight loss were symptoms. Stage 4b Hodgkin's Lymphoma.   But thankfully, we went very aggressive with chemo (and had a lot of bad side effects that don't normally happen to patients), and now I'm about 16 months cancer-free. Yay lucky X-rays! Rachel Jurina, Quora Source: https://www.quora.com/To-those-that-had-have-cancer-what-were-the-signs-that-made-you-think-something-is-not-right-here-to-make-you-go-see-a-doctor   Profits from free accurate cryptos signals: https://www.predictmag.com/  
    • As a man, the reality of life is the harshest part. I don’t mind looking older or becoming weaker over time; it’s nature.   Have you ever heard that the only people who will be loved unconditionally are women and children? Men will only be loved as long as they can provide until they are no longer needed. It doesn’t matter if you already did your best to get your kids to the best school or get the best things for them, if you stop before they’re done with it, there will be no thank you. The only thing they will remember is that they have to quit school at 15, ignoring all the previous 15 years of life you provided for them. The only people who will accept you, no matter what, are your parents. But in this situation, you might be that ungrateful child.   EDIT: Wow, I didn’t think this would get so much attention.   For those who disagree, I can only say that everyone has their problem. If you don’t get the chance to face such a thing, be grateful. Remember, sometimes what you throw in the garbage is something that someone wishes ever to have.” – ElZee, Quora   Profits from free accurate cryptos signals: https://www.predictmag.com/    
    • The good thing i had noticed so far is that the traderpot value is also on the rise..
    • yup its a gradual rollout the right way in my opinion, its really good and its exciting for the sto in 2027
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.