I have a trading algo I have created. Seems to be working well for what I want.
The issue is when you start it it immediately read as signal and goes into a trade – which is problematic.
Obviously once it is in a trade and up and running it can do its own thing and is fine. The issue is always with its first step.
Is there a way to programme it so that it waits for a signal before starting the algo and then never refers back to that again?
i.e.
indicator1 = DIplus[14]
indicator2 = DIminus[14](close)
c1 = (indicator1 CROSSES OVER indicator2)
Once this happens then the algo will start?
Thanks
JSParticipant
Senior
When you have started your algo, the first trade will depend on the conditions you have set in your algo.
The condition, in your example, will indeed ensure that, when the condition is met, the first trade will be executed.
There is nothing wrong with the condition in your example.
Try adding this line at the very beginning:
Defparam PreLoadBars = 0
Thanks, but not quite what I was trying to explain. Sorry for my poor explanation.
I shall try and explain it better.
Basically I would like to get the algo to find a setup first, once it does this then execute a follow on strategy and once it is done, do nothing until the setup presents itself again.
For instance.
Once MACD line crosses signal – it will then wait for SMA 5 to be 3 points higher than SMA 8 before executing a buy signal.
But after trade is executed and ended it should wait until the MACD line crosses the signal line before relooking for the setup.
Does this make sense?
IT is almost like when this is triggered wait for this condition and end. Wait for trigger again and then wait for condition.
As the conditions never happen simultaneously and I want a cross over condition rather than a > condition.
Thanks
JSParticipant
Senior
If I understand what you mean, then you must work with “conditions”:
For example:
MyCondition = 0
If MACD Crosses Over …. Then
MyCondition = 1
EndIf
If Average[5](close) > Average[8](close) + 3 AND MyCondition = 1 then
Buy x contract at market
EndIf
JSParticipant
Senior
For example, you can reset your condition when a position is closed.
If OnMarket = 0 and OnMarket[1] = 1 then
MyCondition = 0
EndIf
Thank you MYCondition is very useful.
So as I understand it then – once MYCONDITION is fulfilled it will allow the other conditions “Average[5](close) > Average[8](close)” to trigger an action.
Thanks for your help.
JSParticipant
Senior
That’s right, when MyCondition (or the name you want to give it) is triggered, it can, together with the next condition, generate a buy or sell signal.
Please note that you put MyCondition back to zero after closing a trade by, for example,
If OnMarket = 0 and OnMarket[1] = 1 then
MyCondition = 0
EndIf
You can of course use more conditions for Long and Short, but that works in an equal way.
Thanks – but I don’t think it does what I need.
All it is doing to setting a trigger point with a condition.
If Average[5](close) > Average[8](close) + 3 AND MyCondition = 1 then
i.e. in this scenario all it needs to happen is the SMA 5 needs to be greater then the SMA8 and at the same time the MACD needs to have crossed over?
What I want is a scenario where once the MACD crosses over it enables the trade to happen once the following parameters are satisfied.
I don’t want them to need for them to happen all at the same time before it triggers the action.
Does that makes sense?
If JS had called MyCondition a Flag then it may have been easier to grasp the concept?
Flag = 0 at start of code, if MACD crosses over then Flag =1; Flag stays at 1 forever until code resets to Flag = 0 (e.g. at trade exit).
So Flag = 1 could be for 50 bars until Average[5](close) > Average[8](close) + 3.
Hope that helps?
Yes sorry my stupidity .. I get it now .. and i understand the principles and I believe have got it working.
Many many thanks.