You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I'm trying to change stop loss for main stop... How do I do that?
That's what I'm doing:
COrder *order=orders.At(i); .... COrderStop *order_stop=order.MainStop(); double new_sl=...; order_stop.StopLoss(new_sl); order.MainStop(order_stop); order.CheckStops();
I really broke my head trying to do that...
It's not updating because of checking in COrderStopVirtualBase::Update
StopLoss() returns new value but sl_line still old...
Hi Shep,
Thank you for pointing these out. I have not noticed this until now. I will update the code.
Yes, I am aware of this. This is still due to the forward declarations. CStop requires instances of COrder and COrderStop in its methods. The same also when you try to compile CStop. All these classes that require each other should be compiled together. It would give errors if each is compiled on its own. For example:
This will not compile. You have to declare a forward declaration so the compiler would recognize the class member m_object2 within the object1 class:
This is ok if Object1 and Object2 are in the same file. If they are in two separate files, then you need to make a forward declaration for Object2 on the class file of Object1, and for Object1 on the class file Object 2.Then the compiler would return no errors if you compile either file. That is true, until you add methods to either of the two classes.
The current version of the compiler recognizes forward declarations, but not the listed methods of the class declared forwardly. That is why you do not receive error messages like "CStop - declaration without type", but you receive compiler error messages for the methods such as you the one you posted above. The compiler recognizes the class, but not the methods of the class that has been forwardly declared.
Hi Enrico,
Thanks for the quick response. You are quite right about the forward declarations. I was worried that it might be a deeper problem than that. It makes sense that the object using the forwardly declared class has no knowledge of that class's members.
I use a different model for my execution engine which uses the strategy pattern. I have a few annoying problems with it, and was just taking a look at your library when I came across those issues.
Your work is really great, you have sound design and engineering skills and thanks for being kind enough to share.
Thanks, Shep.
Hi Enrico,
Thanks for the quick response. You are quite right about the forward declarations. I was worried that it might be a deeper problem than that. It makes sense that the object using the forwardly declared class has no knowledge of that class's members.
I use a different model for my execution engine which uses the strategy pattern. I have a few annoying problems with it, and was just taking a look at your library when I came across those issues.
Your work is really great, you have sound design and engineering skills and thanks for being kind enough to share.
Thanks, Shep.
Hi Shep,
You're welcome and thank you for letting me know. I recall I was also a bit puzzled when I ran into that issue with forward declarations.
Glad to hear that you have found the articles to be useful. I wish you all the best in your efforts in building your own EA engine.
Regards, Enrico
It's not updating because of checking in COrderStopVirtualBase::Update
StopLoss() returns new value but sl_line still old...
The purpose of COrderStopVirtualBase::Update is actually the opposite of what you intend. It is meant to adjust the sl/tp value when its own stop line is updated, usually from outside the EA (dragging on chart or directly altering the value on the object properties window). Use MoveStopLoss() and MoveTakeProfit() methods instead for virtual stops.
This is supposed to be for the next article, but if you are eager, you may want to take a look at the CheckTrailing() method of COrderStopBase. It modifies the order stop when eligible for trailing. The method applies to all three types:
Alternatively, the CTrail class can also be used to alter sl/tp levels without having to retrieve an instance of an order stop (not just for trailing or breakeven).
I really enjoyed the article, it opened my eyes. Please, write a follow up article. I am really interested in how you would approach scalping with this tool.
Thanks a million for this and all your other work.