Reputation: 23
I have a strategy with 2 EMA that is automated by a bot.
When FastMA crossover SlowMA = buy when FastMA crossunder SlowMA = Sell
When I set my alert on the strategy, it rings on every single candle open rather than on the crossovers, when the strategy should buy or sell. Because of this, my startegy buys and sells or sells and buys instantly therefore canceling out the trade.
My questions is the following: How do i make it that the only alarm that rings is when a crossover/crossunder occurs and an order places itself?
I am running it on Oanda Practice to test it before i run it with real capital
Below is my alert section
strategy.entry('Buy', strategy.long, when=goLong())
alert("e=oandapractice a=localhost s=silver b=long q=1 t=market d=5", alert.freq_all)
alert("e=oandapractice a=localhost s=silver q=1 t=market c=position", alert.freq_all)
strategy.entry('Sell', strategy.short, when=goShort())
alert("e=oandapractice a=localhost s=silver b=short q=1 t=market d=5", alert.freq_all)
alert("e=oandapractice a=localhost s=silver q=1 t=market c=position", alert.freq_all)
Upvotes: 0
Views: 600
Reputation: 21342
You should add an if condition to trigger your alerts.
Something like:
is_new_long_position = strategy.position_size[1] == 0 and strategy.position_size > 0
if (is_new_long_position)
alert("e=oandapractice a=localhost s=silver b=long q=1 t=market d=5", alert.freq_all)
alert("e=oandapractice a=localhost s=silver q=1 t=market c=position", alert.freq_all)
Upvotes: 0