THEN condition to use it as an IF condition in the second rule
12 replies
Pago
11 years ago #111005
Hello,
someone knows how to process the result of a rule #1 in a second rule?
For example:
In the first rule i use is the condition MACD > 0 if the result is true i want to use this signal in the second rule.
I try it with THEN Assign Variable, but this variable remains even if the IF conditions no longer be met.
Cezar
stearno
11 years ago #121260
Czar,
You are correct, the rule will asign the variable and then not touch the variable again until the conditions are met.
So what you need to do is have 2 rules: 1st rules assigns variable when MACD >0 and then 2nd rule which assigns variable when MACD<0. Then your variable will always be a reflection of where the MACD is.
-STearno
Pago
11 years ago #121262
Hi Stearno,
I was afraid that it is the only way. The above condition was just a simplified example, the condition is quite complicated and condition for the reverse is very complicated and I thought it can somehow solve different.
I’ve got another idea. I Just try to export the condition as an indicator and then import it into the wizard in order to use the sigal.
Cezar
stearno
11 years ago #121266
Sounds good. Good luck!
Mark Fric
11 years ago #121283
Hello,
someone knows how to process the result of a rule #1 in a second rule?
For example:
In the first rule i use is the condition MACD > 0 if the result is true i want to use this signal in the second rule.
I try it with THEN Assign Variable, but this variable remains even if the IF conditions no longer be met.
Hello Cezar,
what you can do is process the result on the second rule, and then set the variable to false again (by Assign variable function).
Mark
Mark
StrategyQuant architect
Pago
11 years ago #121288
Mark Fric
11 years ago #121292
I meant something like this:
Rule 1:
IF Market Position Is Flat and MACD > 0
THEN
Assign Variable ThereIsSignal = 1
Rule 2:
IF ThereIsSignal = 1
THEN
Enter At Market
Assign Variable ThereIsSignal = 0
this way the variable that was set by the first rule will be unset when you enter the trade, this was your problem as I undetstood.
Mark
Mark
StrategyQuant architect
Pago
11 years ago #121303
518pip
11 years ago #121812
I meant something like this:
Rule 1:
IF Market Position Is Flat and MACD > 0
THEN
Assign Variable ThereIsSignal = 1
Rule 2:
IF ThereIsSignal = 1
THEN
Enter At Market
Assign Variable ThereIsSignal = 0
this way the variable that was set by the first rule will be unset when you enter the trade, this was your problem as I undetstood.
Mark
Hi, I am dealing with similar issue, please help. Anyone.
multi entry if price above 100 ema.
1st entry if 10 ema cross above 20 ema, then enter at market with target.
2nd entry if 10 ema cross above 20 ema again and price still above 100 ema, enter at market. (sometimes 1st may not open anymore if target was reached)
keep enter at market as long as price above 100 ema and very time 10 ema & 20 ema cross above independently.
I tried to assign variable, but My current ea keep open both 1st and 2nd entry at the same time when the 1st entry happens and skip the rest of valid entrys.
Thank you,
Pago
11 years ago #121818
Hi, I am dealing with similar issue, please help. Anyone.
multi entry if price above 100 ema.
1st entry if 10 ema cross above 20 ema, then enter at market with target.
2nd entry if 10 ema cross above 20 ema again and price still above 100 ema, enter at market. (sometimes 1st may not open anymore if target was reached)
keep enter at market as long as price above 100 ema and very time 10 ema & 20 ema cross above independently.
I tried to assign variable, but My current ea keep open both 1st and 2nd entry at the same time when the 1st entry happens and skip the rest of valid entrys.
Thank you,
Hello 518pip,
I think you don´t need to assign a variable.
Rule 1: The first entry –> IsBarOpen is True && Bid > EMA 100 && EMA 10 cross above EMA 20
Rule 2 The second entry –> IsBarOpen is True && (Open P/L [Magic_first_entry] 0 or Closed P/L [Magic_first_entry] 0) && Bid > EMA 100 && EMA 10 cross above EMA 20
To close you can use a third rule with the close conditions.
Hope I could help you. Otherwise you can attach sthe trategy to the post then we can help you more specifically.
Cezar
Mark Fric
11 years ago #121822
Hi, I am dealing with similar issue, please help. Anyone.
multi entry if price above 100 ema.
1st entry if 10 ema cross above 20 ema, then enter at market with target.
2nd entry if 10 ema cross above 20 ema again and price still above 100 ema, enter at market. (sometimes 1st may not open anymore if target was reached)
keep enter at market as long as price above 100 ema and very time 10 ema & 20 ema cross above independently.
I tried to assign variable, but My current ea keep open both 1st and 2nd entry at the same time when the 1st entry happens and skip the rest of valid entrys.
Thank you,
You can do it like this (I’ll show only the long side):
——————–
Rule 1:
——————–
IF
OrderPosition(1000) is not Flat // we make sure the first order is opened already
and Bid > EMA(100) // make sure that price is above EMA(100)
and EMA(10) crosses above EMA(20)
THEN
Enter at Market with Magic Number(2000)
——————–
Rule 2:
——————–
IF
OrderPosition(1000) is Flat // we make sure the order isn’t opened already
and Bid > EMA(100) // make sure that price is above EMA(100)
and EMA(10) crosses above EMA(20)
THEN
Enter at Market with Magic Number(1000)
This should work. The second rule takes care of taking any signal when EMA(10) crosses EMA(20) and Rule 1 takes care of special case that the first order is already opened.
The rules have to be in this order.
Perhaps you’d have to add also Is Bar Open = true to both rules to make sure the trades are opened only on bar open.
Mark
StrategyQuant architect
boomza100
11 years ago #121844
Hi All,
I have a similar question, in line with the subject of this thread.
I keep getting new positions opened, with every new tick.
What I want to do is only open a position once, if my conditions are met.
If there is already an open position, do not open another one.
If a position has been closed, then it is OK to open another position if conditions are met.
My code is like this.
——————–
Rule 1:
——————–
IF IsBarOpen is True
and Some Other Condition //too long to repeat here, but doesn’t matter
and OrderPosition(MagicLong) is Flat //ie: there is no open positions ??? (is that right?)
THEN Enter at Market (MagicLong)
As I understand it, you can only open one position per magic number, yet it keeps opening new positions every tick.
Any suggestions,
Thanks.
Mark Fric
11 years ago #121915
Hi,
condition OrderPosition(MagicLong) is Flat really is true if there are no open positions, so your conditions are correct.
As I understand it, you can only open one position per magic number, yet it keeps opening new positions every tick.
yes,it shouldn’t open multiple positions with the same magic number. If it opens new position every tick there is some problem or possible bug. Can you post your strategy (.sqw file) here?
Mark
StrategyQuant architect
Viewing 12 replies - 1 through 12 (of 12 total)