Problem accessing data of current bar
Forums › ProRealTime English forum › ProBuilder support › Problem accessing data of current bar
- This topic has 7 replies, 2 voices, and was last updated 7 years ago by S. Sjolander.
-
-
09/07/2017 at 8:17 PM #45743
Hi,
When defining “set stop loss x”, I can not access the data of the current bar. E.g. “range” becomes the range of the next bar and “range[1]” becomes the range of the previous bar.
In contrary, when defining entry parameters I can access the data of the current bar.
I am attaching the relevant code.
1234567891011121314151617181920//Entry parameters--------------------------------------------------------------------------------------------------------------MyATR=AverageTrueRange[5](close)//Average True RangeE1=high+0.2*MyATR //Entry in units//Money, risk and position management--------------------------------------------------------------------------------------------Capital = 100000Risk = 0.01Equity = Capital + StrategyProfitMaxrisk = round(Equity*Risk)StopLoss=range+0.2*MyATR+MyATR//Stop loss in units relative to entryPositionSize = round((Maxrisk/StopLoss)/PointValue)*PointSize //No. of contracts of position//Stop order initialization-----------------------------------------------------------------------------------------------------IF MA1h and Zone and (c1 or c2 or c3) THENBUY PositionSize CONTRACTS AT E1 STOP //Stop order valid 1 bar by defaultENDIF//Stop Loss and Target----------------------------------------------------------------------------------------------------------------SET STOP LOSS StopLoss //Stop loss in units relative to entryAppreciate the feedback!
09/07/2017 at 10:30 PM #45757I’m not sure if I understand you correctly but PRT evaluates the code at the end of the candle. High, Close, Range and all this give you the values for the bar that just finished and not of the bar that is in the making.
Not sure if this answered your question.
09/08/2017 at 7:43 AM #45764Thank you Despair for your input.
Yes, PRT should evaluate the code at the end of the candle. As I have no problem with this for the rest of the code, I suspect that something within the “SET STOP LOSS X”- command might be causing the problems.
I will add pictures describing a stop loss that has been triggered in pro backtest, consisting of:
- 0.2*MyATR (OK. Evaluates the ATR of the signal candle, as it should do.)
- Range (NOT OK. Should evaluate the range of the signal candle, but evaluates the range of the next candle.)
- Range[1] (OK. Evaluates the length of the bar previous to the signal candle bar, as it should do.)
- 0.2*MyATR+MyATR+Range (NOT OK. This should give the full length of the stopp loss, evidently it does not.)
I hope this explains the problem further.
09/08/2017 at 7:46 AM #45767Additional pictures.
09/08/2017 at 2:42 PM #45810What it all comes down to, is that I am unable to add the “range” of the signal candle to the definition of the “set stop loss x”.
In addition, I tried to add “AverageTrueRange[1](close)” of the signal candle (which is basically the same as “range”) as the stop loss, with the same result as adding “range”. “AverageTrueRange[2](close)” has the same issue, but “AverageTrueRange[3](close)” and upwards (4, 5, 6… etc.) seems to take the data from the signal candle.
Very strange indeed.
09/08/2017 at 4:52 PM #45813Try replacing your stop loss line with the following:
1set stop ploss stoploss/pipsizeThen i have a hard time following you when you write “next candle”. Next to what?
BTW: Your post would belong in the proorder forum and not here in pro builder. This under forum is just for indicators.
09/08/2017 at 8:18 PM #45816Thanks for the feedback Despair, and thanks for the headsup. I mistook pro builder for pro order, sorry about that.
It is a bad explanation by me, though it seems it is difficult to describe the problem.
Thanks again and I will keep the thread updated if I come up with a solution.
09/08/2017 at 9:56 PM #45818I solved the problem.
When initializing the pending stop order you have to include the stop loss in the IF-loop.
Like this:
————————————————————————————————
IF MA1h and Zone and (c1 or c2 or c3) THENStopLoss=0.2*MyATR+Range+MyAtr
BUY PositionSize CONTRACTS AT E1 STOP //Stop order valid 1 bar by default
ENDIF
And not like this:
———————————————————————————————-
IF MA1h and Zone and (c1 or c2 or c3) THEN
BUY PositionSize CONTRACTS AT E1 STOP //Stop order valid 1 bar by default
ENDIFStopLoss=0.2*MyATR+Range+MyAtr
Otherwise PRT will not interprete the stop loss right.
-
AuthorPosts
Find exclusive trading pro-tools on