This don’t work. It seems so that there isn’t any solution for this problem. I can’t beleave it, it is only a market order.
Buy 1 contract at High STOP
I might be missing something, but how can we buy at High?
High does not allow for spread?
Surely it needs to be something like … Buy 1 contract at (High-x) STOP?
Or better still …
If Close > High - x Then
Buy at Market
Endif
same goes for SellShort …
If Close < Low +x Then
SellShort at Market
Endif
Thank you, but im afraid this wont work. Maybe you can take a look at attaced picture?
how can we buy at High STOP? (for example, at bar 100)
During the next bar (or next few bars) we may hit the value that High was on bar 100 (allowing for spread of course).
Is this what is happening killerplatuze
I like this PopGun, it’s simple and < 10 lines of code … makes it easy to work on! 😉
Try below with values A4 to A7 optimised to whatever you think suits your chosen TF and Instrument.
Below fits what you state in the box on your screenshot?
DefParam CumulateOrders=False
//PopGun
If High[2]>High[1] and Low[2]<Low[1] and High>High[1] and Low<Low[1] then
Buy 1 contract at High+A4 STOP
Set Stop Price High-A5
SellShort 1 contract at Low-A6 STOP
Set Stop Price Low+A7
EndIf
Is above code opening trades > 5 bars after trigger bar?
If Yes, that is the next thing to fix.
Many thanks for your help. It seems to be the right way.
The fifth bar should be filled with a short, but isn’t. If the fourth bar breaks out it will be filled with a trade
So 3 was the trigger bar?
What value are you using for A4 and A6 in the code I posted?
Just 5, just wanna see what happened with the bux trigger. The third candle is the buy trigger, One of the next 5 bars must break out, otherwise the popgun will be deleted.
I take 5 for all.
Try this …
DefParam CumulateOrders=False
PopGun = High[2]>High[1] and Low[2]<Low[1] and High>High[1] and Low<Low[1]
If PopGun Then
Trigger = barindex
TrigHigh = High
TrigLow = Low
TradeOn = barindex < Trigger + 5
Endif
If PopGun and TradeOn then
Buy 1 contract at TrigHigh+A4 STOP
Set Stop Price High-A5
SellShort 1 contract at TrigLow-A6 STOP
Set Stop Price Low+A7
EndIf
Above code with small improvement …
DefParam CumulateOrders=False
PopGun = High[2]>High[1] and Low[2]<Low[1] and High>High[1] and Low<Low[1]
If PopGun Then
Trigger = barindex
TrigHigh = High
TrigLow = Low
TradeOn = barindex < Trigger + 5
Endif
If PopGun and TradeOn then
Buy 1 contract at TrigHigh+A4 STOP
Set Stop Price TrigHigh-A5
SellShort 1 contract at TrigLow-A6 STOP
Set Stop Price TrigLow+A7
EndIf
Without A4 and A6 it works, but there is only a trade if the first bar behind the triggerbar breaks out.
There is no trade if the first bar behind the popgung dont breaks out.
It seems to be more difficuilt than expected. Thanks for your help.
Works fine for me … see attached.
with values A4 to A7 optimised to whatever you think suits your chosen TF and Instrument.
Please confirm that you are doing above and not trying to run the code with the text – A4, A5, A6 and A7 – in the code??