again, a question to the pivot.
Sometimes I scare myself with how little my programming skills are.
I would like to do the following on a daily basis:
Once the pivot points are known (00.00?) open a trade that has the target the pivot point.
For the calculation of the pivot for Monday, the data from Friday should be taken.
How do I program this correctly?
A big thank you in advance
There you go:
DEFPARAM CumulateOrders = False
//
// Predefined PRT calculation (H+L+C)/3
//
p = 1
IF OpenDayOfWeek = 1 THEN
p = 2
ENDIF
Pivt = (DHigh(p) + DLow(p) + DClose(p))/3 // - Pivot
//Res4 = (2 * Pivt) + Dhigh(p) - (3 * Dlow(p)) //Res4
//Res3 = DHigh(p)+(2*(Pivt-DLow(p))) //Res3
//Res2 = Pivt+(DHigh(p)-DLow(p)) //Res2
//Res1 = (2*Pivt) - DLow(p) //Res1
//Sup1 = (2*Pivt) - DHigh(p) //Sup1
//Sup2 = Pivt-(DHigh(p)-DLow(p)) //Sup2
//Sup3 = DLow(p)-(2*(DHigh(p)-Pivt)) //Sup3
//Sup4 = (2 * Pivt) + Dlow(p) - (3 * Dhigh(p)) //Sup4
//MidR1 = (3*((DHigh(p) + DLow(p) + DClose(p))/3)-DLow(p))/2 //MidR1
//MidR2 = 3*(((DHigh(p) + DLow(p) + DClose(p))/3)+DHigh(p))/2-DLow(p) //MidR2
//MidR3 = DHigh(p)+3*(((DHigh(p) + DLow(p) + DClose(p))/3)-DLow(p))/2 //MidR3
//MidS1 = (3*((DHigh(p) + DLow(p) + DClose(p))/3)-DHigh(p))/2 //MidS1
//MidS2 = 3*(((DHigh(p) + DLow(p) + DClose(p))/3)-DLow(p))/2-DHigh(p) //MidS2
//MidS3 = DLow(p)+3*(((DHigh(p) + DLow(p) + DClose(p))/3)-DHigh(p))/2 //MidS3
IF close > Pivt THEN
BUY 1 CONTRACT AT Market
SET TARGET pPROFIT abs(close - Pivt)
ELSIF close > Pivt THEN
SELLSHORT 1 CONTRACT AT Market
SET TARGET pPROFIT abs(close - Pivt)
ENDIF
Sorry, in line 24 the “>” relational operator should be replaced by “<“.
Actually you did not tell when to enter Long or Short, so I just guessed.
Dear man.
Thank you very much for the code.
I will look into it and get back to you.
lg
Hello .
I had to deal with other things the whole days and only now got to look at the code.
I have rewritten the code a bit, simplified it a bit.
It looks like if set cumulateorders = true, the TP is cleared and set new each day. How can I change this?
DEFPARAM CumulateOrders = true
p = 1
IF OpenDayOfWeek = 1 THEN
p = 2
ENDIF
Pivt = (DOpen(p) + DHigh(p) + DLow(p) + DClose(p))/4 // - Pivot
//Res4 = (2 * Pivt) + Dhigh(p) - (3 * Dlow(p)) //Res4
//Res3 = DHigh(p)+(2*(Pivt-DLow(p))) //Res3
//Res2 = Pivt+(DHigh(p)-DLow(p)) //Res2
//Res1 = (2*Pivt) - DLow(p) //Res1
//Sup1 = (2*Pivt) - DHigh(p) //Sup1
//Sup2 = Pivt-(DHigh(p)-DLow(p)) //Sup2
//Sup3 = DLow(p)-(2*(DHigh(p)-Pivt)) //Sup3
//Sup4 = (2 * Pivt) + Dlow(p) - (3 * Dhigh(p)) //Sup4
//MidR1 = (3*((DHigh(p) + DLow(p) + DClose(p))/3)-DLow(p))/2 //MidR1
//MidR2 = 3*(((DHigh(p) + DLow(p) + DClose(p))/3)+DHigh(p))/2-DLow(p) //MidR2
//MidR3 = DHigh(p)+3*(((DHigh(p) + DLow(p) + DClose(p))/3)-DLow(p))/2 //MidR3
//MidS1 = (3*((DHigh(p) + DLow(p) + DClose(p))/3)-DHigh(p))/2 //MidS1
//MidS2 = 3*(((DHigh(p) + DLow(p) + DClose(p))/3)-DLow(p))/2-DHigh(p) //MidS2
//MidS3 = DLow(p)+3*(((DHigh(p) + DLow(p) + DClose(p))/3)-DHigh(p))/2 //MidS3
If time = 080000 then
If close < Pivt then
buy at market
Endif
Endif
SET TARGET pPROFIT abs(close - Pivt)
set stop %loss 10
Addendum.
Perhaps for the better understanding.
Every started trade should keep its “own” pivot as target.
Nope, when accumulating positions an average price is calculated at any new position taken and TP and SL are adjusted accordingly.
This cannot be changed.