Basic ProRealTime code help

MrLeverage

Active member
Messages
107
Likes
5
IF c1 AND c2 THEN
BUY 1 SHARES AT MARKET
ENDIF


I have two conditions as the basis for a strategy. I need condition 1 to be met before condition 2 is considered. The problem I have it what C1 does not happen at the same time as C2. I can't get it to work as when I put "THEN" between C1 and C2 is errors. Can anyone assist?
 
Hi MrLeverage, I think this is what you need.......... From the ProRealTime Programming manual....

Sequential IF conditions
You can create sub-conditions after the validation of the main condition, meaning conditions which must be validated one after another. For that, you need to build a sequence of IF structures, one included in the other.
You should be careful to insert in the code as many ENDIF as IF. Example:
Double conditions on moving averages :

IF (Average[12](Close) - Average[20](Close) > 0) THEN
IF ExponentialAverage[12](Close) - ExponentialAverage[20](Close) > 0 THEN
Result = 1
ELSE
Result = -1
ENDIF
ENDIF

RETURN Result


Your code would probably look like this........

IF C1 THEN
IF C2 THEN
Result = 1
ELSE
Result = -1
ENDIF
ENDIF
RETURN Result

Hope this helps

Stu
 
IF c1 AND c2 THEN
BUY 1 SHARES AT MARKET
ENDIF


I have two conditions as the basis for a strategy. I need condition 1 to be met before condition 2 is considered. The problem I have it what C1 does not happen at the same time as C2. I can't get it to work as when I put "THEN" between C1 and C2 is errors. Can anyone assist?

Stu_tat is right. You need nested [if] statement:


IF c1 THEN
IF c2 THEN
BUY 1 SHARES AT MARKET​
ENDIF​
ENDIF
 
Top