Reputation: 689
strategy("Custom_ema_strategy", overlay=true , shorttitle="Custom EMA Strategy" ,initial_capital=10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100.00, commission_type="percent", commission_value=0.00)
//Inputs
fastMALength = input(title = "Fast MA Length" , type = input.integer , defval = 10)
slowMALength = input(title = "Slow MA Length" , type = input.integer , defval = 20)
selectSource = input(title = "Source" , type = input.source , defval = close)
fastMA = ema(selectSource , fastMALength)
slowMA = ema(selectSource , slowMALength)
filter = input(title = 'Filter' , type = input.integer , defval = 50)
plot(fastMA , color = color.yellow , linewidth = 2 , title = 'FAST MA')
plot(slowMA , color = color.blue , linewidth = 2 , title = 'SLOW MA')
plot(low , title='Title', color=#00ffaa, linewidth=2, style=plot.style_circles)
longCondition = low > fastMA and low > slowMA
shortCondition = crossunder(fastMA , slowMA)
plotchar(longCondition , 'longCondition' , '')
plotchar(low , 'low' , '')
plotchar(fastMA , 'fastMA' , '')
if longCondition
strategy.entry("Long Entry", long = strategy.long)
a. The strategy above doesn't get executed as my longCondition is straight forward , I only need the low to be higher than fastMA and slowMA. As you can see the highlighted candle satisfies the condition but it doesn't execute. Not too sure why it doesn't execute.
b. This blue highlighted candle should fail because the low is 6551.00 and whereas the slowMA is 6551.49 which should be false since the condition is low > slowMA but the longCondition is 1.00 which returns true.
c. The highlighted section shows when the condition is fulfilled, how to enter the strategy at the next candle(which the arrow indicates) after the condition is fulfilled.
Upvotes: 0
Views: 183
Reputation: 8789
You are getting an entry early on in your dataset, but because you are not exiting the trade, the number of entries you get will correspond to the quantity of pyramided entries you allow:
Upvotes: 1