SVKParticipant
Junior
Hi All,
again I’m turning to you knowledgable folks for a small help.
I have attempted to do it myself but I’m getting nowhere unfortunately.
Threads I have reviewed:
How to keep a condition active for more than one bar
Wait for x bars before entry
x bars in a row code
I’m looking for a code which will retain the trigger point but will delay it for 1 or 2 bars and will execute trade only if we are still in downtrend or uptrend.
Price crosses under the 200MA – trigger bar (#1)
Code retains this information but doesn’t execute the order on next bar(#2).
When second bar(#3) since trigger opens it needs to check if previous bar(#2) closed below bar (#1 trigger bar).
If bar #2 didn’t close below bar #1 then order is cancelled.
If bar #2 closed below bar#1 then order is executed on bar#3.
First photo is the situation I’m trying to avoid.
Second photo is a succesfull trade execution.
Thank you very much for your help
Once PostPone = 0
Once BuyingConditionsAreSet = 0
Once AllMyBuyingConditionsMeet = 0
It Not BuyingConditionsAreSet then
// Sort out Buying Conditions here. If they are met, end with :
BuyingConditionsAreSet = 1
AllMyBuyingConditionsMeet = 1
endif
If AllMyBuyingConditionsMeet then
PostPone = 2
Endif
[...]
If AllMyBuyingConditionsMeet then
If not OnMarket and PostPone = 0 then
Buy xyz Shares At Market
BuyingConditionsSet = 0 // Reset.
AllMyBuyingConditionsMeet = 0 // Reset.
ElsIf Not OnMarket and PostPone > 0 then
PostPone = PostPone -1 // Now wait for the next call. 2 actually.
endif
endif
// BuyingConditionsSet and AllMyBuyingConditionsMeet seem redundant (do the same)
// but "underway" at downcounting PostPone, you may feel that conditions are
// not right anymore (the 3 of 1-2-3 never occurs), meaning that the conditions
// have been "set" all right, but you won't Enter. On the other hand, once
// you have definitely set the conditions, you may not want to look back and
// just wait 2 bars regardless. So it is a bit how you want all happening.
SVK, If you require a fully working code, then this is not for me. In that case the above may be helpful for others.
It is not that exciting. But when to reset and why, could be (very much).
Regards,
Peter
JSParticipant
Senior
Hi @SVK
DefParam CumulateOrders = False
S1 = Close
S2 = Average[200](Close)
Cond1 = S1[1] Crosses Over S2[1]
Cond2 = S1 > S1[1]
Cond3 = S1[1] Crosses Under S2[1]
Cond4 = S1 < S1[2]
If Cond1 and Cond2 then
Buy 1 contract at market
EndIf
If Cond3 and Cond4 then
SellShort 1 contract at market
EndIf
JSParticipant
Senior
Edit line 9 : Cond4 = S1 < S1[1]