Indicator lookup last bar
Indicator lookup last bar
23 Aug 2014, 23:50
Hi There,
I am building a robot around the Rate of Change Indicator;
So far I got it working to open and close positions when the Value of the ROC is above or below the 0-line:
if (ROC.rocline.LastValue < 0 && !isShortPositionOpen) { ClosePosition(); Sell(); } if (ROC.rocline.LastValue > 0 && !isLongPositionOpen) { ClosePosition(); Buy();
I would like to only enter a trade if the value of the previous Bar was above/below the 0-Line.
If i set a take profit for example of 10 pips; and it is reach, at the next bar a new position is opened. I want the Robot to wait until the ROC line crosses below/above the 0 line again before opening a new position.
I got this working according to code below, but it will miss opportunaties if I code it like this, as it just sets a window:
if (ROC.rocline.LastValue < 0 && ROC.rocline.LastValue > -0.3 && !isShortPositionOpen) { ClosePosition(); Sell(); } if (ROC.rocline.LastValue > 0 && ROC.rocline.LastValue < 0.3 && !isLongPositionOpen) { ClosePosition(); Buy();
So for a buy I would like that I get the value of the ROC of the previous bar to be below 0, the current bar closed above 0 as confirmation.
And for a Sell visa versa; ROC previous bar is above 0, current bar closes below 0.
Thanks in advance.
modarkat
25 Aug 2014, 10:18
ROC.rocline.Last(0) - current value,
ROC.rocline.Last(1) - previous value
@modarkat