ProRealCode - Trading & Coding with ProRealTime™
Thanks, by launching the strategy on the 1 minute TMF, do you mean placing the 1mn lines at the beginning of the global code and then the 60 minutes conditions / lines of code ? Thanks
Place your code related to the 60-minutes timeframe under this statement:
TIMEFRAME(1 hour, updateonclose) //use update on close or not?
and the rest, about the 1-minute conditions below this:
TIMEFRAME(default)
Default is the current timeframe of the chart.
HI, dos not work . My code (not even finished at that stage) is looking like . The idea is to check few indicators during a 1 hour timeframe ad if one of the indicator is correctly responding, then to generate immedately an order during the 1 minute timeframe… It means i need to get the expected signal during the 60 minutes timeframe and immediately react under the 1 mn timeframe. It also means i cannot wait the 1 hour TF is closed and restart ….thats probably the issue. I also tested the condition all conditions = order or 1 of the conditions )= order. without success.
DEFPARAM CumulateOrders = False // Cumul des positions désactivé
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d’une position avant l’heure spécifiée
noEntryBeforeTime = 003000
timeEnterBefore = time >= noEntryBeforeTime
// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d’une position après l’heure spécifiée
noEntryAfterTime = 215500
timeEnterAfter = time < noEntryAfterTime
// Conditions pour ouvrir une position acheteuse
timeframe (60 minutes)
indicator1 = xxxx[x]
c1 = (indicator1 > x)
indicator2 = xxxxxx[x]
indicator3 = xxxxx[x](open)
c2 = (indicator2 CROSSES OVER indicator3)
indicator4 = xxxxx[x](totalPrice)
indicator5 = xxxxxxx[x](totalPrice)
c3 = (indicator4 CROSSES OVER indicator5)
indicator6 = xxxxxx[x](totalPrice)
indicator7 = xxxxx[x](totalPrice)
c4 = (indicator6 CROSSES OVER indicator7)
indicator8 = xxxxxxxxx[x,y](close)
indicator9 = xxxxxxx[x](xxxxxxxxxx[x,y](close))
c5 = (indicator8 CROSSES OVER indicator9)
indicator10 = xxxxxxxx[x](xxxxxxxxxxxxxxxx[x,y](close))
c6 = (indicator10[1] CROSSES OVER indicator10)
c7 = (indicator2[1] CROSSES OVER indicator3)
timeframe(1 minute,default)
IF (c1 AND c2 AND c3 AND c4 AND c5 AND c6 And 7) AND not daysForbiddenEntry THEN
BUY 1 SHARES AT MARKET
ENDIF
Hmmm
Lolzzzz
Anyway, your want an indicator on the 1hr timeframe to trigger a buy or sell on the 1 minute timeframe…
It wont happen, becuase you may have to wait a minute for the close of the 1 minute… so here’s an example code, but for an immediate reaction run on the 1 second timeframe not 1 minute…Let me give you a code for running a code on 1 second chart only using the values or results from 5 or 10 minutes chart.
So once you have the variable triggered in the HTF the in the below case it retains the value of the close, otherwise it updates all the time and messes up the trail… so
timeframe (1hour, updateonclose)
If not onmarket then
mytrigger=0
endif
if movingaverageA crossesovermoving averageB then
Mytrigger=1
else
mytrigger=0
endif
timeframe (1 second)
If not onmarket and mytrigger=1 then
sell myamount contracts at market
endif
// If you use the 1 minute chart, you may have to await the end of bar, so for immediate execution use the 1 second timeframe for execution of trades and HTFs for conditions determination
Timeframe (10 minute, updateonclose) //this will ensure only the close value is taken and it doesnt constantly update on the deafault timeframe//
Timeframe (10 minute, updateonclose)
if close[0] then
close10min=close[0]
endif
Timeframe (5 minute, updateonclose)
if close[0] then
close5min=close[0]
endif
timeframe (default)//you can put this as 5 minutes, or whatever but the code runs on the 1 second chart and runs the dax trail perfectly well
if daxtrail5mins=1 then
once m=0
IF Not OnMarket THEN
trailpausecount=0
TrailStart = 8 //10 Start trailing profits from this point
BasePerCent = 0.100 //10.0% Profit to keep
StepSize = 3 //6 Pips chunks to increase Percentage
PerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunk
RoundTO = -0.5 //-0.5 rounds to Lower integer, +0.4 rounds to Higher integer
PriceDistance = 7 * pipsize//8.9 minimun distance from current price
y1 = 0
y2 = 0
ProfitPerCent = BasePerCent
endif
If onmarket and m=0 then
m=1
ENDIF
If not onmarket and m=1 THEN
QUIT
endif
If trailtimeframe=5 then
close5=close5min
elsif trailtimeframe=10 THEN
close5=close10min
endif
If onmarket and close5 then
IF LongOnMarket AND close5 > (TradePrice + (y1 * pipsize)) THEN //LONG
x1 = (close5 – tradeprice) / pipsize //convert price to pips
IF x1 >= TrailStart THEN //go ahead only if N+ pips
Diff1 = abs(TrailStart – x1)
Chunks1 = max(0,round((Diff1 / StepSize) + RoundTO))
ProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc))
ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
y1 = max(x1 * ProfitPerCent, y1) //y = % of max profit
ENDIF
ELSIF ShortOnMarket AND close5 < (TradePrice - (y2 * pipsize)) THEN//SHORT
x2 = (tradeprice - close5) / pipsize //convert price to pips
IF x2 >= TrailStart THEN //go ahead only if N+ pips
Diff2 = abs(TrailStart – x2)
Chunks2 = max(0,round((Diff2 / StepSize) + RoundTO))
ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc))
ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
y2 = max(x2 * ProfitPerCent, y2) //y = % of max profit
ENDIF
ENDIF
IF y1 THEN //Place pending STOP order when y>0
SellPrice = Tradeprice + (y1 * pipsize) //convert pips to price
IF abs(close5 – SellPrice) > PriceDistance THEN
IF close5 >= SellPrice THEN
SELL AT SellPrice STOP
ELSE
SELL AT SellPrice LIMIT
ENDIF
ELSE
SELL AT Market
ENDIF
If not onmarket and m=1 THEN
QUIT
endif
ENDIF
IF y2 THEN //Place pending STOP order when y>0
ExitPrice = Tradeprice – (y2 * pipsize) //convert pips to price
IF abs(close5 – ExitPrice) > PriceDistance THEN
IF close5 <= ExitPrice THEN
EXITSHORT AT ExitPrice STOP
ELSE
EXITSHORT AT ExitPrice LIMIT
ENDIF
ELSE
EXITSHORT AT Market
ENDIF
If not onmarket and m=1 THEN
quit
endif
ENDIF
endif
endif
U know I didnt have insrt PRT code in my before window, so sorry abo that, thought something had changed, but now its there again…. Hmmm
Heres the codes again
timeframe (1hour, updateonclose)
If not onmarket then
mytrigger=0
endif
if movingaverageA crossesovermoving averageB then
Mytrigger=1
else
mytrigger=0
endif
timeframe (1 second)
If not onmarket and mytrigger=1 then
sell myamount contracts at market
endif
if close[0] then
close10min=close[0]
endif
Timeframe (5 minute, updateonclose)
if close[0] then
close5min=close[0]
endif
timeframe (default)//you can put this as 5 minutes, or whatever but the code runs on the 1 second chart and runs the dax trail perfectly well
if daxtrail5mins=1 then
once m=0
IF Not OnMarket THEN
trailpausecount=0
TrailStart = 8 //10 Start trailing profits from this point
BasePerCent = 0.100 //10.0% Profit to keep
StepSize = 3 //6 Pips chunks to increase Percentage
PerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunk
RoundTO = -0.5 //-0.5 rounds to Lower integer, +0.4 rounds to Higher integer
PriceDistance = 7 * pipsize//8.9 minimun distance from current price
y1 = 0
y2 = 0
ProfitPerCent = BasePerCent
endif
If onmarket and m=0 then
m=1
ENDIF
If not onmarket and m=1 THEN
QUIT
endif
If trailtimeframe=5 then
close5=close5min
elsif trailtimeframe=10 THEN
close5=close10min
endif
If onmarket and close5 then
IF LongOnMarket AND close5 > (TradePrice + (y1 * pipsize)) THEN //LONG
x1 = (close5 – tradeprice) / pipsize //convert price to pips
IF x1 >= TrailStart THEN //go ahead only if N+ pips
Diff1 = abs(TrailStart – x1)
Chunks1 = max(0,round((Diff1 / StepSize) + RoundTO))
ProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc))
ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
y1 = max(x1 * ProfitPerCent, y1) //y = % of max profit
ENDIF
ELSIF ShortOnMarket AND close5 < (TradePrice - (y2 * pipsize)) THEN//SHORT x2 = (tradeprice - close5) / pipsize //convert price to pips IF x2 >= TrailStart THEN //go ahead only if N+ pips
Diff2 = abs(TrailStart – x2)
Chunks2 = max(0,round((Diff2 / StepSize) + RoundTO))
ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc))
ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
y2 = max(x2 * ProfitPerCent, y2) //y = % of max profit
ENDIF
ENDIF
IF y1 THEN //Place pending STOP order when y>0
SellPrice = Tradeprice + (y1 * pipsize) //convert pips to price
IF abs(close5 – SellPrice) > PriceDistance THEN
IF close5 >= SellPrice THEN
SELL AT SellPrice STOP
ELSE
SELL AT SellPrice LIMIT
ENDIF
ELSE
SELL AT Market
ENDIF
If not onmarket and m=1 THEN
QUIT
endif
ENDIF
IF y2 THEN //Place pending STOP order when y>0
ExitPrice = Tradeprice – (y2 * pipsize) //convert pips to price
IF abs(close5 – ExitPrice) > PriceDistance THEN
IF close5 <= ExitPrice THEN EXITSHORT AT ExitPrice STOP
ELSE
EXITSHORT AT ExitPrice LIMIT
ENDIF
ELSE
EXITSHORT AT Market
ENDIF
If not onmarket and m=1 THEN
quit
endif
ENDIF
endif
endif
I would like to make an indicator with different timeframes. To give an example: If I wanted to observe if the RSI is oversold in a time frame of 1 second, let me know with a signal in a time frame of 5 minutes, which is where I usually work. My goal is to be able to save time and not have to change time frames.
This you think can be achieved. I’ve been thinking about it for a while but I can’t do it.
Thank you.
The support for multiple time frames implies that on a 1-second TF you can check conditions on a 5-minute TF, not the other way round.
The TF on your chart must always be the smallest one. Of course you can have both the 1-second and 5-minute TF on your chart, but the indicator needs to be added to the 1-second TF.
Thank you Roberto for your response.
is it possible to get hold of a value returned by a personal indicator placed on a 3600 tick chart inside a 3 minute chart? This would be the difference between finding intraday trades 5 days a week and not finding one trade, on time, in a week.
If your thinking of back-testing and automatic trading I think the answer is no.
But if just as an indicator and manual trading, then very loosely Maybe.
Arrays update on each tick, in a indicator, so you could count/accumulate the data.
Storing it, and aligning to what was on the tick chart would be tricky but I think doable.
However , when a chart is built, it appears to use OHLC bar data until current bar where ticks available.
Therefore you couldn’t gain access or look back for the ticks before current bar when chart opened.
So either you would have to wait to accumulated enough tick data and/or open chart substantially earlier than you need.
The automatic closing of PRT would lose the tick data gathered on close/reboot.
Also, if the chart window was re-calculated and updated, for any reason while open, the data would get lost.
So though it maybe possible, it would be a nightmare to use.
The simple reason would be, you can not store user data in the program which would be available the next time its run/opened.
Now it maybe easier to build the 3min time frame on the 3600 tick chart.
All 3min indicators would have to be converted.
One limiting factor would be the number of bar needed in the chart to calculate the 3min indicators.
Its hard to say yes with out knowing the full details of what your doing.
Which ever way, it’s an out of the box, programming challenge.
https://www.prorealcode.com/topic/show-5-minute-candlestick-in-1-minute-chart/
Good morning everyone. I ask for help please: I don’t know if I’m doing something wrong, but I used the multitimeframe mode to draw my indicator on the same graph, applying it to two different timeframes, but checking the result I noticed that the result does not coincide with the data of the indicator normally drawn on the single timeframe. In particular it seems that it’s wrong in drawing the double periods (for example the two-weekly tf on the weekly chart and so on …).
How can I resolve this inconvenience? Do any of you know the problem? Am I the one making a mistake or is it a system bug?
Thanks in advance
Make an example (code snippet) to test it.
Thanks for replying Roberto.
For example on the 2 months TF my indicator value is 5527,76 while if I charge it on the monthly TF with indication at beginning of code TIMEFRAME (2 MONTHS) the value it returns is 5312,08
The code is as follows (ignore colors and colorbetween I don’t use):
timeframe (2 months, default)
period = 13
deviation1 = 1
deviation2 = 2
deviation3 = 3
longupper= 30
longmiddle=20
longlower=10
shortlower=-30
shortmiddle=-20
shortupper=-10
rem up = 1
rem down = -1
rem begin = 1
// (i) indicators
iSTD1 = deviation1 * STD[period](close)
iSTD2 = deviation2 * STD[period](close)
iSTD3 = deviation3 * STD[period](close)
iSMA = Average[period,0](close)
sma25 = Average[25,0](close)
sma50 = Average[50,0](close)
// (c) conditions
cUpperBand3 = iSMA + iSTD3 // ----3----
cUpperBand2 = iSMA + iSTD2 // ----2----
cUpperBand1 = iSMA + iSTD1 // ----1----
cMiddleBand = iSMA // ----0----
cLowerBand1 = iSMA - iSTD1 // ----1----
cLowerBand2 = iSMA - iSTD2 // ----2----
cLowerBand3 = iSMA - iSTD3 // ----3----
// delay start
if barindex < period then // hold off till enough bar present
ts = Undefined // removes ts tangent line from 0 til real value available
endif
// logic operation
// setup block --> When 'begin' = 0, executes next block.
// Since 'trend' default = 0, being set to 1 or -1 will
// allow the 'following' logic code blocks to be executed
// Bollinger Logic -----------
// initial, set trend, trend only changed by iSTD1
if trend=0 and close crosses over cUpperband1 then
trend = longupper
elsif trend=0 and close crosses under cLowerBand1 then
trend = shortlower
endif
// following from first time after trend set!
// change of trend
if trend = longupper and close crosses under cUpperBand1 then
trend = longmiddle
endif
if trend=longmiddle then
if close crosses under cMiddleBand then
trend=longlower
elsif close crosses over cUpperBand2 then
trend=longupper
else
trend = longmiddle
endif
endif
if trend=longlower then
if close crosses under cLowerBand1 then
trend=shortlower
elsif close crosses over cUpperBand1 and close < cUpperBand2 then
trend = longmiddle
elsif close crosses over cUpperBand2 then
trend=longupper
else
trend=longlower
endif
endif
if trend=shortlower and Close crosses over cLowerBand1 then
trend=shortmiddle
endif
if trend=shortmiddle then
if close crosses over cMiddleBand then
trend=shortupper
elsif close crosses under cLowerBand2 then
trend = shortlower
else
trend=shortmiddle
endif
endif
if trend = shortupper then
if close crosses over cUpperBand1 then
trend=longupper
elsif close crosses under cLowerBand1 and close > cLowerBand2 then
trend=shortmiddle
elsif close crosses under cLowerBand2 then
trend=shortlower
else
trend = shortupper
endif
endif
// set 'ts' values to appropriate band threshold level
if trend = longupper or trend = shortupper then
ts = cUpperBand1
elsif trend = longmiddle or trend = shortmiddle then
ts = cMiddleBand
elsif trend = longlower or trend = shortlower then
ts = cLowerBand1
endif
// color settings
if trend = longupper or trend = longmiddle or trend = longlower then
r = 0
g = 255 // set all colorbetween's green
a1 = 20 // on upperband 3
a2 = 15 // on upperband 2
a3 = 10 // on upperband 1
a4 = 5 // on lowerband 1
a5 = 15 // off lowerBand 2
a6 = 20 // off lowerBand 3
elsif trend = shortupper or trend=shortmiddle or trend=shortlower then
r = 255 // set all colorbetween's red
g = 0
a1 = 20 // off upperband 3
a2 = 15 // off upperband 2
a3 = 5 // on upperBand 1
a4 = 10 // on lowerBand 1
a5 = 15 // on lowerBand 2
a6 = 20 // on lowerBand 3
endif
////////////
if close >= cMiddleBand then
r0=0
g0=255
elsif close < cMiddleBand then
r0=255
g0=0
endif
if close >= cUpperBand1 then
r11 =0
g11=255
elsif close < cUpperBand1 then
r11 =255
g11=0
endif
if close >= cUpperBand2 then
r21 =0
g21=255
elsif close < cUpperBand2 then
r21 =255
g21=0
endif
if close >= cUpperBand3 then
r51 =0
g51=255
elsif close < cUpperBand3 then
r51 =255
g51=0
endif
if close <= cLowerBand1 then
r31=255
g31=0
elsif close > cLowerBand1 then
r31 =0
g31=255
endif
if close <= cLowerBand2 then
r41=255
g41=0
elsif close > cLowerBand2 then
r41 =0
g41=255
endif
if close <= cLowerBand3 then
r61 =255
g61 =0
elsif close > cLowerBand3 then
r61 =0
g61 =255
endif
IF cMiddleBand < sma25 then
r71=255
g71=0
elsif cMiddleBand >= sma25 then
r71=0
g71=255
endif
IF sma25 < sma50 then
r81=255
g81=0
elsif sma25 >= sma50 then
r81=0
g81=255
endif
//colorbetween(cUpperBand2,cUpperBand3, 0,255,0,a1) // upperBand3 green - trend up
//colorbetween(cUpperBand1,cUpperBand2, 0,255,0,a2) // upperBand2 green - trend up
//colorbetween(cMiddleBand,cUpperBand1, r,g,0,a3) // upperBand1 green/red - trend up/down
//colorbetween(cMiddleBand,cLowerBand1, r,g,0,a4) // lowerBand1 green/red - trend up/down
//colorbetween(cLowerBand1,cLowerBand2, 255,0,0,a5) // lowerBand2 red - trend down
//colorbetween(cLowerBand2,cLowerBand3, 255,0,0,a6) // lowerBand3 red - trend down
REM colorbetween (cMiddleBand,sma25, r71,g71,0,15)
REM colorbetween (sma25,sma50, r81,g81,0,10)
return ts coloured(r,g,0) style(line,1) as "BTrend 2 months" ,cMiddleBand coloured (r0,g0,0) style (dottedline,1) as "SMA (13)", sma25 coloured (255,255,0) style (dottedline,1) as "SMA (25)", sma50 coloured (255,102,255) style (dottedline,1) as "SMA (50)" rem , cUpperBand1 coloured (r11 ,g11 ,0) style (DOTTEDLINE4 ,1) as "Upper1", cUpperBand2 coloured (r21 ,g21 ,0) style (DOTTEDLINE4 ,1) as "Upper2", cUpperBand3 coloured (r51 ,g51 ,0) style (DOTTEDLINE4 ,1) as "Upper3", cLowerBand1 coloured (r31 ,g31 ,0) style (DOTTEDLINE4 ,1) as "Lower1", cLowerBand2 coloured (r41 ,g41 ,0) style (DOTTEDLINE4 ,1) as "Lower2", cLowerBand3 coloured (r61 ,g61 ,0) style (DOTTEDLINE4 ,1) as "Lower3"
I tested it on intraday TF and seems to work well …
I meant on s&p500 INDEX when I wrote … “For example on the 2 months TF my indicator value is 5527,76 while if I charge it on the monthly TF with indication at beginning of code TIMEFRAME (2 MONTHS) the value it returns is 5312,08” …
Multi timeframe – MTF indicators for ProRealTime
This topic contains 164 replies,
has 53 voices, and was last updated by PeterSt
9 months ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 05/27/2020 |
| Status: | Active |
| Attachments: | 49 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.